Home Forums Chart Support X-axis click event Reply To: X-axis click event

#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