使用Highcharts-angular动态更改数据系列类型

时间:2019-06-28 15:01:24

标签: angular highcharts

我有一个带有highcharts的角度项目,使用的是官方的highcharts-angular包装器。我想将数据显示为项目图或实体表。用户应该能够在两者之间切换。当我更改图表的“选项”时,我得到

ERROR TypeError: Cannot read property '0' of undefined
    at q.getExtremes (highcharts.src.js:30138)
    at q.getExtremes (bullet.src.js:279)

我也尝试按照建议的here使用Series.update方法,但是得到相同的错误。您可以在此stackblitz中重现它。该代码基本上是这样做的:

    // initial options
    this.chartOptions =
    {
      series: [{
        "type": "solidgauge",
        "data": [{ "y": 380.2 }]
      }]
    };

    // after some delay, or when user clicks a button

    this.chartOptions =
    {
      series: [ {
        "type": "bullet",
        "data": [{ "y": 80.2 }]
      } ]
    };

1 个答案:

答案 0 :(得分:0)

Highcharts中存在一个与更新solidgauge系列类型:https://github.com/highcharts/highcharts/issues/7746

相关的错误

作为解决方法,您可以更新chart.type

setBullet() {
  const component = this;
  this.chartOptions =
    {
      chart: {
        type: 'bullet',
        ...
      },
      series: [...]
    };
}

setSolidGauge() {
  const component = this;
  this.chartOptions =
    {
      chart: {
        "type": "solidgauge",
        ...
      },
      series: [...]
    };
}

实时示例: https://stackblitz.com/edit/angular-iktja5?file=src/app/chart.component.ts

无角演示:http://jsfiddle.net/BlackLabel/30hn4ywb/