Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot read property 'toLocaleString' of undefined. Angular 5 ngx-charts

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",

like image 550
Tzimpo Avatar asked Jan 03 '23 04:01

Tzimpo


2 Answers

For a Grouped Vertical Bar Chart, you need to use:

ngx-charts-bar-vertical-2d

Rather than:

ngx-charts-bar-vertical
like image 97
Count Spatula Avatar answered May 05 '23 08:05

Count Spatula


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.

like image 35
user184994 Avatar answered May 05 '23 07:05

user184994