我正在尝试将一些动态数据推入数组。
export class Test implements OnInit {
private lineChart: Array<any>;
}
在代码中,我动态生成一些数据并将lineChart.push(data)放入空的lineChart数组中,它正在工作,但数据格式不正确,无法使用。关于如何得出以下结果的任何想法?
这是预期的结果:
private lineChart: Array<any> = [
{ data: [65, 59, 80, 81, 56, 55, 40], label: 'toto' },
{ data: [28, 48, 40, 19, 86, 27, 90], label: 'tata' },
{ data: [81, 56, 55, 48, 40, 19, 34], label: 'titi' },
]
我正在尝试使用此Javascript盗窃:https://alligator.io/angular/chartjs-ng2-charts/
import { Component } from '@angular/core';
@Component({ ... })
export class AppComponent {
chartOptions = {
responsive: true
};
chartData = [
{ data: [330, 600, 260, 700], label: 'Account A' },
{ data: [120, 455, 100, 340], label: 'Account B' },
{ data: [45, 67, 800, 500], label: 'Account C' }
];
chartLabels = ['January', 'February', 'Mars', 'April'];
onChartClick(event) {
console.log(event);
}
}
chartData是我想使用动态生成的数据最后获得的数组。
答案 0 :(得分:0)
应该是
private lineChart: Array<{
data: number[],
label: string,
}> = [
{ data: [65, 59, 80, 81, 56, 55, 40], label: 'toto' },
{ data: [28, 48, 40, 19, 86, 27, 90], label: 'tata' },
{ data: [81, 56, 55, 48, 40, 19, 34], label: 'titi' },
];