【发布时间】:2017-02-06 08:58:56
【问题描述】:
是否可以将单位添加到图例中显示的 Y 轴值? 目前我可以显示图表,但需要修改图例。
【问题讨论】:
标签: dygraphs
是否可以将单位添加到图例中显示的 Y 轴值? 目前我可以显示图表,但需要修改图例。
【问题讨论】:
标签: dygraphs
您可以使用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>
【讨论】:
valueFormatter 上的文档。参数之一是系列名称。