Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get index of a point in Highcharts?

I'm using "Time data with irregular intervals" chart of Highcharts. As you know when mouse moves over points of line the formatter function runs and shows some information. I want to know index of the point that mouse moves over it. So if mouse moves over first point of the line, tooltip shows "1" and the second point shows "2" and so on. thnx.

like image 862
Morteza Avatar asked Dec 14 '11 16:12

Morteza


3 Answers

This worked for me using v2.2:

this.series.data.indexOf( this.point )
like image 192
Edgar Avatar answered Oct 07 '22 22:10

Edgar


One way is to pre-process the data to contain a property with the index. In the Snow-depth example you could do a preparation like this:

function prepare(dataArray) {
    return dataArray.map(function (item, index) {
        return {x: item[0], y: item[1], myIndex: index};
    });
};

to convert the array of [x, y] to be an object like { x: x, y: y, myIndex: i}. Then its easy to pick up that index in the formatter with:

formatter: function() {
     return 'point ' + this.point.myIndex;
}

Example on jsfiddle

like image 40
eolsson Avatar answered Oct 07 '22 20:10

eolsson


For the record your can do it directly in a nice way

It is store in:

this.points[0].point.x
like image 38
user789148 Avatar answered Oct 07 '22 22:10

user789148