代码之家  ›  专栏  ›  技术社区  ›  Tzimpo

无法读取未定义的属性“ToLocaleString”。角度5 NGX图表

  •  1
  • Tzimpo  · 技术社区  · 8 年前

    Console log Cannot read property 'toLocaleString' of undefined 在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>`
    

    知道这个错误吗?我尝试了chart:“name”:string,“price”:number[]=[];但同样的错误

    我使用的是Angular cli:1.7.4 节点:8.11.2 操作系统:win32 x64 角度:5.0.2 “@swinglane/ngx charts”:“7.4.0”,

    3 回复  |  直到 7 年前
        1
  •  4
  •   Count Spatula    7 年前

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

    ngx-charts-bar-vertical-2d
    

    而不是:

    ngx-charts-bar-vertical
    
        2
  •  0
  •   user184994    8 年前

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

    只需更新数据以包括 价值 属性,它应该工作。

        3
  •  0
  •   Bhimashankar Mantur    7 年前
    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": [
    ]
    },
    ...
    ]
    
    推荐文章