2014-04-29 23 views
1

請幫助我第一次嘗試使用dygraphs。我有以下代碼不會生成圖表。我做錯了什麼?使用unix時間的dygraph不會顯示任何東西

http://jsfiddle.net/52Qv4/1/

g = new Dygraph(

    // containing div 
    document.getElementById("graphdiv"), [ 
     [1396411199, 50, 10], 
     [1396497599, 63, 11], 
     [1396583999, 120, 12], 
     [1396670399, 55, 20], 
     [1396756799, 60, 22], 
     [1396843199, 63, 25], 
     [1396929599, 52, 25] 
    ], 
    // options 
    { 
     xRangePad: 10, 
     yRangePad: 10, 
     xValueFormatter: Dygraph.dateString_, 
     xValueParser: function (x) { 
      return parseInt(x, 10); 
     }, 
     xTicker: Dygraph.dateTicker, 
     labels: ["Dates", "Not Kept", "Hosts"], 
     title: "Promises not kept", 
     legend: "always", 
     drawPoints: "true", 
     pointSize: 2, 
     colors: ["orange", "blue", "black"], 
     strokeWidth: 0 
    }); 
+0

你撥弄失敗。使用dygraphs.com/fiddle作爲模板來解決這個問題。另外,你會想要使用毫秒以來的紀元,而不是自紀元以來的秒數。您應該打開控制檯並按照它提供的建議 - 您正在使用一些已棄用的選項。 – danvk

+0

更新了小提琴,但結果仍然相同。我看不到如何工作控制檯是jsfiddle。我確實有本地副本,控制檯顯示錯誤:'TypeError:s.toExponential不是函數'http://jsfiddle.net/52Qv4/5/ –

回答

0

見Dygraphs文檔:http://dygraphs.com/data.html。它指出:

xValueParser affects CSV only

更新代碼中使用CSV的工作原理:因爲它沒有包括dygraphs的JavaScript

g = new Dygraph(

    // containing div 
    document.getElementById("graphdiv"), 
      "Date,Series1,Series2\n" + 
       "1247382000,50,20\n" + 
       "1247986800,50,10\n", 
    // options 
    { 
     xRangePad: 10, 
     yRangePad: 10, 
     xValueFormatter: Dygraph.dateString_, 
     xValueParser: function (x) { 
      return 1000 * parseInt(x, 10); 
     }, 
     xTicker: Dygraph.dateTicker, 
     labels: ["Dates", "Not Kept", "Hosts"], 
     title: "Promises not kept", 
     legend: "always", 
     drawPoints: "true", 
     pointSize: 2, 
     colors: ["orange", "blue", "black"], 
     strokeWidth: 1 
    }); 

Here is your updated FIDDLE