Angular框架专题

Angular中动态的更新highcharts数据

2021-11-01  本文已影响0人  听书先生
1、安装以及配置highcharts
npm install highcharts-angular --save 

npm install highcharts --save
import * as Highcharts from 'highcharts';

export class AppComponent { 
  Highcharts: typeof Highcharts = Highcharts; 
  chartOptions: Highcharts.Options = { 
    series: [{ data: [1, 2, 3], type: 'line' }]
  }
};
<highcharts-chart 
  [Highcharts]="Highcharts" 
  [options]="chartOptions" 
  style="width: 100%; height: 400px; display: block;" 
>
</highcharts-chart>
2、highcharts中新增、修改数据
<highcharts-chart 
  [Highcharts]="Highcharts" 
  [options]="chartOptions1" 
  #myChart
  style="width: 100%; height: 400px; display: block;" 
></highcharts-chart>
  @ViewChild("myChart") myChart: any;
this.myChart.chart.addSeries( 
  { 
    name: '夏季', 
    data: [4, 7, 10, 12, 14, 17, 13, 14, 21, 19, 9, 5], 
    color: 'red' 
  } 
);
this.myChart.chart.series[1].update(
  { 
    data: [12, 7, 30, 42, 14, 17, 13, 24, 21, 19, 9, 5] 
  }
);

更新多条数据时:

this.myChart.chart.update(
  { 
    series: [ 
    { 
      name: "春季", 
      data: [43, 10, 12, 14, 17], 
    },
    { 
      name: "夏季", 
      data: [29, 10, 18, 12, 14, 17], 
     }, 
   ], 
});
上一篇下一篇

猜你喜欢

热点阅读