我试图随着时间的推移显示值,但无论我尝试和绘制什么数据,图表上都没有显示。 JsFiddle here
见下面的代码。我究竟做错了什么?
HTML:
<div id="theGraph"></div>
CSS:
#theGraph{
height:300px;
width:500px;
}
Javascript:
var graphData = [
[new Date("2015-03-13T08:00").getTime(), 2],
[new Date("2015-03-15T00:00").getTime(), 3]
];
var options = {
series: {
lines: {
show: true,
lineWidth: 2
},
points: {
show: true
}
},
lines: {
show: true
},
points: {
show: true
},
yaxis: {
min: 0,
max: 5
},
xaxis: {
mode: 'time',
minTickSize: [1, 'hour'],
min: new Date("2015-03-13T00:00").getTime(),
max: new Date("2015-03-15T08:00").getTime(),
timeformat: '%m/%d %H:%M'
}
};
$.plot($('#theGraph'), graphData, options);
答案 0 :(得分:1)
$ .plot方法获取你想要绘制图形的div的占位符/ id。 $ .plot(&#39;#id&#39;,.....)也是这样做的。
代码$ .plot()中只有一个问题。论证&#39; graphData&#39;应该在[]括号中,因为$ .plot需要数组系列数据。
修改后的代码:
$.plot($('#theGraph'), [graphData], options);
您可以提及数据系列可以在flot中绘制多行。
var d1 = [], d2 =[], d3 =[];
$.plot($('#theGraph'), [d1,d2,d3], options);