Dygraph Y轴标签单元

时间:2017-02-06 08:58:56

标签: dygraphs

是否可以将单位添加到图例中显示的Y轴值? 目前我可以显示图形,但需要修改图例。

1 个答案:

答案 0 :(得分:1)

您可以使用valueFormatter

执行此操作



new Dygraph(
    document.getElementById("graph"),
    "X,Y\n" +
    "1,0\n" +
    "2,2\n" +
    "3,8\n",
    {
      legend: 'always',
      axes: {
        y: {
          valueFormatter: function(v) {
            return v + ' mph';  // controls formatting in the legend/mouseover
          },
          axisLabelFormatter: function(v) {
            return v + ' mph';  // controls formatting of the y-axis labels
          }
        }
      }
    });

<link href="https://cdnjs.cloudflare.com/ajax/libs/dygraph/2.0.0/dygraph.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/dygraph/2.0.0/dygraph.js"></script>
<div id="graph" style="height: 200px;"></div>
&#13;
&#13;
&#13;