0

There are plenty examples of hiding an Y-Axis without hiding the series - But i need the opposite of that.

I want to make a series invisible while still displaying the y-axis and i dont know how!

Why?

Because i have 2 diagrams which are perfectly aligned by their x-Axis: enter image description here

But when i disable both Temperature fields, the axis will be lost, and the diagrams are incorrect in size: enter image description here

I also don't like the idea, of disabling all and loosing whole diagram style: enter image description here

There is no problem by having an empty diagram, but having a blank box isn't the style i want to reach.

I tried to manipulate the axis in within the legendItemClick event, but selecting the correct axis and set their value visible didn't work out. How can I solve this problem?

Community
  • 1
  • 1
Neysor
  • 3,893
  • 11
  • 34
  • 66

1 Answers1

1

I think you have two options:

  • play around with margins - to make them fixed
  • set min and max for axis, so labels will remain on a chart: example

if you don't know min/max values at start you can change them within the legendItemClick as following:

 plotOptions: {
        series: {
            events: {
                legendItemClick: function() {
                    var temperatur = this.chart.series[0];
                    var taupunkt = this.chart.series[1];
                    var other = this.name=="Lufttemperatur"?taupunkt:temperatur;
                    var element = this;
                    if(this.name == "Lufttemperatur" || this.name == "Taupunkt") {
                        if(this.visible && !other.visible) {
                            //both will be invisible soon
                            this.chart.yAxis[0].update({
                                min:element.yAxis.min,
                                max:element.yAxis.max
                            });
                        } else {
                            //one will be visible
                            this.chart.yAxis[0].update({
                                min:null,
                                max:null
                            });
                        }
                    }
                }
            }
        },
 }

This will only set min/max if there is no one of your series visible, but deletes it if you have one visible

Neysor
  • 3,893
  • 11
  • 34
  • 66
Paweł Fus
  • 44,795
  • 3
  • 61
  • 77