Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Highcharts - How to get a value of a stack in a series?

I was wondering if it is possible to get the value of a stack in a series to use in my tooltip in Highcharts.

I got it using the this.series.stackKey like the following example:

$(function () {
    $('#container').highcharts({

        chart: {
            type: 'column'
        },

        title: {
            text: 'Total fruit consumtion, grouped by gender'
        },

        xAxis: {
            categories: ['Apples', 'Oranges', 'Pears', 'Grapes', 'Bananas']
        },

        yAxis: {
            allowDecimals: false,
            min: 0,
            title: {
                text: 'Number of fruits'
            }
        },

        tooltip: {
            formatter: function () {
                return '<b>' + this.x + '</b><br/>' +
                    this.series.name + ': ' + this.y + '<br/>' +
                    'Total: ' + this.point.stackTotal + ' Stack: ' + this.series.stackKey;
            }
        },

        plotOptions: {
            column: {
                stacking: 'normal'
            }
        },

        series: [{
            name: 'John',
            data: [5, 3, 4, 7, 2],
            stack: 'male'
        }, {
            name: 'Joe',
            data: [3, 4, 4, 2, 5],
            stack: 'male'
        }, {
            name: 'Jane',
            data: [2, 5, 6, 2, 1],
            stack: 'female'
        }, {
            name: 'Janet',
            data: [3, 0, 4, 4, 3],
            stack: 'female'
        }]
    });
});

But the tooltip shows me something like "columnfemale" and I want to see only the stack value:"female".

Fiddle: http://jsfiddle.net/5nLa3saf/

like image 261
valdeci Avatar asked Aug 12 '15 20:08

valdeci


1 Answers

The value of the stack option can be found in Series.options.stack.

For your code it would look like this (JSFiddle):

tooltip: {
    formatter: function () {
        return '<b>' + this.x + '</b><br/>' +
            this.series.name + ': ' + this.y + '<br/>' +
            'Total: ' + this.point.stackTotal + ' Stack: ' + this.series.options.stack;
    }
}
like image 133
Halvor Holsten Strand Avatar answered Sep 29 '22 06:09

Halvor Holsten Strand