无法读取未定义的属性'toLocaleString'。 Angular 5 ngx图表

问题描述 投票:1回答:3

Console logCannot read property 'toLocaleString' of undefinedon my component.ts我正在使用这种方法从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>`

对这个错误有什么想法吗?我试过图表:{“name”:string,“price”:number} [] = [];但同样的错误

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

angular angular5 ngx-datatable ngx-charts
3个回答
5
投票

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

ngx-charts-bar-vertical-2d

而不是:

ngx-charts-bar-vertical

0
投票

您的数据需要有一个名为value的属性,但您的数据只有一个名为price的属性。

只需更新您的数据以包含value属性,它应该工作。


0
投票
the above error still occurs for charts such as Grouped Vertical Bar Chart, Grouped Horizontal Bar Chart etc this looks like a bug from ngx-charts
the input for this is 

[
  {
    "name": "Germany",
    "series": [
      {
        "name": "2010",
        "value": 7300000
      },
      {
        "name": "2011",
        "value": 8940000
      }
    ]
  },
​
  {
    "name": "USA",
    "series": [
      {
        "name": "2010",
        "value": 7870000
      },
      {
        "name": "2011",
        "value": 8270000
      }
    ]
  }
]

他们期望外部数组中的值,但如果我们发送它们的值,则没有任何意义

i.e [
{
"name": "Germany",
"value": 234324,
"series": [
]
},
...
]
© www.soinside.com 2019 - 2024. All rights reserved.