Home Forums StockChart Support convertValueToPixel in StockChart Reply To: convertValueToPixel in StockChart



In case of StockChart, you need to use the convertValueToPixel method with respect to individual charts to get their corresponding pixel coordinates as shown in the code snippet below –

document.getElementById("displayYPixel").innerHTML = "Y-Pixel Coordinates of the dataPoint is: " + Math.round((stockChart.charts[e.chart.index].container.offsetTop + stockChart.charts[e.chart.index].axisY[0].convertValueToPixel(e.dataPoint.y))) + "px";
document.getElementById("displayXPixel").innerHTML = "X-Pixel Coordinates of the dataPoint is: " + Math.round((stockChart.charts[e.chart.index].container.offsetLeft + stockChart.charts[e.chart.index].axisX[0].convertValueToPixel(e.dataPoint.x))) + "px";

Please check this JSFiddle for an example on displaying the pixel coordinate of a dataPoint on click.

Display Pixel Coordinate of dataPoint in StockChart

Indranil Deo
Team CanvasJS