Я сделал простой онлайн-пример для вас с обновлением Highcharts в приложении Angular. Я использовал highcharts-angular
официальный упаковщик Highcharts, который я рекомендую вам (его можно скачать здесь: https://github.com/highcharts/highcharts-angular). Проверьте код и демоверсию, размещенную ниже:
app.module.ts:
import { BrowserModule } from "@angular/platform-browser";
import { NgModule } from "@angular/core";
import { HighchartsChartModule } from "highcharts-angular";
import { ChartComponent } from "./chart.component";
import { AppComponent } from "./app.component";
@NgModule({
declarations: [AppComponent, ChartComponent],
imports: [BrowserModule, HighchartsChartModule],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule {}
chart.component.html:
<div class="boxChart__container">
<div>
<highcharts-chart
id="container"
[Highcharts]="Highcharts"
[constructorType]="chartConstructor"
[options]="chartOptions"
[callbackFunction]="chartCallback"
[(update)]="updateFromInput"
[oneToOne]="true"
style="width: 100%; height: 400px; display: block;"
>
</highcharts-chart>
<button (click)="onInitChart()">Init Chart</button>
</div>
</div>
chart.component.ts:
import { Component, OnInit } from "@angular/core";
import * as Highcharts from "highcharts";
import * as HighchartsMore from "highcharts/highcharts-more";
import * as HighchartsExporting from "highcharts/modules/exporting";
HighchartsMore(Highcharts);
HighchartsExporting(Highcharts);
@Component({
selector: "app-chart",
templateUrl: "./chart.component.html"
})
export class ChartComponent implements OnInit {
title = "app";
chart;
updateFromInput = false;
Highcharts = Highcharts;
chartConstructor = "chart";
chartCallback;
chartOptions = {
series: [],
exporting: {
enabled: true
},
yAxis: {
allowDecimals: false,
title: {
text: "Data"
}
}
};
constructor() {
const self = this;
// saving chart reference using chart callback
this.chartCallback = chart => {
self.chart = chart;
};
}
ngOnInit() {}
onInitChart() {
const self = this,
chart = this.chart;
chart.showLoading();
setTimeout(() => {
chart.hideLoading();
self.chartOptions.series = [
{
data: [2134000, 3168818, 2569759],
name: 2015,
type: "column"
},
{
data: [2497680, 3195299, 2480444],
name: 2014,
type: "column"
},
{
data: [2872000, 3604271, 2925828],
name: 2016,
type: "column"
}
];
self.updateFromInput = true;
}, 2000);
}
}
Демо:
https://codesandbox.io/s/kw94l52z55