1

我有以下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.. 我根本看不到绘图。我哪里错了?

在此处输入图像描述

提前致谢,

4

3 回答 3

3

我遇到了这个问题,我认为您需要将数组包装在另一个数组中...

$.plot($('.chart'), [store]);
于 2012-06-05T20:54:31.047 回答
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>
于 2012-06-05T20:47:52.780 回答
1

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

于 2012-06-05T21:08:42.910 回答