Highcharts - Point Index

Returning the index of a selected point.

by Scott Engemann

HTML

<script src="http://highcharts.com/js/testing.js"></script>
<script src="http://code.highcharts.com/highcharts.js"></script>
<div id="container" class="chart"></div>

CSS

.chart {
    height: 400px;
}

JavaScript

$(function() {
    $('#container').highcharts({
        chart: {
            type: 'column'
        },
        xAxis: {
            categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
        },
        
        plotOptions: {
            series: {
                cursor: 'pointer',
                events: {
                    click: function(e) {
                        // Log to console
                        alert(this.name + ' clicked\n' +
                              'Alt: ' + event.altKey + '\n' +
                              'Control: ' + event.ctrlKey + '\n'+
                              'Shift: ' + event.shifkKey + '\n'+
                              'Index: ' + event.point.x);
                    }
                }
            }
        },
        
        series: [{
        name: 'Foo',
        data: [{
            y: 3,
            myData: 'firstPoint'
        }, {
            y: 7,
            myData: 'secondPoint'
        }, {
            y: 1,
            myData: 'thirdPoint'
        }]
    }]
    });
});