javascript - flot how to know the x axis points in dynamic data -
i using flot jquery library draw charts.
when chart has specific number of columns, can set x values points.
but have dynmic data. how can know points of x axis please?
for example,
the x axis of first point 1325876000000 x axis of second point 1328194400000 third 1330360000000 fourth 1332838400000
but lets have 9 columns. how can know x axis them please?
i printing chart in way
var holder = $('#vertical-chart'); if (holder.length) { $.plot(holder, data, chartoptions); }
the input data this
label: "label1"
data: [[1325876000000,0],[1325876000000,0],[1325876000000,0],[1325876000000,30]]
but don't know how many points in array. 11 or 2
edit
this chartoption
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 }
when using $.plot(holder, data, chartoptions);
, save plot variable.
declare var plot;
globally,
and call this: plot = $.plot(holder, data, chartoptions);
.
you can grab data plot this:
var datasets = []; var xdata = []; datasets = plot.getdata(); //this returns array of datasets //goes through each series of data (var = 0; < datasets.length; i++){ //picks series label of "label 1" if (datasets[i].label == "label 1"){ //copies x coordinates series xdata (var j = 0; j < datasets[i].data[j].length; j++){ xdata.push(datasets[i].data[j][0]); //if want y coords, use datasets[i].data[j][1] } } }
Comments
Post a Comment