简体   繁体   English

Flot:日期/时间为x轴的图形无法正确绘制

[英]Flot: Graph with Date/Time as x axis not plotting correctly

I am trying to display values over time, but no matter what data I try and plot, nothing appears on the graph. 我试图显示随时间变化的值,但是无论我尝试绘制什么数据,图形上都不会出现任何内容。 JsFiddle here . JsFiddle在这里

See code below. 请参见下面的代码。 What am I doing wrong? 我究竟做错了什么?

HTML: HTML:

<div id="theGraph"></div>

CSS: CSS:

#theGraph{
    height:300px;
    width:500px;
}

Javascript: 使用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 method takes the place holder / id of your div where you want to plot the graph. $ .plot方法将div的占位符/ id用作您要绘制图形的位置。 $.plot('#id',.....) also do the same. $ .plot('#id',.....)也一样。

And only one problem in your code $.plot(). 在您的代码$ .plot()中只有一个问题。 The argument 'graphData' should be in [] braces as $.plot expects array of series data. 参数'graphData'应该放在[]中,因为$ .plot需要序列数据数组。

Modified Code: 修改后的代码:

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

You can mention may data series to draw multiple lines in flot. 您可以提及may数据系列以在flot中绘制多条线。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM