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.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #5702

    smbdy
    Participant

    Hello,

    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.

    #5703

    Sunil Urs
    Keymaster

    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

    #5705

    smbdy
    Participant

    Thanks a lot. That what I was looking for.

    #17808

    intijk
    Member

    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?

    #17820

    Bivek Singh
    Participant

    @intijk,

    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.

    —-
    Bivek Singh,
    Team CanvasJS

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.