gpt4 book ai didi

angular - highcharts-angular 从数据库动态更新

转载 作者:行者123 更新时间:2023-12-05 06:29:39 26 4
gpt4 key购买 nike

我在 Angular 6 应用程序中使用 highcharts-angular。当我设置数据时,在 ngOnInit 中硬核它,图表可见并且工作正常。

但我想动态更新图表系列,意思是向系列添加点,添加新系列......这将在调用 Web API 并获取新数据、调用 loadBidChartData() 后完成。

如果我为聊天设置新系列,或更新系列,图表看不到变化,初始状态没有变化。 我该如何解决这个问题?

这是示例代码的小和平在 html 中是这样的:

<highcharts-chart [Highcharts]="Highcharts" [options]="chartOptions" style="width: 100%; height: 400px; display: block; overflow: auto;" [update]="true" ></highcharts-chart> 

Angular :

 import * as Highcharts from 'highcharts';
export class ExampleComponent implements OnInit {
Highcharts = Highcharts; // required
chartOptions = {
chart: {
type: "scatter",
width: 900
},
},
tooltip: {
valueDecimals: 0,
formatter: function () {
return this.y + ' €';
}
},
title: {
text: ''
},
xAxis: {
type: 'datetime',
},
yAxis: {
type: 'number',
},
legend: {
layout: 'vertical',
align: 'right',
verticalAlign: 'top',
floating: false,
borderWidth: 1
},
series: []
};

ngOnInit(): void {
this.chartOptions.series= [{
name: 'first last',
data: [[Date.UTC(2018, 11, 16, 10, 56, 25), 23], [Date.UTC(2018, 11, 16, 10, 57, 15), 132], [Date.UTC(2018, 11, 16, 10, 58, 2), 312], [Date.UTC(2018, 11, 16, 10, 58, 15), 432]]
}];
}

loadBidChartData(bidApiModel: BidItem[]): void {
this.chartOptions.series= [{
name: 'first last',
data: [[Date.UTC(2018, 11, 16, 10, 56, 25), 23], [Date.UTC(2018, 11, 16, 10, 57, 15), 132], [Date.UTC(2018, 11, 16, 10, 58, 2), 312], [Date.UTC(2018, 11, 16, 10, 58, 15), 432]]
},
{
name: 'second last',
data: [[Date.UTC(2018, 11, 16, 10, 56, 28), 50], [Date.UTC(2018, 11, 16, 10, 56, 45), 152], [Date.UTC(2018, 11, 16, 10, 56, 53), 250], [Date.UTC(2018, 11, 16, 10, 57, 11), 320]]
}];
}
}

解决方案:在后台更新并向 Highcharts 添加和删除点的工作演示:https://stackblitz.com/edit/angular-bv26xz
感谢 User3250Wojciech Chmiel 的帮助。

最佳答案

您需要使用 [(update)] 标志来更新系列如下:

loadBidChartData(bidApiModel: BidItem[]): void {
this.chartOptions.series= [{
name: 'first last',
data: [[Date.UTC(2018, 11, 16, 10, 56, 25), 23], [Date.UTC(2018, 11, 16, 10, 57, 15), 132], [Date.UTC(2018, 11, 16, 10, 58, 2), 312], [Date.UTC(2018, 11, 16, 10, 58, 15), 432]]
},
{
name: 'second last',
data: [[Date.UTC(2018, 11, 16, 10, 56, 28), 50], [Date.UTC(2018, 11, 16, 10, 56, 45), 152], [Date.UTC(2018, 11, 16, 10, 56, 53), 250], [Date.UTC(2018, 11, 16, 10, 57, 11), 320]]
}];
this.updateFlag = true;
}

<highcharts-chart [Highcharts]="Highcharts" [options]="chartOptions" style="width: 100%; height: 400px; display: block; overflow: auto;" [(update)]="updateFlag" ></highcharts-chart>

此处的工作演示:https://stackblitz.com/edit/angular-d5spve

关于angular - highcharts-angular 从数据库动态更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53374858/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com