You must be logged in to post your query.
Home › Forums › Chart Support › click on a legend item to get its name?
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
@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
Perfect Vishwas! – just what I needed – thanks very much!
You must be logged in to reply to this topic. Login/Register