Katona
Katona

Reputation: 4901

Center title of chart relative to the plot background

I would like to center the title of a pie chart relative to the plot background (not the element containing the chart), so that if there is a legend next to the char the title is still centered relative to the pie.

Using

    title: {
        text: 'Title',
        align: 'center'
    }

centers the title relative to the containing element. See this fiddle for the full example.

Is it possible somehow?

Upvotes: 1

Views: 56

Answers (1)

ppotaczek
ppotaczek

Reputation: 39099

You can position the title in the render event, for example:

chart: {
  ...,
  events: {
    render: function() {
      var seriesGroupBBox = this.seriesGroup.getBBox();

      this.title.attr({
        x: seriesGroupBBox.x + seriesGroupBBox.width / 2 - this.title.getBBox().width / 2
      });
    }
  }
}

Live demo: https://jsfiddle.net/BlackLabel/6a9sroe7/

API Reference: https://api.highcharts.com/highcharts/chart.events.render

Upvotes: 1

Related Questions