Majid Darabi
Majid Darabi

Reputation: 741

highstock chart click get closest point

I use Highstock to display time series data and I want to get the closest data point to the point where a user clicks on the chart. Is there any API to do it ?

P.S: I know how to do it by getting xAxis value and searching over series but I want to know is there any built-in function or not ?

Thank you

Upvotes: 1

Views: 457

Answers (1)

Paweł Fus
Paweł Fus

Reputation: 45079

There's no official API to get this.

However, look int othe sources, where you can find: runPointActions method. You can use exactly the same solution as for shared tooltip or default one.

Snippet from sources:

    // Separate tooltip and general mouse events
    followPointer = hoverSeries && hoverSeries.tooltipOptions.followPointer;
    if (hoverSeries && hoverSeries.tracker && !followPointer) { // #2584, #2830

        // get the point
        point = hoverSeries.tooltipPoints[index]; 
        // ABOVE LINE IS INTERESTENING, RIGHT? ;) where: index = pointer.getIndex(e),

        // a new point is hovered, refresh the tooltip
        if (point && point !== hoverPoint) {

            // trigger the events
            point.onMouseOver(e);

        }

    }

Upvotes: 1

Related Questions