Harish Nayak
Harish Nayak

Reputation: 348

Dygraph Y-axis label unit

Is it possible to add Units to Y-axis values that are showing in legends?. currently I can able to display graph, but need to modify the legends.

Upvotes: 1

Views: 1441

Answers (1)

danvk
danvk

Reputation: 16903

You can do this with a 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>

Upvotes: 1

Related Questions