是否可以将单位添加到图例中显示的Y轴值? 目前我可以显示图形,但需要修改图例。
答案 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;