maricavor
Posts: 3
Joined: Fri Sep 09, 2022 7:06 pm

column comparison with legends

How to enable and show legends to hide or show individual countries for this chart: https://www.highcharts.com/demo/column-comparison?
michal.f
Posts: 1114
Joined: Thu Aug 12, 2021 12:04 pm

Re: column comparison with legends

Hello, welcome to our forum and thanks for contacting us with your question!

The default behaviour of the legend is to list all series. In this demo showcase, the series is years so if you want the legend to list a given country you have to "reverse" the data structure.

Let me know if you have any further questions!
Best regards!
Michał Filipiec
Highcharts Developer
https://blacklabel.pl/highcharts/
maricavor
Posts: 3
Joined: Fri Sep 09, 2022 7:06 pm

Re: column comparison with legends

Thanks for your reply! Is it possible to do it without modifying data. i.e implement custom legends and click function? Could you give an example of reversed data for this chart and still to keep comparison bars ( columns )?
michal.f
Posts: 1114
Joined: Thu Aug 12, 2021 12:04 pm

Re: column comparison with legends

Hi,

Adding all the countries as a dummy series and adding the logic responsible for updating the data to them solves the problem.
Demo: https://jsfiddle.net/BlackLabel/05dck8np/

Feel free to ask any further questions!
Best regards!
Michał Filipiec
Highcharts Developer
https://blacklabel.pl/highcharts/
maricavor
Posts: 3
Joined: Fri Sep 09, 2022 7:06 pm

Re: column comparison with legends

Thanks! But could you advise about strange behaviour, when only 1 country left on the chart and others are hidden, sometimes by showing the second one, it appearing without comparison bar and sometimes when 2 countries left, by deselecting one the bar space does not disappear. Does it have to do with chart.update function?
Attachments
Screenshot 2022-09-17 at 09.09.10.png
Screenshot 2022-09-17 at 09.09.10.png (56.3 KiB) Viewed 235 times
Screenshot 2022-09-17 at 09.08.40.png
Screenshot 2022-09-17 at 09.08.40.png (63 KiB) Viewed 235 times
michal.f
Posts: 1114
Joined: Thu Aug 12, 2021 12:04 pm

Re: column comparison with legends

Hello,

I can see this behavior and there are a few other problems with colors or switching years.

Unfortunately, adding such functionality to this demo seems to be something custom and more time-consuming, so it goes beyond the scope of support on our forum. If you need help with your implementation, you can try to look for it on the more general forums like StackOverflow or contact the Black Label company that specializes in Highcharts custom projects. See official Black Label site: https://blacklabel.pl

Best regards!
Michał Filipiec
Highcharts Developer
https://blacklabel.pl/highcharts/

Return to “Highcharts Usage”