score:1

Accepted answer

you can add some flag to avoid looping through the first chart.

  $.each(highcharts.charts, function(i, chrt) {
    //
    // flag to avoid looping through the first chart
    //
    if (i !== 0) {
      $.each(chrt.series, function(j, serie) {
        let tmp_key = serie.name.replace(/[\s,-]/g, '');
        if (!object.keys(listed).includes(tmp_key)) {
          legend.append(
            '<div class="item ' + tmp_key + '"><div class="symbol" style="background-color:' +
            serie.color +
            '"></div><div class="seriename" id="">' +
            serie.name +
            '</div></div>'
          );
          listed[tmp_key] = [serie];
        } else {
          listed[tmp_key].push(serie);
        }
      });
    }
  });

demo: https://jsfiddle.net/blacklabel/yatz5m38/

score:0

a jsfiddle would be nice. do notice though that

            if (serie.visible) serie.setvisible(false);
            else serie.setvisible(true);

can be simplified to serie.setvisible(!serie.visible)


Related Query

More Query from same tag