score:16

Accepted answer

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

score:6

you can set showinlegend as false when you create the chart.

{
    name: 'tokyo',
    data: [7.0, 6.9, 9.5, 14.5, 18.2, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6],
    showinlegend: false
}

demo1

if you want to update it dynamically you can do the following.

options.series[1].showinlegend = false;
chart = new highcharts.chart(options);

you forgot to force chart to redraw.

demo

or chart.legend.allitems[1].destroy(); to remove the first one.

score:6

this can now be solved without any hacks through the series.update method (api). for example:

chart.series[0].update({ showinlegend: false });

see this jsfiddle demonstration. the method signature is:

update(object options, [boolean redraw])

where options are options for any regular series object. you can optionally halt redrawing to change multiple options before redrawing.


Related Query