Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

highcharts link series such that turn one off turns off the other

I would like to link a pair of series in highcharts so that clicking either one in the legend turns both in the pair on/off.

For example, in this fiddle, if I click 1A in the legend I would like it to also turn off 2A but leave 1B and 2B unaffected. Clicking 2A should also turn off 1A, i.e. the link should work both ways.

Is there a way to achieve this?

like image 360
harryg Avatar asked Jul 09 '13 09:07

harryg


2 Answers

You can also use linkedTo options from Highcharts, see: http://jsfiddle.net/GCqsf/4/

There is only one limit - linked series isn't displayed in legend, so probably it may not fit the best your example. Since Highcharts 3.0.7 you can set series.showInLegend = true to display linked series in legend.

like image 132
Paweł Fus Avatar answered Oct 09 '22 17:10

Paweł Fus


You'll have to handle the legendItemClick event and specifically hide (and show) the "sister" series.

I have a running example in this jsFiddle.

Note that I'm using the links variable as an easy way to get the "sister" series for a given series.

Also note that I've added an id to each series so that chart.get() returns the series when given its id.

like image 36
ssarabando Avatar answered Oct 09 '22 17:10

ssarabando