首页 > 解决方案 > Highcharts Angular-“SeriesAbandsOptions”类型上不存在属性“数据”

问题描述

我正在尝试使用 REST API 设置图表的数据,但出现以下错误:“SeriesAbandsOptions”类型上不存在属性“数据”

ngOnInit(): void {
    this.chartService.getMostFrequentUpdateData().subscribe(
      (data: ChartData[]) => {
        if(this.chartOptions.series){
          this.chartOptions.series[0].data = data;
        }
      }
    );
  }

我得到错误.data。为清楚起见,这是我的图表:

chartOptions: Options = {

  title: {
      text: 'CDF of the most frequent update frequency',
      style: {
        color: 'whitesmoke'
      }
    },
    chart: {
      type: 'line',
      zoomType: 'x',
      backgroundColor: '#323232',
    },
...

  series: [
      {
        name: 'Frequency of the most frequent update in the sequence (upd/min)',
        type: 'line',
        data: [],
        color: '#009879',
        }
    ],
}

标签: angulartypescripthighchartsdata-binding

解决方案


似乎缺少一些 TS 定义。你有两个选择:

  1. 把一切都扔到any-相当残酷。
  2. SeriesAbandsOptions创建附加接口以扩展缺少data类型的现有接口。

简单演示:https ://stackblitz.com/edit/highcharts-angular-property-xxx-doesnt-exist-on-type-yyy


推荐阅读