在创建的饼图上更改mouseTracking

时间:2019-05-08 09:52:02

标签: angular highcharts

在创建的饼图上,我需要在角度组件中调用函数后更改mouseTracking。

不幸的是,在 Highcharts-> setOptions-> plotOptions-> series series-> setOptions 上,将enableMouseTracking设置为false不会对图表产生任何影响。

      Highcharts.setOptions({
        plotOptions: {
          series: {enableMouseTracking: false}
        }
      });
      this.chartRef.series[0].setOptions({
        enableMouseTracking: false
      });

甚至额外执行setData(只是重绘图表也无济于事)

enableMouseTracking在创建饼形图之前最初在chartOptions中进行设置时可以正常工作。

是否可以在创建的图表上更改mouseTracking?如果可以,怎么做?

请告知。预先感谢。


以下更多代码:

Package.json

    "@angular/core": "7.2.12",
    "highcharts": "7.1.1",
    "highcharts-angular": "2.4.0",

HTML

<highcharts-chart
  [Highcharts]="Highcharts"
  [options]="chartOptions"
  [update]="false"
  [runOutsideAngular]="true"
  style="width: 300px; height: 280px; display: block;"
></highcharts-chart>

打字稿

export class MyChartComponent implements OnInit, AfterViewInit, OnDestroy {

  public Highcharts = Highcharts; // required
  private chartRef;

  public chartOptions = {
    chart: {
      plotBackgroundColor: null,
      plotBorderWidth: null,
      plotShadow: false,
      type: 'pie',
      events: this.getHighchartsEvents()
    },
    series: [{
      name: 'Data',
      enableMouseTracking: true,
      size: '100%',
      innerSize: '50%',
      data: [this.highchartsData]
    }],
    // [...]
  }

  private getHighchartsEvents() {
    const self = this;
    return {
      load: function(event) {
        self.chartRef = this;
      }
    }
  }

  public disableMouseTracking() {
    if(this.chartRef) {
      Highcharts.setOptions({
        plotOptions: {
          series: {enableMouseTracking: false}
        }
      });
      const turnOffMouseTracking = {
        enableMouseTracking: false
      };
      this.chartRef.series[0].setOptions(turnOffMouseTracking);
      // this.chartRef.series[0].setData(this.highchartsData); // additional execution of setData (just to redraw the chart does not help either) 
    }
  }

0 个答案:

没有答案