Enzo
Enzo

Reputation: 962

Highcharts modify stacklabels dynamically

I use stacklabels in my stacked bar chart.

stackLabels: {
    rotation : angelLabel,
    style: {
        fontSize: labelFontSize,
        fontFamily: labelFontFamily
    },
    enabled:true,
    color: '#000000',
    useHTML: true
}

The code above works well at initialization. Now, I need to change "enabled" to false. The code below is not working.

   chart.options.yAxis[0].stackLabels.enabled = false;
   chart.redraw();

How can i change stacklabels dynamically?

Upvotes: 2

Views: 827

Answers (1)

Kacper Madej
Kacper Madej

Reputation: 7896

stackLabels is a property of a yAxis, so you could update that axis using API function Axis.update()

$(function () {
    var chart = $('#container').highcharts({
        chart: {
            type: 'column'
        },
        yAxis: {
            stackLabels: {
                enabled: true
            }
        },
        plotOptions: {
            column: {
                stacking: 'normal'
            }
        },

        series: [{
            data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4]
        }, {
            data: [144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4, 29.9, 71.5, 106.4, 129.2]
        }]
    }).highcharts();

    var enable = true;
    $('#button').click(function () {
        enable = !enable;
        chart.yAxis[0].update({
            stackLabels: {
                enabled: enable
            }
        });
    });
});

Example: http://jsfiddle.net/yqypj4qr/

Upvotes: 3

Related Questions