javascript - How to plot a date range on X-axis in Flot Charts? -


i'm using flot charts display data period (to selected user, e.g. last 30 days, last 7 days, 1st jan 2013 3rd mar 2013 etc)

so want display line chart x-axis date.

e.g. if i've 2 days, startdate , enddate how make x-axis display like:

1 jan 2013 | 2 jan 2013........................3 mar 2013

my code follows: data (currently it's static).

var mydata = [                 [1, 2.4],                 [2, 3.4 ],                 [3, 4.5 ],                 [4, 5 ],                 [5,  5],                 [6, 5],                 [7, 2 ],                 [8, 1 ],                 [9, 1.5 ],                 [10, 2.5 ],                 [11,  3.5],                 [12, 4 ],                 [13, 4 ],                 [14, 2.4],                 [15, 3.4 ],                 [16, 4.5 ],                 [17, 5 ],                 [18,  5],                 [19, 5],                 [20, 2 ],                 [21, 1 ],                 [22, 1.5 ],                 [23,  2.5 ],                 [24,   3.5],                 [25,  4 ],                 [26,  4 ],                 [27,  2.5 ],                 [28,   3.5],                 [29,  4 ],                 [30,  4 ],             ];  var plot = $.plot($("#mychart"), [{                 data: mydata,                 label: "y-axis label"             }], {                 series: {                     lines: {                         show: true                     },                     points: {                         show: true                     },                     shadowsize: 2                 },                 grid: {                     hoverable: true,                     clickable: true                 },                 colors: ["#37b7f3", "#d12610", "#52e136"],                 xaxis: {                      mode: "time", timeformat: "%d/%m/%y", minticksize: [1, "day"]                 },                 yaxis: {                     ticks: 11,                     tickdecimals: 0,             min:0, max: 5                 }             }); 

i realize need make mydata [date, value]. work? i've data dynamically generated server in json in

[{date, value}, {date, value}...]

format. please guide.

you need change numbers unix time stamps multiplied 1000. api if search time series data:

the time series support in flot based on javascript timestamps, i.e. everywhere time value expected or handed over, javascript timestamp number used. number, not date object. javascript timestamp number of milliseconds since january 1, 1970 00:00:00 utc. same unix timestamps, except it's in milliseconds, remember multiply 1000!

there .net example in api:

public static int getjavascripttimestamp(system.datetime input) { system.timespan span = new system.timespan(system.datetime.parse("1/1/1970").ticks); system.datetime time = input.subtract(span); return (long)(time.ticks / 10000); } 

here example - http://jsfiddle.net/zxtfc/4/


Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

css - Can I use the :after pseudo-element on an input field? -