Filtering legend of a Highcharts by only visible series

前端 未结 3 2061
情话喂你
情话喂你 2020-12-31 15:48

We are using Highcharts and have some complex charts with roughly 75 series within on chart. The series are not used through the whole chart but only for range of three mont

3条回答
  •  旧时难觅i
    2020-12-31 16:33

    Well just setting the showInLegend doesn't do the trick, there are some more hooks that need to be taken care of

    Refer Halvor Strand's answer for a more recent way


    Old trick but still works

    To Add

    item.options.showInLegend = true;
    chart.legend.renderItem(item);
    chart.legend.render();
    

    To Remove

    item.options.showInLegend = false;
    item.legendItem = null;
    chart.legend.destroyItem(item);
    chart.legend.render();
    

    where, item can be a point or series

    var item = chart.series[1];
    

    Add Remove Legend Dynamically | Highchart & Highstock @ jsFiddle

提交回复
热议问题