首页 > 解决方案 > 无法读取未定义的属性“toLocaleString”。Angular 5 ngx 图表

问题描述

控制台日志无法读取我的 component.ts 上未定义的属性“toLocaleString”我正在使用此方法从 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);
              }
            });

      }`

我也设置

`
     chart: { name :string, price :number}[] = [];
view: any[] = [700, 400];

  // options
  showXAxis = true;
  showYAxis = true;
  gradient = false;
  showLegend = true;
  showXAxisLabel = true;
  showYAxisLabel = true;`

和我的 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>`

对这个错误有什么想法吗?我试过图表:{“名称”:字符串,“价格”:数字} [] = []; 但同样的错误

我正在使用 Angular CLI:1.7.4 节点:8.11.2 操作系统:win32 x64 Angular:5.0.2 “@swimlane/ngx-charts”:“7.4.0”,

标签: angularangular5ngx-datatablengx-charts

解决方案


对于分组垂直条形图,您需要使用:

ngx-charts-bar-vertical-2d

而不是:

ngx-charts-bar-vertical

推荐阅读