Formatting axisY labels to percentage - CanvasJS JavaScript Charts

Formatting axisY labels to percentage - CanvasJS JavaScript Charts

by canvasjs

HTML

<script src="https://canvasjs.com/assets/script/canvasjs.min.js"></script>
<br/><!-- Just so that JSFiddle's Result label doesn't overlap the Chart -->
<div id="chartContainer" style="height: 360px; width: 100%;"></div>

JavaScript

var chart = new CanvasJS.Chart("chartContainer",
{ 
	data: [
	{
		type: "bar",
		dataPoints: [
			{ x: 10, y: 73451 },
			{ x: 20, y: 90345 },
			{ x: 30, y: 54560 },
			{ x: 40, y: 54365 },
			{ x: 50, y: 98675 },
			{ x: 60, y: 68645 },
			{ x: 70, y: 28455 },
			{ x: 80, y: 34453 },
			{ x: 90, y: 14564 }
		]
	}					
	]
});

var max = chart.options.data[0].dataPoints[0].y;

for(var i = 0; i < chart.options.data[0].dataPoints.length; i++) {
  if(max < chart.options.data[0].dataPoints[i].y) 
    max = chart.options.data[0].dataPoints[i].y;
}

chart.options.axisY = {
	viewportMaximum : max,
  viewportMinimum : 0,
  interval : max / 10,
  labelFormatter: function(e) {
      return Math.round(e.value / max * 100) + "%";
    }
};

chart.render();