簡體   English   中英

浮點如何知道動態數據中的x軸點

[英]flot how to know the x axis points in dynamic data

我正在使用flot jquery庫繪制圖表。

當我的圖表具有特定的列數時,可以為點設置x值。

但現在我有一個動態數據。 那么我怎么知道x軸的點呢?

例如,

the x axis of the first point is 1325876000000
the x axis of the second point is 1328194400000
the third is 1330360000000
the fourth is 1332838400000

但可以說我將有9列。 我怎么知道他們的x軸?

我以這種方式打印圖表

var holder = $('#vertical-chart');

   if (holder.length) {
       $.plot(holder, data, chartOptions);
   }

輸入數據是這樣的

標簽:“ label1”

data: [[1325876000000,0],[1325876000000,0],[1325876000000,0],[1325876000000,30]]

但現在我不知道該數組中有多少點。 可能是11或可能是2

編輯

這個圖表選項

  chartOptions = {
           xaxis: {
               min: (new Date(2011, 11, 15)).getTime(),
               max: (new Date(2012, 04, 18)).getTime(),
               mode: "time",
               tickSize: [2, "month"],
               monthNames: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],
               tickLength: 0
           },
           grid: {
               hoverable: true,
               clickable: false,
               borderWidth: 0
           },
           bars: {
               show: true,
               barWidth: 12 * 24 * 60 * 60 * 300,
               fill: true,
               lineWidth: 1,
               order: true,
               lineWidth: 0,
               fillColor: { colors: [{ opacity: 1 }, { opacity: 1 }] }
           },

           tooltip: true,
           tooltipOpts: {
               content: '%s: %y'
           },
           colors: App.chartColors
       }

當使用$.plot(holder, data, chartOptions); ,使用變量保存圖。

聲明var plot; 在全球范圍內

然后像這樣調用: plot = $.plot(holder, data, chartOptions);

您可以像這樣從圖中獲取數據:

var datasets = [];
var xData = [];

datasets = plot.getData();    //this returns an array of all datasets

//goes through each series of data
for (var i = 0; i < datasets.length; i++){
    //picks the series with label of "label 1"
    if (datasets[i].label == "label 1"){
        //copies x coordinates from the series into xData
        for (var j = 0; j < datasets[i].data[j].length; j++){
            xData.push(datasets[i].data[j][0]);               //if you want y coords, use datasets[i].data[j][1]
        }
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM