In my Angular application, I am using ng2-charts, and trying to create a bar chart. The following stackblitz is working perfectly, I am following it: https://stackblitz.com/edit/ng2-charts-bar-template However, in my application, I am fetching data from a service, and populating dataset for chart. That works, however with two problems.
It shows only one color, gray.
For every bar, it is taking first date value for label i.e. Apr-2019, whereas all respective values are provided for label: property.
Tried populating values as plain javascript objects, or typed objects i.e. Label and ChartDataSets, result is the same.
Tech info:
Angular CLI: 8.0.4, Node: 11.12.0, OS: win32 x64, Angular: 8.0.2, [email protected], [email protected]
public barChartData: ChartDataSets[] = [];
public barChartLabels: Label[] = [];
resultItemsReport.forEach(element => {
this.barChartData.push({ data: [element.itemQuantity], label: element.itemName
});
});
this.barChartLabels.push('Apr-2019');
<canvas baseChart
[datasets]="barChartData"
[labels]="barChartLabels"
[options]="barChartOptions"
[plugins]="barChartPlugins"
[legend]="barChartLegend"
[chartType]="barChartType" [colors]="barChartColors">
</canvas>
I expect that bars have colors auto assigned, without the need to assign it manually, as is there already in stackblitz sample application.
Here is data used in chart: