2013-09-25 71 views
1

我正在用Dygraphs構建線性圖。我在x軸上有「1 2 3 4」,在y軸上有「12,55,23,18」。當我繪製圖形時,刻度線具有中間數字。Dygraphs「x軸」介於範圍

例如,在1和2之間,我可以在x軸上看到1.5。我希望將確切的時間間隔定義爲1個增量。有沒有辦法解決這個問題?如何在Dygraph中做到這一點?這是一個例子:

<html> 
<head> 
<script type="text/javascript" 
    src="dygraph-combined.js"></script> 
</head> 
<body> 
<div id="graphdiv"></div> 
<script type="text/javascript"> 
    g = new Dygraph(

    // containing div 
    document.getElementById("graphdiv"), 
    // CSV or path to a CSV file. 
    ("Response Time,Loop\n" + 
    "01,175\n" + 
    "02,170\n" + 
    "03,180\n" + 
    "04,177\n" + 
    "05,179\n"+ 
    "06,165\n") 
); 
</script> 
</body> 
</html> 

回答

2

有沒有內置的支持(你應該明星issue 368)。但是你可以通過定義返回非整數空字符串的axisValueFormatter模擬它:

axes: { 
    x: { 
     axisLabelFormatter: function(num, gran, opts, g) { 
      if (num == Math.floor(num)) { 
       return Dygraph.numberAxisLabelFormatter(num, gran, opts, g); 
      } else { 
       return ''; 
      } 
     } 
    } 
} 

全功能的演示here