dktg
Posts: 151
Joined: Mon Jan 29, 2018 2:19 pm

Drilldown for one bar in stacked barchart

Hi, we have a stacked barplot that shows just one bar for the year 2022, the x-axis however has to start in 2000. For this single bar, we like to implement a drilldown. I was able to that however the x-axis labels and the labels in the legend are still wrong. How would I fix that?

Here you find the code: https://jsfiddle.net/statistik_tg/aeo7spLj/3/

Thank you and kind regards,
jakub.j
Posts: 1091
Joined: Tue Jan 24, 2023 11:14 am

Re: Drilldown for one bar in stacked barchart

We appreciate you reaching out to us!

I found the solution for your problem. Instead of adding new series in chart.drilldown, you add them in chart.event.drilldown which causes the problem with legend items. When I changed the logic, everything works as expected.

Demo: https://jsfiddle.net/BlackLabel/xds5k2hn/

In case of any other questions related to Highcharts functionality feel free to contact us anytime
Best regards
Jakub
dktg
Posts: 151
Joined: Mon Jan 29, 2018 2:19 pm

Re: Drilldown for one bar in stacked barchart

Hi, thank you for your reply and the adjusted code. I see my mistake. However, when I jump into the drilldown, the x-axis still displays the labels 2000 and a missing label instead of cat_1 and cat_2. Is that even possible to adapt? And how would I have to adapt the tooltip-option so that within the drilldown the tooltip displays cat_1 and cat_2? Thanks for any further support and kind regards,
jakub.j
Posts: 1091
Joined: Tue Jan 24, 2023 11:14 am

Re: Drilldown for one bar in stacked barchart

You're welcome!

You can dynamically change the categories using xAxis.setCategories so I extracted your categories arrays to variables and on drilldown and drillup events I use this method to set the proper categories to xAxis.
Now, when the categories are set, the tooltip show "Cat1" and so on when drilled down.

Demo: https://jsfiddle.net/BlackLabel/knzpmyr3/

Do not hesitate to contact us in the future
Best regards
Jakub
dktg
Posts: 151
Joined: Mon Jan 29, 2018 2:19 pm

Re: Drilldown for one bar in stacked barchart

Perfect, thank you and kind regards,
jakub.j
Posts: 1091
Joined: Tue Jan 24, 2023 11:14 am

Re: Drilldown for one bar in stacked barchart

You're welcome! In case of any further questions, feel free to contact us again.

Best regards
Jakub
dktg
Posts: 151
Joined: Mon Jan 29, 2018 2:19 pm

Re: Drilldown for one bar in stacked barchart

Hi, indeed I have a further question. Is it also possible to display the subcategories (cat_1, cat_2) for each group if there are not always the same, i. e. cat_1 and cat_2 for group_1, cat_3 and cat_4 for group_2 and so on? And if yes, how would I implement that into the code above?
Thank you and kind regards,
jakub.j
Posts: 1091
Joined: Tue Jan 24, 2023 11:14 am

Re: Drilldown for one bar in stacked barchart

Hey,

Yes, I added a customCategories property to one of the drilldown series.
On chart.events.drilldown I check if it exists on the series and then I set those custom categories or if they don't exist, the default categories are set.

Demo: https://jsfiddle.net/BlackLabel/wnLfd0va/

I hope you will find it useful
Best regards
Jakub

Return to “Highcharts Usage”