2012-01-10 76 views
0

我有一個要求使用x軸選擇繪製具有縮放功能的圖形,我使用Flot繪製圖形。我必須顯示縮放後出現的點數。 我很高興得到的總長度不是縮放的長度。浮點圖數據點的數量

好心幫

+0

您的意思是'Plot'與'Plot Graph Number of Data points'一樣嗎? – 2012-01-10 06:44:03

+0

flot不會更改數據集,因此如果您想知道可見點,則必須自己計算。 – Ryley 2012-01-10 16:46:30

回答

2

在你的「plotzoom」回調,可以分&最大的x/y座標回來,像這樣(從網站上的例子):

placeholder.bind('plotzoom', function (event, plot) { 
    var axes = plot.getAxes(); 
    $(".message").html("Zooming to x: " + axes.xaxis.min.toFixed(2) 
         + " – " + axes.xaxis.max.toFixed(2) 
         + " and y: " + axes.yaxis.min.toFixed(2) 
         + " – " + axes.yaxis.max.toFixed(2)); 
}); 

你可以用這些來計算這個矩形內有多少個點。

我可以建議使用underscore.js過濾器函數來簡化它嗎?

例如,

var xmin = axes.xaxis.min.toFixed(2); 
var xmax = axes.xaxis.max.toFixed(2); 
var ymin = axes.yaxis.min.toFixed(2); 
var ymax = axes.yaxis.max.toFixed(2); 

var points = [{x: 1, y:20} ..some points.. {x: 30, y: -23}]; 

var shownpoints = _.filter(points, function(point){ 
    return point.x > xmin && 
      point.x < xmax && 
      point.y > ymin && 
      point.y < ymax; 
    } 
); 

這會給具有x &ý格言之間在點陣列。然後你可以用長度來計數!

+0

如何獲取點數組?我傳遞數據爲{「label」:「Label 1」,「data」:[[x,y],[x,y] ......] – paramupk 2012-02-03 06:17:13

+0

plot.getData()會給出數據感謝很多minikomi – paramupk 2012-02-03 08:29:16