Home Forums Chart Support How do I show y-axis with data converted to percentage Reply To: How do I show y-axis with data converted to percentage

#35281

Suhas Patil,

You can use labelFormatter function on axisY to convert the axisY labels to percentages.

To switch the axisY labels from percentages to absolute values you can create a drop-down menu with the respective options. Based on the option selected you can update the labelFormatter function and then call chart.render().

document.getElementById("changeAxisYLabel").addEventListener('change', function(event){
  if (event.target.value == "absoluteValue") {
    chart.options.axisY.labelFormatter = function(e) {
      return e.value;
    }
  }
  else if (event.target.value == "percentage") {
    chart.options.axisY.labelFormatter = convertToPercentage;
  }
  chart.render();
});

Please take a look at this JSFiddle for a working example on the same.

Chart with Axis Y Labels as Percentage


Thangaraj Raman
Team CanvasJS