Home › forums › Using CanvasJS › click event for any cursor position
This topic contains 4 replies, has 4 voices, and was last updated by Bivek Singh 9 months, 3 weeks ago.
Is there any way to handle click event for any mouse position? I found only support for clicks on data points.
I would like to create mouse click handler for any cursor position and also I want to get the value of X axe corresponding to that position.
If not supported out of the box, where should I start looking in order to make such extension?
I’m considering some ugly approach – find the native Canvas element, add mouse handler there, calculate X value for this coordinate (I know max X value and canvas size), but this probably won’t be accurate cause axisY title takes some place on chart … and in general this sounds like a dirty hack.
What would you recommend? Thank you.
This will not be possible directly via the existing API. But if you are ok editing CanvasJS code, Axis has a function getXValueAt(x) which can convert given pixel value to X value on axisX. You can make it public by writing few lines of code inside CanvasJS object which is present at the end of file.
Hope this helps
Thanks a lot. That what I was looking for.
Is this still a workable solution?
We need to purchase one license to get the code to do this hack?
Could I do it in trial version?
You can use convertPixelToValue method to fetch axis value for any given pixel co-ordinate. You can also get pixel co-ordinate for any axis value using convertValueToPixel.
You must be logged in to reply to this topic.