My goal is to populate an array with dynamic data.
export class Test implements OnInit {
private lineChart: Array<any>;
}
As I work on the code, I am dynamically generating some data and pushing it into the empty lineChart array. While this process works, the data is not formatted as required. Any suggestions on how to achieve the desired result below?
The expected output should look like this:
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' },
]
I am utilizing the JavaScript library mentioned here: 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);
}
}
In the end, I aim to obtain the array stored in 'chartData' by dynamically generated data.