2012-06-05 66 views
1

我有以下JS數據:jQuery的海軍報圖不繪製

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

由於提前,

+0

你的html樣子是什麼? – Jason

+0

Lee

回答

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

我有這個問題,我想你需要用你的陣列中的另一個陣列...

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

不錯的提示,這也有幫助 – Lee

1

您需要將您的x軸模式設置爲'時間',並提供日期作爲時間戳ps以毫秒爲單位。請參閱「時間序列數據」標題下的API Docs以獲取更多信息。