簡體   English   中英

jQuery Flot圖形未繪制

[英]Jquery flot graph not plotting

我有以下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。我根本看不到圖形。 我要去哪里錯了?

在此處輸入圖片說明

提前致謝,

我遇到了這個問題,我想您需要將數組包裝在另一個數組中。

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

嘗試這個 :

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

您需要將x軸模式設置為“時間”,並以毫秒為單位提供日期作為時間戳。 有關更多信息,請參見“時間序列數據”標題下的API文檔

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM