2013-09-25 73 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