【问题标题】:Dygraph Y-axis label unitDygraph Y轴标签单元
【发布时间】:2017-02-06 08:58:56
【问题描述】:

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

【问题讨论】:

    标签: dygraphs


    【解决方案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>

    【讨论】:

    • 嗨,如果不同的列有不同的单位,我该如何处理?
    • 查看valueFormatter 上的文档。参数之一是系列名称。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多