user1751287 user1751287 - 6 months ago 42
Javascript Question

chartjs custom y axis values, different text for each one

I am trying to change numeric values within y axis with custom text ones. I tried using loop but it takes only the first one.

callback:function(value) {
var value = ["January", "February", "March", "April", "May"];
for(i = 0; i < value.length; i++){
return value[i];
}

}


here is FIDDLE with the sample graph

maybe case of something ?

Answer

Try to return value from the array properly,

callback:function(value) { 
  var x = ["January", "February", "March", "April", "May", "June", "July"];
  return x[value | 0];                  
}

DEMO

Comments