gpt4 book ai didi

javascript - Flot:以日期/时间为 x 轴的图表未正确绘制

转载 作者:行者123 更新时间:2023-12-03 10:34:18 24 4
gpt4 key购买 nike

我试图显示随时间变化的值,但无论我尝试绘制什么数据,图表上都不会出现任何内容。 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);

最佳答案

$.plot 方法获取要绘制图表的 div 的占位符/id。 $.plot('#id',.....) 也做同样的事情。

您的代码 $.plot() 中只有一个问题。参数“graphData”应位于 [] 大括号中,因为 $.plot 需要系列数据数组。

修改后的代码:

$.plot($('#theGraph'), [graphData], options);

您可以指定可能的数据系列来在flot中绘制多条线。

 var d1 = [], d2 =[], d3 =[];
$.plot($('#theGraph'), [d1,d2,d3], options);

关于javascript - Flot:以日期/时间为 x 轴的图表未正确绘制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29073522/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com