Home Forums Chart Support X-axis click event

X-axis click event

Viewing 3 posts - 1 through 3 (of 3 total)
  • #42219

    If I click on axis x, how do I get the x coordinate of this point

    #42236

    @weijian-zhu2,

    You can bind mouse events to the chart container and get mouse coordinates in pixels, which can be converted to corresponding values along the axis using convertPixelToValue as shown in this documentation page. Please take a look at the code snippet below:

    jQuery(".canvasjs-chart-canvas").last().on("click", 
        function(e){
    	var parentOffset = $(this).parent().offset();
    	var relX = e.pageX - parentOffset.left;
    	var xValue = Math.round(chart.axisX[0].convertPixelToValue(relX));
    	console.log(xValue);
    });


    Thangaraj Raman
    Team CanvasJS

    #42238

    Thank you very much. I’ll try it right away

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

You must be logged in to reply to this topic.