Is there anyway to remove a series by name or id? I mean it is possible to remove series by this.remove()
or
var seriesLength = chart.series.length;
for(var i = seriesLength - 1; i > -1; i--) {
chart.series[i].remove();
}
but by name say, series_name.remove()
is it possible?
You could probably just iterate through the series and check the . name against your "passed in name" instead of scanning the document for "series_name". There really should be a chart. remove(series) (not just index, because the indices remap after you remove one).
Highchart by default puts a credits label in the lower right corner of the chart. This can be removed using credits option in your chart settings. will remove the highcharts.com logo.
The legend displays the series in a chart with a predefined symbol and the name of the series. Series can be disabled and enabled from the legend.
Well, I don't know if at the time it was possible, but now you have a get
function in the chart
object to which you can pass an id
and retrieve an element within the chart
.
For example:
var chart = new Highcharts.Chart({
chart: { renderTo: 'container' },
series: [
{
id: 'series-1',
data: [1,2,3,4,5,6,7,8,9]
},
{
id: 'series-2',
data: [9,8,7,6,5,4,3,2,1]
}
]
});
//Remove the 'series-2'
chart.get('series-2').remove();
Working example in jsfiddle
Ok, I found it myself. I send the series name in a hidden field of a div and when I click the delete button I'm checking if the name matches among the series and if match found I delete it.
var chart = $('#container').highcharts();
var seriesLength = chart.series.length;
for(var i = seriesLength - 1; i > -1; i--)
{
//chart.series[i].remove();
if(chart.series[i].name ==document.getElementById("series_name").value)
chart.series[i].remove();
}
These two simple solutions work for me.
UPDATE : I realized I misunderstood the question. These solutions remove all the ledends.
$(function () {
// Build the chart.
$('#volume_pie_chart').highcharts({
// Some configuration code...
})
// Hide the legend.
$('.highcharts-legend').hide()
});
...
},
legend: {
x: 9999, // Make the legend invisible.
y: 9999
},
...
This needs more visibility, because this is fairly janky. You could probably just iterate through the series and check the .name against your "passed in name" instead of scanning the document for "series_name".
There really should be a chart.remove(series) (not just index, because the indices remap after you remove one).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With