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 it Yourself by Editing the Code below.

labelFormatter Example using formatDate function

Try it Yourself by Editing the Code below.



In order to provide better support,we have closed the comments and switched completely to our Forums.
If you have any questions, please feel free to ask in our forums.

Comments 8

  1. 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. Hi

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

In order to provide better support,we have closed the comments and switched completely to our Forums.
If you have any questions, please feel free to ask in our forums.