将json数据推送到数组后,Angular Kendo线图无法绘制。

问题描述 投票:0回答:1

我有一个来自后台的JSON格式的数据,它在我的控制台上看起来是这样的,我可以绘制它。

(10) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}]
0: {windSpeed: 7.85, timeStamp: "2020-06-07-11:59"}
1: {windSpeed: 10.23, timeStamp: "2020-06-07-12:09"}
2: {windSpeed: 9.34, timeStamp: "2020-06-07-12:19"}
3: {windSpeed: 11.24, timeStamp: "2020-06-07-12:29"}
4: {windSpeed: 9.32, timeStamp: "2020-06-07-12:39"}
5: {windSpeed: 10.12, timeStamp: "2020-06-07-12:49"}
6: {windSpeed: 8.63, timeStamp: "2020-06-07-12:59"}
7: {windSpeed: 10.97, timeStamp: "2020-06-07-13:09"}
8: {windSpeed: 11.41, timeStamp: "2020-06-07-13:19"}
9: {windSpeed: 9.69, timeStamp: "2020-06-07-13:29"}

当我把这些数据推送到一个数组中时,我无法绘制图表,这是我的数组。

public series:any[]=[];

当我推送json的时候:

  this.series.push(this.JsonData);

我在控制台得到的数据格式是这样的。

[Array(10)]
0: Array(10)
0: {windSpeed: 7.85, timeStamp: "2020-06-07-11:59"}
1: {windSpeed: 10.23, timeStamp: "2020-06-07-12:09"}
2: {windSpeed: 9.34, timeStamp: "2020-06-07-12:19"}
3: {windSpeed: 11.24, timeStamp: "2020-06-07-12:29"}
4: {windSpeed: 9.32, timeStamp: "2020-06-07-12:39"}
5: {windSpeed: 10.12, timeStamp: "2020-06-07-12:49"}
6: {windSpeed: 8.63, timeStamp: "2020-06-07-12:59"}
7: {windSpeed: 10.97, timeStamp: "2020-06-07-13:09"}
 8: {windSpeed: 11.41, timeStamp: "2020-06-07-13:19"}
9: {windSpeed: 9.69, timeStamp: "2020-06-07-13:29"}

这种格式不绘制图表,任何帮助将非常感激。

javascript angular kendo-ui
1个回答
0
投票

这是因为你正在将一个数组A(你的 "JsonData")推送到数组B(你的 "series")中,你要做的是将数组A中的ITEMS推送到数组B中。

这可以通过以下方法来实现,例如,使用 点差操作员:

this.series.push(...this.JsonData);
© www.soinside.com 2019 - 2024. All rights reserved.