score:153
try this to remove all chart series,
while(chart.series.length > 0)
chart.series[0].remove(true);
it works for me. the code
for (var i = 0; i < chart.series.length; i++)
won't work because the chart.series.length
is decreased each time remove()
is called. That way, the i
will never reach the expected length. Hope this helps.
score:-1
I found the working solution. Try this:
for (var i = 0; i < chart.series.length; i++) {
chart.series[0].remove();
}
chart.redraw();
It will completely remove all series.
score:0
It may just be a simple matter of telling the chart to redraw. When you remove a series, try forcing the chart to redraw:
for (var i = 0; i < chart.series.length; i++) {
chart.series[i].remove(true); //forces the chart to redraw
}
score:0
var seriesLength = chart.series.length;
for(var i = seriesLength -1; i > -1; i--) {
chart.series[i].remove();
}
score:0
You can also update and add a new series and if the new series is less than the current series then remove the series:
var hChart = $("#Chart").highcharts();
for (var i = 0; i < newSeries.length; i++) { //UPDATE-OLD/ADD-NEW SERIES
if (hChart.series[i])
hChart.series[i].update(newSeries[i]);
else
hChart.addSeries(newSeries[i]);
}
var serieslen = newSeries.length;
if (hChart.series[serieslen]) {
var loopfrm = hChart.series.length - 1;
for (var i = loopfrm; i >= serieslen; i--) {//REMOVE SERIES
hChart.series[loopfrm].remove();
}
}
score:1
The reason for (var i = 0; i < chart.series.length; i++)
doesn't work is because you're modifying the array while you're looping over it. To get around this, you can iterate over the array from right to left, so when you remove an element, the index of the array will still point to the last item in the array.
Using lodash's forEachRight, you can do:
_.forEachRight(chart.series, chartSeries => {
chartSeries.remove(false);
});
chart.redraw();
score:9
Another way to remove all series in HighCharts with a for loop is to start from the end. Here's how to do it:
var seriesLength = chart.series.length;
for(var i = seriesLength - 1; i > -1; i--) {
chart.series[i].remove();
}
I prefer to go this route because when using a HighStock chart, the navigator is usually the first series. I also prefer to keep a variable set to the navigator series. In that case, I'll do the following:
var seriesLength = chart.series.length;
var navigator;
for(var i = seriesLength - 1; i > -1; i--) {
if(chart.series[i].name.toLowerCase() == 'navigator') {
navigator = chart.series[i];
} else {
chart.series[i].remove();
}
}
Now I can easily set the navigator series.
Here's an example of removing all series from a Highchart: http://jsfiddle.net/engemasa/srZU2/
Here's an example of resetting a HighStock chart with new data (including the navigator series): http://jsfiddle.net/engemasa/WcLQc/
score:43
The following way the chart will not redraw every iteration.
So you'll get a better performance.
while( chart.series.length > 0 ) {
chart.series[0].remove( false );
}
chart.redraw();
Source: stackoverflow.com
Related Query
- Proper way to remove all series data from a highcharts chart?
- Highcharts - Remove first marker from Area chart in every series
- Creating a responsive accumulated rain chart from a series containing individual rain fall data using Highcharts
- Extract data series from a JSON array for a Highcharts chart with 2 y-axis
- HighCharts column chart populated with series data from a function
- highcharts series remove function deletes all original series data (even after stored in new variable)
- Highcharts data from google spreadsheet hide all series except one at start
- Highcharts remove legend and series from chart on legendItemClick
- Highcharts - Sankey chart not displaying all the data when series font increased
- Highcharts displays series names but missing data points from json source
- Highcharts data from Google spreadsheet show line chart for one series
- Highcharts - best way to handle and display zero (or negative) values in a line chart series with logarithmic Y axis
- Highcharts Column chart with drilldown, remove hyperlink like formatting from x-axis labels
- Highcharts - How can I remove starting and ending padding from area chart
- How can I delete all of the points from a highcharts series
- Add dynamic data to line chart from mysql database with highcharts
- HighCharts : How to add or remove "chart context menu" from chart container?
- Highcharts - remove points from series
- Setting data with null values doesn't remove dots from the chart
- adding series from existing highcharts chart
- How to show Legends for all the series data in stacked column chart Highcharts?
- Creating depth chart using highcharts and creating bids and asks in such a way that bids and asks are created from center of chart
- How to hardcode chart data in my Model then have my Controller pull it from there to display it. Using Highcharts
- How to remove sliced line from pie high chart if there there is only one object in data
- Highcharts polar chart wind rose data from JSON
- HighCharts Angular - data from API not showing in chart
- Highcharts series showing different data for 'column' and 'line' chart
- Highcharts stock chart based on data from Quandl API
- How to add Series data in Highcharts from MVC
- Can we get index from series data in highcharts
More Query from same tag
- How to create more gap between axis labels on a stacked bar chart?
- Highcharts time series combo graph where few months data is null
- HighCharts: How to toggle yAxis options on browser resize?
- return json arrays from symfony controller for many usage on highcharts.js
- Highcharts: adding line to graph removes labels from X axis
- Unable to plot dynamically updating y-values on Highcharts spline plot
- Paint segment of highcharts chart
- Highcharts - Why is there extra spacing before the first column and after the last column?
- Highcharts allowDecimals condition
- Replace highcharts with images for report?
- How do I add secondary axis to highstock charts?
- Highcharts Stacked Column chart change legendItemClick function
- Split json data
- How do i limit the range of the x or y value in High charts?
- Can the crosshair in a Highcharts chart set and be moved programmatically?
- How to show the value of all linked axes in tool tip in highcharts?
- Motion in drilldown bubble chart Highcharts
- Disable average values on highchart line graph
- Highstock + angular material + flex-layout problems
- Change color of Multibar chart in Django
- Div element not hiding even after hiding the tooltip in highcharts
- Some series are not visible in a time serie chart with columns
- Creating highchart linechart with data using PHP (and Laravel)
- Does highcharts have a callback function for before full chart reload (this should not include legends disable)?
- how do I process dynamically generated graph with PHP and send the result as an email?
- Highcharts dual X axis chart not scaling axis
- Export highcharts animation as video
- Add series to highcharts dynamically without initial data
- How to export the whole page or html content with Highcharts not just the chart?
- Is there a way to make highcharts tick lines point inwards rather than outwards