Angular Highchart-使用JSON填充数组

问题描述 投票:0回答:1

我正在尝试用JSON数据填充数组

this.http
          .get(
            "https://cdn.jsdelivr.net/gh/highcharts/[email protected]/samples/data/usdeur.json"
          )
          .subscribe(response => {
            console.log(response)
            this.seriesOptions = [
              {
                name: "Test",
                data: response,
                id: "dataseries"
              }
            ];

          console.log(this.seriesOptions); <---- NULL

          });

然后我想在高图中显示此JSON

 this.chartOptions = {
      chart: {
        type: "line",
        zoomType: "xy",
        panning: true,
        panKey: "shift"
      },
      series: this.seriesOptions
    };

在HTML中,我有

   <highcharts-chart id="container" [Highcharts]="Highcharts" [constructorType]="chartConstructor"
        [options]="chartOptions" [callbackFunction]="chartCallback" [(update)]="updateFromInput" [oneToOne]="true">
      </highcharts-chart>

问题:我无法填充此数组'this.seriesOptions'返回null。从JSON获取数据的正确方法是什么?

angular highcharts
1个回答
0
投票

我已经为您设置了此示例:https://stackblitz.com/edit/angular-f3ny5h

希望有帮助!

© www.soinside.com 2019 - 2024. All rights reserved.