Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Check and Uncheck all the Legend elements in HighCharts Linechart?

I want customize the checking and unchecking legend elements all at once, iam not getting any idea, can we do this? let me know way to do this..

like image 637
sakar Avatar asked Dec 02 '22 23:12

sakar


2 Answers

This is an example that does that, plus a variety of other things with legend items and checkboxes, using a series of external controls:

http://jsfiddle.net/simo/57SR9/94/

function:

$('#checkAll').click(function(){
    for(i=0; i < chart.series.length; i++) {
        if(chart.series[i].selected == false){
            chart.series[i].select();
            showSeries.call(chart.series[i], {checked: true});
        }
    }
});
like image 200
jlbriggs Avatar answered Jan 03 '23 18:01

jlbriggs


You can iterate over each series inside the chart and call show() or hide() function, depending on what you want to do. This solution is similar to the previous answers, but calling using the show/hide functions

i = 0;

while (i < chart.series.length) {
    if (chart.series[i].visible === false) { // here you can filter the visible series
        chart.series[i].select();
        chart.series[i].show(); // here you can call hide()
        i++;
        return;
    }
}
like image 43
Hugo Nugra Avatar answered Jan 03 '23 18:01

Hugo Nugra