Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enable or disable data labels shown in pie charts in Highcharts on click of a button

Tags:

highcharts

I have a dynamic pie chart. On the click of a button the data labels shown when dataLables is true to show data points and when it is false it should be hidden.

plotOptions: {
    pie: {
        allowPointSelect: false,
        cursor: 'pointer',
        dataLabels: {
            enabled: false
        }
    }
}
like image 514
Leo Avatar asked Apr 09 '13 15:04

Leo


1 Answers

You can use the API to toggle the series plot options like this:

    var chart = $('#container').highcharts();
    var opt = chart.series[0].options;
    opt.dataLabels.enabled = !opt.dataLabels.enabled;
    chart.series[0].update(opt);

e.g. http://jsfiddle.net/sYMcs/

chart.series[0].options gets the options applying to series 0. series.update amends the current options, and redraws the chart.

like image 79
SteveP Avatar answered Sep 23 '22 01:09

SteveP