如何更新 ApexChart?
2021-02-28
1829
我在项目中使用 ng-apexcharts,但遇到了问题。我尝试更新图表,按照文档使用
updateSeries()
方法,但出现此错误:
TypeError: undefined is not an object (evaluating 'this.chart.updateSeries')
执行更新的方法是:
changeData(numberOfDays: number) {
const zoomData = this.chartData;
zoomData.sort( (a, b) => {
return b.date - a.date;
} );
zoomData.splice(numberOfDays, zoomData.length);
this.chart.updateSeries([{
data: zoomData.map(el => el.close)
}]);
}
zoomData 上的数据是:
[
{
"date":1614297600000,
"close":121.260002
},
{
"date":1614211200000,
"close":120.989998
},
{
"date":1614124800000,
"close":125.349998
}
]
我做错了什么?
谢谢
2个回答
我已经解决了这个问题。使用
ng-apexcharts
时,更新应如下所示:
public updateSeries() {
this.chartOptions.series = [{
data: [23, 44, 1, 22]
}];
}
chartOptions
是图表的初始属性集。
MrRobot
2021-03-02
/*I had the same problem in Vue 3, to update the options:*/
onUpdated(()=>{
ApexCharts.exec(idChart, 'updateOptions', {
xaxis: {
categories: NewCategories
}
});
})
Ileana BROTSKY
2024-05-27