Home forums Using CanvasJS click on a legend item to get its name?

This topic contains 2 replies, has 2 voices, and was last updated by  JohnJeff 11 months, 2 weeks ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
  • #23022


    I would like to be able to click on an item in the legend to get its content. e.g. the following script returns “my item is: [object Object]”

    legend: {
                    display: true,
                    position: 'bottom',
                    // on click of a legend
                    onClick: function (evt, item) {
                        console.log("my item is: " + item);

    So, what’s in the [Object Object] array??? Is there some way I can get the name of the legend item — and pass it on into a function to do whatever?





    Please refer documentation of itemClick for attaching click event to legend items. It gives event-object with chart, dataPoint, dataSeries, etc as parameters. Using e.dataSeries.name you can get the name of the legend item (if name is set for that dataSeries).

    If you are still facing the issue, kindly create JSFiddle reproducing the issue you are facing so that we can look into your code, understand the issue better and help you out.

    Vishwas R
    Team CanvasJS


    Perfect Vishwas! – just what I needed – thanks very much!


Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.