score:0
Forked because I wanted behavior to change. Originally when a user selected two series and then tried to unselect one ... the whole series would swap visibility. I check to see if all other series are "all else visibile" or "all else not visible" first before swapping the visibility for the series.
http://jsfiddle.net/nd0dcdmz/3/
legendItemClick: function(e) {
var seriesIndex = this.index;
var series = this.chart.series;
// test for if all other series besides one selected are visible or not visible
var allElseVisible = series.every(
s => (s.index == seriesIndex ? true : s.visible),
);
var allElseNotVisible = series.every(
s => (s.index == seriesIndex ? true : !s.visible),
);
// if everything else is deselected or selected ... swap visibility
// else swap the visibility of selected object.
if (allElseVisible || allElseNotVisible) {
series.map(s => {
if (s.index != seriesIndex) {
s.visible ? s.hide() : s.show();
}
});
} else {
return true;
}
return false; // overrides default behavior
},
score:1
If you want to keep the normal functionality but also be able to show/hide all then create a button or a link for a show_all()
/hide_all()
javascript method.
this method initializes a counter and starts the showing/hiding:
counter = 0;
setTimeout(process_hide, 1);
function process_hide()
{
your_chart.series[counter].hide();
counter+=1;
if (counter < read_chart.series.length) {
setTimeout(process_hide, 1);
}
}
The reason you do this instead of just doing $.each(your_chart, function(i,v){v.hide()})
is that it locks up the UI - using the timeout you'll actually see the series being hidden one by one - and if you want to modify something else - like a process meter, it'll actually work.
score:1
Forked index's answer and added functionality to have individual toggles for each series. http://jsfiddle.net/c4Zd8/1/
$.each(allSeries, function(index, series) {
if (selected == index) {
if (series.visible == true) {
series.hide();
}
else {
series.show();
}
}
});
score:2
Just sharing cause @igor's answer doesn't work on me, so I made adjustments, here's the fiddle (forked from the @igor's answer)
score:11
I wanted to do something similar... I wanted to have it so that if you control-click (or cmd-click) a legend item, it would hide ALL OTHER items. (But leave normal clicks as their default behavior).
plotOptions: {
series: {
events: {
legendItemClick: function(e) {
// Upon cmd-click of a legend item, rather than toggling visibility, we want to hide all other items.
var hideAllOthers = e.browserEvent.metaKey;
if (hideAllOthers) {
var seriesIndex = this.index;
var series = this.chart.series;
for (var i = 0; i < series.length; i++) {
// rather than calling 'show()' and 'hide()' on the series', we use setVisible and then
// call chart.redraw --- this is significantly faster since it involves fewer chart redraws
if (series[i].index === seriesIndex) {
if (!series[i].visible) series[i].setVisible(true, false);
} else {
if (series[i].visible) series[i].setVisible(false, false);
}
}
this.chart.redraw();
return false;
}
}
}
}
}
score:48
Every event in HighCharts contains this
value which contains current element (series in this case). You can select all series using this.chart.series
and handle them in any way you want. Try this function.
legendItemClick: function(event) {
if (!this.visible)
return false;
var seriesIndex = this.index;
var series = this.chart.series;
for (var i = 0; i < series.length; i++)
{
if (series[i].index != seriesIndex)
{
series[i].visible ?
series[i].hide() :
series[i].show();
}
}
return false;
}
Source: stackoverflow.com
Related Query
- Highcharts Series - want to show/hide all EXCEPT selected series (reversal of default logic)
- Highcharts data from google spreadsheet hide all series except one at start
- Hide all other series except selected series. Also display the list of items in dropdown
- How can i hide all the Series in highcharts at a time
- Hide all but selected data series, HighCharts
- How do I hide a Highcharts series from the chart, but always show it in the tooltip?
- I want to capture the starting and end point of all the series in my multigraph and show it in a table using MeasureX of StockTools in Highstock
- HighCharts Hide Series Name from the Legend
- Proper way to remove all series data from a highcharts chart?
- How can I hide series from a HighCharts legend?
- Highchart - show / hide an y-Axis without hiding the series
- How can I hide a series from initially being displayed in Highcharts
- Highcharts - How to hide series name and Y value in tooltip
- Show specific series values in the stack label using highcharts
- Never want to hide tooltip on highcharts
- How can I delete all of the points from a highcharts series
- How to hide one series data info in tooltip using highcharts
- highcharts / highstock column doesn't show all datalabels
- How can I hide ALL series with the same ID with a button on highcharts? (line graph)
- Highcharts hide series without change legend color
- Show / Hide plotband in Highcharts - Javascript
- Highcharts: show series on legend but hide on chart
- Show all labels in highcharts horizontal bar graph
- How can I hide and show a category in highcharts
- How to show 0 for incomplete Series in Highcharts
- Highcharts - Hide series "points" (labels) on both x- and y-axis
- Highcharts Solid Gauge only want to show 1 data label
- Highcharts animate series on show
- Highcharts show the same yAxis start and end value with multiple data series
- How show all tooltips split in graph with many series
More Query from same tag
- How to get next point in Highcharts tooltip
- Highcharts : cross symbol with fillColor
- Highcharts and jQuery Mobile Pages
- Highcharts bar: height by xAxis
- stacked bar chart shows hanging zeros when all values are 0 highcharts
- highstock charts - button for date range
- Load mysql data to Highcharts line chart using JSON
- Highcharts Polar Plot area scaling issues
- Highcharts dataLabel positioning issue in FF and IE
- Filter data in Highcharts
- How to update HighChart series inside setInterval method
- problems charts jquery highcharts
- Flags Stack Distance Not Working
- Min/Max yAxis not working correctly in Highcharts
- Highchart by aggegated data
- Updating a Highchart from a form with a click() event in jquery
- How to get current width of highcharts column
- HighCharts Pie Chart - Add text inside each slice
- Highcharts not working on Heroku environment, works on local environment
- Dynamically set click event on bar from highcharts graph
- how to display charts/graphs based on user specific data
- How do I turn string insert data into a series for react highcharts?
- How can I make preset json data ready to be used in my highchart?
- How to select multiple points or markers programmatically in Highcharts?
- highcharts - create a total sumline of an existing serie
- Highcharts - Resizing Columns to Fix Data Label
- Fire a bootstrap modal when i click on a stacked bar of highcharts
- Highchart How to set pie chart sliced distance gap wider to one another
- How to use specific version of external library in jsfiddle?
- Highcharts don't render in Internet Explorer 11