labelFormatter : Function

A custom formatter function that returns label to be displayed on axisX.

Notes
  • labelFormatter function should return a string.
  • You can use formatNumber and formatDate functions to format number/date values inside the formatter function.
var  chart =  new  CanvasJS.Chart("container",
{
 .
 .
axisX:{
        labelFormatter: function ( e ) {
               return "x: " + e.value;  
         }  
},
 .
 .
});
chart.render();
  • By using labelFormatter, you can return any value to be displayed on axis.
    Below is the structure of object passed as parameter to the function
e: { // parameter sent to function
       chart,
       axis,
       value,
       label
 }
Note

If you have to access any preset options of the chart, you can access them via e.chart.options. For example e.chart.options.title.text


Try Editing The Code

labelFormatter Example using formatDate function

Try Editing The Code


If you have any questions, please feel free to ask in our forums.Ask Question

8 Comments

  1. Shravan says:

    am trying to plot x-axis labels using labelFormatter from a json object where it consists of date and value.
    May I know how to do that ?

  2. Isaac Nehmad says:

    Hi

    Is there a way to format the label with html, like doing the label with a border or place a where i need

If you have any questions, please feel free to ask in our forums. Ask Question