How to use highcharts with angular 5?

前端 未结 10 1416
囚心锁ツ
囚心锁ツ 2020-12-14 18:39

Is there any way to use highcharts.js with angular2 ?Is there any option available instead of highcharts?

10条回答
  •  感动是毒
    2020-12-14 19:11

    With usage of official highcharts module only (w/o angular2-highcharts and other and even @types/highcharts)

    npm install --save-dev highcharts

    import * as HC from 'highcharts';
    ...
    export class MainComponent implements OnInit, AfterViewInit {
    ...
    ngAfterViewInit() {
      let chartOptions = {
      ...
        chart: {
          renderTo: 'chartPanel', // need to have div #chartPanel in template
          ...
        }
      }
      this.chartInstance = new HC.Chart(chartOptions);
    }
    

    this.chartInstance will have all highcharts methods like addSeries, reflow, redraw etc.

提交回复
热议问题