label: String

Sets label value of a dataPoint. The value appears next to the dataPoint on axisX Line. If not provided, it takes x value for label.

Default: x value
Example: “label1”, “label2”..
Notes
  • To make an axis appear as a category Axis, one must set label property for all dataPoints.
var  chart =  new  CanvasJS.Chart("container",
{
 .
 .
 data: [{
  dataPoints: [
   { y: 10,  label: "label1" },

   ],

  },
 ]
 .
 .
});
chart.render();

Try Editing The Code

  Also See:    


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

8 Comments

  1. Puneet says:

    Hi,
    In the above example when i add another datapoint { y: 23, label: ‘cat 9’ } the label appears twice on the X axis. How can i make the y point 23 appear in the old category itself. Just to add i also changed the series type to ‘line’

    • Anjali says:

      puneet,

      You have two options

      1. Change/Update existing dataPoint at “cat 9” like “chart.options.data[0].dataPoints[8].y = 23”
      2. Every dataPoint appears corresponding to x value – which we are assigning internally in this case. So we would suggest setting x value for all dataPoints so that you can control their position. So, two of your dataPoint would look like like: { y: 14, label: “cat 9”, x: 8} and { y: 23, label: “cat 9”, x: 8}.

  2. Albert says:

    Hi,

    Seems the label can only set on the axisX. Is there any way to set it on axisY?
    Because I want to show Time on axisX and category on axisY.
    Thanks in advance.

  3. stephen bourne says:

    Hi. I want to add labels to all of my datapoints, so that they show up as the tooltips. But, i want the x-axis to still appear as a numeric axis with numeric labels. Is there any way to do that?

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