Reputation: 5936
I have the following JS data:
var store = [];
store.push([new Date('2012-01-01'), 2]);
store.push([new Date('2012-01-02'), 3]);
store.push([new Date('2012-01-03'), 4]);
store.push([new Date('2012-01-04'), 6]);
store.push([new Date('2012-01-05'), 3]);
store.push([new Date('2012-01-06'), 4]);
store.push([new Date('2012-01-07'), 2]);
store.push([new Date('2012-01-08'), 1]);
store.push([new Date('2012-01-09'), 4]);
store.push([new Date('2012-01-10'), 2]);
store.push([new Date('2012-01-11'), 3]);
store.push([new Date('2012-01-12'), 6]);
store.push([new Date('2012-01-13'), 2]);
store.push([new Date('2012-01-14'), 5]);
store.push([new Date('2012-01-15'), 4]);
store.push([new Date('2012-01-16'), 2]);
store.push([new Date('2012-01-17'), 6]);
store.push([new Date('2012-01-18'), 6]);
store.push([new Date('2012-01-19'), 1]);
store.push([new Date('2012-01-20'), 1]);
store.push([new Date('2012-01-21'), 1]);
store.push([new Date('2012-01-22'), 8]);
store.push([new Date('2012-01-23'), 8]);
store.push([new Date('2012-01-24'), 13]);
store.push([new Date('2012-01-25'), 5]);
store.push([new Date('2012-01-26'), 5]);
store.push([new Date('2012-01-27'), 1]);
store.push([new Date('2012-01-28'), 1]);
store.push([new Date('2012-01-29'), 2]);
store.push([new Date('2012-01-30'), 6]);
Flot code:
$.plot($('.chart'), store);
HTML:
<div class="chart"></div>
My Axis on both the x and y is only showing from -1 to 1.. I can't see the graph plotting at all. Where am i going wrong?
Thanks in advance,
Upvotes: 1
Views: 2620
Reputation: 801
Try this :
<html>
<head>
<script language="javascript" type="text/javascript" src="jquery.js"></script>
<script language="javascript" type="text/javascript" src="jquery.flot.js"></script>
</head>
<body>
<div class="chart"></div>
<script type="text/javascript">
$(function () {
var store = [];
store.push([new Date(2012, 1, 1)).getTime(), 2]);
.
.
.
store.push([(new Date(2012, 1, 30)).getTime(), 6]);
$.plot($('.chart'), store, {
grid: {hoverable: true},
xaxis: {
mode: "time",
timeformat: "%d.%m.%y",
minTickSize: [1,"day"],
min: (new Date(2012, 1, 1)).getTime(),
max: (new Date(2012, 1, 30)).getTime()
},
yaxis: {
mode: "number",
tickSize: 1
},
series: {
lines: { show: true },
points: { show: true }
}
});
});
</script>
</body>
</html>
Upvotes: 2
Reputation: 38189
You need to set your x-axis mode to 'time', and provide the dates as timestamps in milliseconds. See the API Docs under the 'Time series data' heading for more information.
Upvotes: 1
Reputation: 2830
I had this problem, I think you need to wrap your array in another array...
$.plot($('.chart'), [store]);
Upvotes: 3