angular - 需要数据或数据集字段才能以 Angular 4 呈现字符条

标签 angular charts

我正在尝试在我的 Angular 4 项目中使用 ng2-charts

HTML:

 <canvas baseChart
            [datasets]="customerBarChartData"
            [colors]="barChartColors"
            [options]="customerBarChartOptions"
            [legend]="barChartLegend"
            [chartType]="barChartType"
            ></canvas>

TS:

  geochatArry: Array<any> = [];
  ....
  public customerBarChartData:any[] = this.geochatArry;
  .... 
  /// Service
   this.geochatArry=data.json();
   console.log(this.geochatArry);

enter image description here

但我收到 ng-charts 配置错误,需要数据或数据集字段才能呈现字符栏。请告诉我我的错误在哪里。

谢谢。

最佳答案

当动态数据进入“customerBarChartData”数组时使用 *ngIf 它将起作用。

<div style="display: block" *ngIf="customerBarChartData">
   <canvas baseChart
   [datasets]="customerBarChartData"
   [colors]="barChartColors"
   [options]="customerBarChartOptions"
   [legend]="barChartLegend"
   [chartType]="barChartType">
</canvas>
</div>

关于angular - 需要数据或数据集字段才能以 Angular 4 呈现字符条,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46909164/

相关文章:

javascript - Google Charts - 仪表板 ComboChart 不堆叠条形图

php - 使用 jqwidgets 时不显示 mysql 数据图表

android - AChartEngine - 如何获取单个系列中 "single Date"值(作为 X 轴)的多个 Y 值?

angular - 应该对所有事情都使用 ChangeDetectionStrategy.OnPush 吗?

css - 如何将跨度放置在 Angular 4 的 mat-icon 上并在 Click 上下拉

linux - 在 Linux 服务器上部署 Angular 5 应用程序

AngularJS 2 ZoneAwarePromise 而不是 bool 值

node.js - Node JS Web 应用程序部署

asp.net-mvc - 如何创建 3D 饼图? -Asp.net MVC

date - 如何将日期和值与 Google 图表中的网格线对齐?