Console logCannot read property 'toLocaleString' of undefinedon my component.ts i am using this method to take the data from json
getChartProducts() {
this.TicketService.getAlladminPage(this.number, this.size, this.sort, this.orderByColumn)
.subscribe(
(chart: any[]) => {
let item = 0;
if (chart['content']) {
while(item < chart['content'].length){
let chartItem = {
'name' : chart['content'][item].name,
'price': chart['content'][item].price
};
this.chart.push(chartItem);
item ++;
}
console.log( this.chart);
}
});
}`
i also set
`
chart: { name :string, price :number}[] = [];
view: any[] = [700, 400];
// options
showXAxis = true;
showYAxis = true;
gradient = false;
showLegend = true;
showXAxisLabel = true;
showYAxisLabel = true;`
and my HTML
` <ngx-charts-bar-vertical
[view]="view"
[scheme]="colorScheme"
[results]="chart"
[gradient]="gradient"
[xAxis]="showXAxis"
[yAxis]="showYAxis"
[legend]="showLegend"
[showXAxisLabel]="showXAxisLabel"
[showYAxisLabel]="showYAxisLabel"
[xAxisLabel]="xAxisLabel"
[yAxisLabel]="yAxisLabel"
(select)="onSelect($event)">
</ngx-charts-bar-vertical>`
Any idea for this error? i tried chart: { "name":string, "price" :number}[] = []; but again the same error
I am using Angular CLI: 1.7.4 Node: 8.11.2 OS: win32 x64 Angular: 5.0.2 "@swimlane/ngx-charts": "7.4.0",
For a Grouped Vertical Bar Chart, you need to use:
ngx-charts-bar-vertical-2d
Rather than:
ngx-charts-bar-vertical
Your data needs to have a property called value
, but your data only has a property called price
.
Just update your data to include a value
property, and it should work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With