Chart.js icon indicating copy to clipboard operation
Chart.js copied to clipboard

Is there a getPointsAtEvent() equivalent that returns the LABEL associated with the data point?

Open shoupjom opened this issue 11 years ago • 2 comments

I'm in the process of trying to write a custom function to accomplish this, but thought I'd check to see if someone else had already done it. Essentially instead of the data point value being returned I'd like the label associated WITH that data point value to be returned.

Use Case: I'm looking at a bar chart of sales by month... I click on the bar, it returns the month.

So it might be called, getLabelByPoint() or getLabelsByBar() or something like that...

shoupjom avatar Mar 25 '15 14:03 shoupjom

Progress update... set the canvas' onclick event to fire the getRelativePosition(e) method to obtain the x, y coordinates. Used the dataset object of my chart instance to return the x,y coordinates of each data point/label. I plan on looping over each data point coordinates and comparing to the onclick coordinates to determine the label of the datapoint/bar that was clicked. Right path? Overkill? Make sense?

shoupjom avatar Mar 25 '15 20:03 shoupjom

As far as I know, nothing like this exists in version 1. Version 2 has something similar to what you'd like using

scale.getLabelForIndex(dataIndex, datasetIndex)

etimberg avatar Dec 25 '15 02:12 etimberg