К сожалению, я понятия не имею, почему Angular выбрасывает эту ошибку. Не могли бы вы прикрепить содержимое this.chart.legend
объекта?
Однако я предлагаю вам использовать официальную оболочку Highcharts для Angular (которую можно скачать здесь: https://github.com/highcharts/highcharts-angular), поскольку обновление диаграммы за рамками Angular * не рекомендуется . Затем вы можете просто изменить параметры диаграммы с измененным именем легенды и изменить флаг updateFromInput
, чтобы обновить весь компонент диаграммы. Проверьте код и демонстрационную версию, размещенную ниже.
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)="update_chart()">Change legend name</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: [
{
name: "Series name",
data: [1, 2, 3, 6, 9]
}
],
exporting: {
enabled: true
},
yAxis: {
allowDecimals: false,
title: {
text: "Data"
}
}
};
constructor() {
const self = this;
this.chartCallback = chart => {
self.chart = chart;
};
}
ngOnInit() {}
update_chart() {
const self = this,
chart = this.chart;
self.chartOptions.legend = {
labelFormatter: function() {
return `${this.name} - edited`;
}
};
self.updateFromInput = true;
}
}
Демо:
https://codesandbox.io/s/7y5j93l2rq
Highcharts Угловая обертка:
https://github.com/highcharts/highcharts-angular