0
votes

Is there any way to make a Highcharts pie chart with a height that automatically fits the chart and the legend? I have a variable number of legend elements and cannot rely on a fixed pixel height or one relative to the width.

The legend is far away from the pie chart. I would like the pie chart to be at the top of the container with the legend right below, with the height set to whatever the combined height is (rather than setting a static height).

1
Hi @tau, Could you describe your problem more precisely? Also, some live example would be very useful (jsfiddle.net/BlackLabel/raebx3zc).ppotaczek
i updated my description a bit and here is an example: jsfiddle.net/kyn8gqa9 thanks!tau

1 Answers

1
votes

You can calculate the required chart height and use setSize method to set it:

events: {
  load: function() {
    this.setSize(
      null,
      this.seriesGroup.getBBox().height +
        this.marginBottom + this.plotTop + 20
    );
  }
}

Live demo: http://jsfiddle.net/BlackLabel/5jL1acdk/

API: https://api.highcharts.com/class-reference/Highcharts.Chart#setSize