在我的角度解决方案中,我需要使用Highcharts显示一些图表。在我的component.ts
中,我有以下代码:
import * as Highcharts from "highcharts";
highcharts = Highcharts;
chartOptions = {
chart: {
type: "spline",
title: "Reach/TRP"
},
xAxis: {
title: {
text: this.xAxis.name
}
},
yAxis: {
title: {
text: "Reach"
}
},
series: [
{
name: this.xAxis.name,
data: this.xAxis.data
}
]
};
然后在我的.html
中,我像这样使用它:
<highcharts-chart
[Highcharts] = "highcharts"
[options] = "chartOptions"
style="width: 100%; height: 400px; display: block;">
</highcharts-chart>
在我的html
上,我还有以下下拉菜单:
<p-dropdown [showTransitionOptions]="'0ms'" [hideTransitionOptions]="'0ms'"
dropdownIcon="fa fa-angle-down" class= "nextgen-dropdown"
[options]="optionsLookup"
[(ngModel)]="selectedOption" (onChange)= "onOptionChange($event)">
</p-dropdown>
具有"OnOptionChange"
方法的应该像这样更新Chart
的方法:
onOptionChange() {
this.xAxis.name = this.selectedOption;
this.xAxis.data = [100, 100, 200, 200, 350, 250];
this.chartOptions.series[0] = this.xAxis;
}
这里的问题是方法被正确调用,但是图表根本没有更新。
我在这里想念的是什么?
您应该传递新的选项参考:
onOptionChange() {
this.xAxis.name = this.selectedOption;
this.xAxis.data = [100, 100, 200, 200, 350, 250];
this.chartOptions.series[0] = this.xAxis;
this.chartOptions = { ...this.chartOptions }; // this should do the trick
}