-
Notifications
You must be signed in to change notification settings - Fork 11.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to listen for clicks on labels? #2802
Comments
There is a method on the scale to go from the pixel to the correct label. I am on mobile so i can't post a fiddle, but the zoom and pan plugin in the chartjs organization uses it |
Thanks. I've just gone through the scales docs and I don't see such a function. Could it be undocumented or am I missing it? |
I don't think it is currently documented. The bit in the zolm and pan plugin is in |
Thanks for putting me on the right track. The
I then try to access the function of interest by making one of the following calls inside the
The chart renders normally so I know that |
Those functions are on a particular scale. Scales can be found in |
@RoxKilly did you get this working? If so, can you please close this issue? |
No I haven't gotten it working. Thanks to your help I'm now able to call the function in question with To see what I'm trying to capture, use the input above the chart to select how many bars you want on the chart, then press the button next to the input. Once the chart is built, click the y-axis labels (not the data bars) and the result of calling
Because I don't have a reliable pattern, I still don't know how to get the text of the yLabel that was clicked. |
@RoxKilly I got your plunkr working a bit better here. I used It works a bit better :) For some reason the first label is not shown on the first label (index 0). Not sure why. |
Thanks for moving the ball forward on this. I was pretty frustrated before but I'm encouraged now. |
@etimberg Actually, your fix works! Index 0 was not getting printed because I would only print if value was truthy, and zero failed the Thanks a bunch. |
@RoxKilly awesome. Glad it works 😄 |
I celebrated too soon it seems. The results of Unless you have another idea this seems to be the end of the road for what I can do without changing the library itself. |
@RoxKilly sorry about that. There is an error in the function the category scale uses to go backwards. I fixed it in #2870. I updated your plunk with a hotpatch: http://plnkr.co/edit/GsOi2hX42389VJnuzGhv?p=preview |
A typo on line 7 of your Plunk's
With
by capitalizing the 'c' in "Chart". Initial testing is positive; the fix seems to work with both horizontal and vertical bar charts (the types I can confirm were not working before). Thanks again. Closing. |
My bad on the typo. Hadn't had coffee yet 😛 |
v2.1.6
My use case must be pretty common so I bet it has been solved but I can't find anything in the docs. I have a horizontal bar chart. When the user focuses on a category (clicks the bar), I show detailed info elsewhere in the view.
Often a category has
value=0
, so there is no bar to click on. Ironically these are the categories most interesting to my user (a low bar means a problem that requires the user's attention) so I still need to give the user a way to show the category details in the view. Any user would expect that he could just click the category name (the yAxis label in my horizontal bar chart) to select that category. So my problem is simple: What's the cleanest way to detect which label was clicked on?The text was updated successfully, but these errors were encountered: