Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chart.js - Formatting Y axis

I'm using Chart.js to draw a simple bar plot and I need to format its Y axis like

123456.05 to 123 456,05 $

I don't understand how to use scaleLabel : "<%=value%>"

I saw someone pointing to "JS Micro-Templating",
but no clue how to use that with our scaleLabel option.

Does someone know how to format this Y axis, and maybe give me an example ?

like image 720
Pierre de LESPINAY Avatar asked Dec 04 '13 09:12

Pierre de LESPINAY


1 Answers

I had the same problem, I think in Chart.js 2.x.x the approach is slightly different like below.

ticks: {     callback: function(label, index, labels) {         return label/1000+'k';     } } 

More in details

var options = {     scales: {         yAxes: [             {                 ticks: {                     callback: function(label, index, labels) {                         return label/1000+'k';                     }                 },                 scaleLabel: {                     display: true,                     labelString: '1k = 1000'                 }             }         ]     } } 
like image 115
Jaison James Avatar answered Sep 30 '22 04:09

Jaison James