Rohit Mehrotra
Rohit Mehrotra

Reputation: 29

Pie Chart Center Text gets overlap with tooltip

I am using a Pie chart of HighChart lib. On hover over of pie, the center text is getting overlapped with the tooltip. Is there any solution to fix this?

enter image description here

link to stackblitz https://stackblitz.com/edit/pie-chart-using-highcharts-er7kym?file=app%2Fhighcharts.service.ts

Upvotes: 0

Views: 789

Answers (2)

Rohit Mehrotra
Rohit Mehrotra

Reputation: 29

Got after doing some research got the answer. just need to make useHTML as false. this.series.chart.setTitle({ text: span, useHTML: false });

link to fiddle https://stackblitz.com/edit/highcharts-angular-basic-line-buzwdr?file=src%2Fapp%2Fapp.component.ts

Upvotes: 1

Sebastian Hajdus
Sebastian Hajdus

Reputation: 1560

Something in the settings was wrong, I created a similar chart from the demo and here the text no longer overlaps the tooltip.

Highcharts.chart('container', {
  chart: {
    plotBackgroundColor: null,
    plotBorderWidth: 0,
    plotShadow: false
  },
  title: {
    text: 'Browser<br>shares<br>2017',
    align: 'center',
    verticalAlign: 'middle',
    y: 60
  },
  tooltip: {
    pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
  },
  plotOptions: {
    pie: {
      allowPointSelect: true,
      showInLegend: true,
      cursor: 'pointer',
      innerSize: '50%',
      dataLabels: {
        enabled: false,
        format: '<b><a (click)="helloFunc(point.name)">{point.name}</a></b>: {point.percentage:.1f} %bbb',
        style: {
          color: (Highcharts.theme && Highcharts.theme.contrastTextColor) ||
            'black',
        },
      },
      states: {
        hover: {
          brightness: 0,
          halo: {
            opacity: 1,
          },
        },
        select: {
          brightness: 0,
          halo: {
            opacity: 1,
          },
        },
      },
      point: {
        events: {
          mouseOver: function() {
            let chart = this.series.chart;
            chart.title.attr({
              text: `<span style="color:#e43761;" class="dealer-title" data-oa-qa="donut-total-count-text">Total<br/><b>${this.y}</b></span>`,
            });
          },
          click: function() {
            let chart = this.series.chart;
            chart.title.attr({
              text: `<span style="color:#e43761;" class="dealer-title" data-oa-qa="donut-total-count-text">Total<br/><b>${this.y}</b></span>`,
            });
          },
          legendItemClick: function() {
            let chart = this.series.chart;
            chart.title.attr({
              text: `<span style="color:#e43761;" class="dealer-title" data-oa-qa="donut-total-count-text">Total<br/><b>${this.y}</b></span>`,
            });
            return false;
          },
        },
      },
    },
  },
  series: [{
    type: 'pie',
    name: 'Browser share',
    innerSize: '50%',
    data: [
      ['Chrome', 58.9],
      ['Firefox', 13.29],
      ['Internet Explorer', 13],
      ['Edge', 3.78],
      ['Safari', 3.42],
      {
        name: 'Other',
        y: 7.61,
        dataLabels: {
          enabled: false
        }
      }
    ]
  }]
});

Example recreated in Angular: Demo

Upvotes: 1

Related Questions