2017-02-07 45 views
0

使用flot.js v 0.83我有一個問題從.pointOffset獲取數據。 這是我的代碼:flot.js:無法讀取Plot.plot.pointOffset未定義的屬性'p2c'

var position = 0; 
var existing = $("#placeholder"+tnr).data("plot"); 
var leftoffset = existing.offset(); 
// i receive values for offset! 
var lastDatapoint; 
$.each(existing.getData(), function(i, item, array) { 
      // get the last data point in the series data, e.g. [0, 5] 
      lastDatapoint = item.data[item.data.length - 1]; // still receive data here! 
      // get the position of the datapoint fails!!! 
      position = existing.pointOffset({ 
       x: lastDatapoint[0], 
       y: lastDatapoint[1] 
      }); 
     }); 

其實我收到existing.offset,甚至lastDatapoint值。但請求pointOffset當我得到這個錯誤:

Uncaught TypeError: Cannot read property 'p2c' of undefined at Plot.plot.pointOffset (jquery.flot.min.js:7)

這裏有什麼問題?

+0

請出示你的代碼的其餘部分,尤其是你的FLOT圖表的座標軸選項。 'pointOffset()'函數可以和普通的選項一起工作:https://jsfiddle.net/gp760m61/ – Raidri

+0

@Raidri你是正確的日誌,因爲你將劇情分配給一個var,就像你的小提琴'var plot ='一樣。我不能這樣做,因爲我動態加載多個圖。這就是爲什麼我要求這樣的情節:'var existing = $(「#placeholder」+ tnr).data(「plot」);' – kosemuckel

+0

'var plot = ...'沒有被使用,那不是問題或差異。 – Raidri

回答

0

好的,對我來說它已經解決了。由於我需要左側位置和情節的寬度,以低於其他畫布對齊,我現在會做這種方式:

var existing = $("#placeholder"+tnr).data("plot"); 
// get the left margin 
var offset = existing.offset(); 
var left = offset['left']; 
// get width of 'real' plot 
var width = existing.width(); 
相關問題