Home Forums StockChart Support Callback for click with crosshair at arbitrary position in stock chart

Callback for click with crosshair at arbitrary position in stock chart

Viewing 2 posts - 1 through 2 (of 2 total)
  • #44178

    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?

    #44182

    @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.

    Adding y-axis stripline on clicking inside stockchart

    __
    Sachin Bisht
    Team CanvasJS

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

You must be logged in to reply to this topic.