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

Tzimpo picture Tzimpo · Jul 8, 2018 · Viewed 7k times · Source

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

Answer

Count Spatula picture Count Spatula · Aug 17, 2018

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

ngx-charts-bar-vertical-2d

Rather than:

ngx-charts-bar-vertical