Home Forums Chart Support click on a legend item to get its name?

click on a legend item to get its name?

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

    Hi,

    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?

    TIA

    JohnJeff

    #23024

    @johnjeff,

    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

    #23035

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

    JohnJeff

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

You must be logged in to reply to this topic.