m.cs
Posts: 5
Joined: Tue Oct 03, 2023 2:43 pm

X Axis Multiple Years

Tue Oct 03, 2023 3:02 pm

Hi,

I have a gantt chart where the X Axis is dynamic and works almost always fine. The problem is when I have data from multiple years, both rows of the X Axis show the year which is strange.
How can I hide the top X Axis when the bottom X Axis is Years? Or if the bottom is Years, I show the top row but without any label?
Any solution would be fine.

Here is the Js Fiddle: https://jsfiddle.net/pbm87fc3/1/

Thank you.

jakub.j
Posts: 857
Joined: Tue Jan 24, 2023 11:14 am

Re: X Axis Multiple Years

Tue Oct 03, 2023 6:12 pm

Welcome to our forum and thanks for contacting us with your question!

These are the 2 possibilities:

#1 Set xAxis.visible to false for the 2nd xAxis - to hide the whole xAxis
Demo: https://jsfiddle.net/BlackLabel/t5sajkeb/

#2 Set xAxis.labels.format to an empty string - the row is shown without any labels
Demo: https://jsfiddle.net/BlackLabel/hb1xs24o/

Feel free to ask any further questions!
Kind regards
Jakub
Jakub
Highcharts Developer

m.cs
Posts: 5
Joined: Tue Oct 03, 2023 2:43 pm

Re: X Axis Multiple Years

Wed Oct 04, 2023 8:13 am

Hi Jakub,

Thank you for your answer but I didn't want to hide the top axis always. I just wanted to hide it when the bottom axis is years. Is this possible?

jakub.j
Posts: 857
Joined: Tue Jan 24, 2023 11:14 am

Re: X Axis Multiple Years

Wed Oct 04, 2023 9:54 am

Hey!

Sorry, I misunderstood your question. I wrote custom logic in chart.events.render such that it toggles the visibility of the higher xAxis based on the labels' content of the lower one.

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

Let me know if that was what you were looking for!
Best regards
Jakub
Jakub
Highcharts Developer

m.cs
Posts: 5
Joined: Tue Oct 03, 2023 2:43 pm

Re: X Axis Multiple Years

Fri Oct 06, 2023 2:27 pm

Yes, that's it!
Thank you!

Return to “Highcharts Gantt”