mobcdi
mobcdi

Reputation: 1592

Using chartjs v2 to show categorical values on axis instead of numeric

In chartjs v2 is there a way to change the numeric values on the axis to categorical text labels instead (low, medium, high) for example ?

Upvotes: 2

Views: 820

Answers (1)

potatopeelings
potatopeelings

Reputation: 41065

If you want to change just the tick labels use the callback property of ticks. For example

...
options: {
  scales: {
    yAxes: [{
      ticks: {
        callback: function(value) {
          if (value === 20)
            return 'Low';
          else if (value === 50)
            return 'Medium';
          else if (value === 80)
            return 'High';
          else
            return '';
        }
      }
    }]
  }
}

Fiddle - http://jsfiddle.net/1gfu0tfg/

Upvotes: 2

Related Questions