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 5 days, 23 hours ago.

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

    JohnJeff
    Member

    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

    Vishwas R
    Keymaster

    @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

    JohnJeff
    Member

    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.