You must be logged in to post your query.
Home › Forums › StockChart Support › Callback for click with crosshair at arbitrary position in stock chart
Tagged: Crosshair
I want to click with the crosshair at an arbitrary position in the stock chart to place an alarm threshold. I can click on candle sticks and define a callback to be called on click. But can I also define a callback at any other position in a candle stick chart to retrieve the Y value of the click position in order to define an alert threshold?
@tuelle42,
You can get to know y-value of the clicked position anywhere on the chart by converting the pixel coordinates of the event to y-value using convertPixelToValue method as shown in the code snippet below.
$(stockChart.charts[0].container).on("mousedown", function(e) { var offset = $(this).offset(); var relY = e.pageY - offset.top; stockChart.charts[0].axisY[0].addTo("stripLines", { value: stockChart.charts[0].axisY[0].convertPixelToValue(relY) }); });
Kindly take a look at this JSFiddle for adding a stripline to y-value corresponding to the event coordinate.
__ Sachin Bisht Team CanvasJS
You must be logged in to reply to this topic. Login/Register