Jquery flot graph没有绘图

时间:2012-06-05 20:26:37

标签: javascript jquery charts flot

我有以下JS数据:

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]);

剧情代码:

$.plot($('.chart'), store);

HTML:

<div class="chart"></div>

x和y上的我的轴只显示从-1到1 ..我根本无法看到图形绘图。我哪里错了?

enter image description here

提前致谢,

3 个答案:

答案 0 :(得分:3)

我有这个问题,我认为你需要将你的数组包装在另一个数组中......

$.plot($('.chart'), [store]);

答案 1 :(得分:2)

试试这个:

<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>

答案 2 :(得分:1)

您需要将x轴模式设置为“时间”,并将日期作为时间戳(以毫秒为单位)。有关详细信息,请参阅“时间序列数据”标题下的API Docs