简体   繁体   English

带有 Angular 的 NG2 图表:无法绑定到“颜色”,因为它不是 Angular 中“画布”的已知属性 13

[英]NG2 Chart with Angular: Can't bind to 'colors' since it isn't a known property of 'canvas' in Angular 13

Template <canvas baseChart [datasets]="barChartData" [labels]="barChartLabels" [options]="barChartOptions" [legend]="barChartLegend" [type]="barChartType" [colors]="chartColors"></canvas> Code: <canvas baseChart [datasets]="barChartData" [labels]="barChartLabels" [options]="barChartOptions" [legend]="barChartLegend" [type]="barChartType" [colors]="chartColors"></canvas>代码:

  public chartColors: Array<any> = [
{
  backgroundColor: ['#d13537', '#b000b5']
}

] I am getting error:- Can't bind to 'colors' since it isn't a known property of 'canvas'. ] 我收到错误消息:- 无法绑定到“颜色”,因为它不是“画布”的已知属性。 I am using "@angular/cdk": "^13.1.1", "@angular/common": "~13.0.0", "ng2-charts": "^3.0.8", "chart.js": "^3.7.1", and my working code with "@angular/common": "^7.2.5" is at url https://stackblitz.com/edit/ng2-charts-bar-and-line-qkglqd我正在使用 "@angular/cdk": "^13.1.1", "@angular/common": "~13.0.0", "ng2-charts": "^3.0.8", "chart.js": “^3.7.1”,我的工作代码“@angular/common”:“^7.2.5”位于 url https://stackblitz.com/edit/ng2-charts-bar-and-line-qkglqd

Instead of using the [colors] parameter, use [data] and include a backgroundColor array inside of the dataSet.不要使用 [colors] 参数,而是使用 [data] 并在 dataSet 中包含一个 backgroundColor 数组。 Like this:像这样:

HTML HTML

<canvas baseChart
        [data]="barChartData"
        [labels]="barChartLabels"
        [type]="barChartType">
</canvas>

TS TS

import { ChartData, ChartType } from 'chart.js';

...

  public barChartType: ChartType = 'bar'
  public barChartLabels: string[] = ['Label 1', 'Label 2', 'Label 3'];
  public barChartData: ChartData<'bar'> = {
    labels: this.barChartLabels,
    datasets: [
      {
        label: "Title label",
        data: [5, 3, 1],
        backgroundColor: ["red", "green", "blue"],
        hoverBackgroundColor: ["darkred", "darkgreen", "darkblue"],
      }
    ]
  };

It seems you're using the configuration of a different version.看来您正在使用不同版本的配置。 This method worked for me using Angular 12 and "ng2-charts": "^3.0.8".这种方法对我有用 Angular 12 和“ng2-charts”:“^3.0.8”。 You can read the documentation for the current version here: https://www.chartjs.org/docs/latest/charts/bar.html您可以在此处阅读当前版本的文档: https://www.chartjs.org/docs/latest/charts/bar.html

have same issue with Angular 13.2.3 !与 Angular 13.2.3 有同样的问题!

Aso, experienced that putting the canvas in Aso,体验过将 canvas 放入

<ng-template>

does not cause the build error but the chart is not appearing.不会导致构建错误,但图表不会出现。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 具有Angular 4的ng2-chart:无法绑定到“数据”,因为它不是“ canvas”的已知属性 - ng2-chart with Angular 4: Can't bind to 'data' since it isn't a known property of 'canvas' Angular 7:无法绑定到“元素”,因为它不是 - Angular 7 : Can't bind to 'element' since it isn't a known property of 无法绑定到“”,因为它不是“ angular 2”的已知属性 - can't bind to '' since it isn't a known property of '' angular 2 NG2-Charts 无法绑定到“数据集”,因为它不是“画布”的已知属性 - NG2-Charts Can't bind to 'datasets' since it isn't a known property of 'canvas' NG2-Charts模板解析错误:无法绑定到“数据集”,因为它不是“ canvas”的已知属性 - NG2-Charts Template parse errors: Can't bind to 'datasets' since it isn't a known property of 'canvas' 无法绑定到“数据集”,因为它不是“画布”的已知属性 - Can't bind to 'datasets' since it isn't a known property of 'canvas' 无法绑定到“ chartType”,因为它不是“ canvas”的已知属性 - Can't bind to 'chartType' since it isn't a known property of 'canvas' Angular 4无法绑定到&#39;formGroup&#39;,因为它不是&#39;form&#39;的已知属性 - Angular 4 Can't bind to 'formGroup' since it isn't a known property of 'form' 无法绑定到((ngModel),因为在角度单位测试用例中它不是&#39;input&#39;的已知属性 - Can't bind to '(ngModel' since it isn't a known property of 'input' in angular unit test case 无法绑定到“ formGroup”,因为它不是“ form”的已知属性。 (“角7 - Can't bind to 'formGroup' since it isn't a known property of 'form'. (" in angular 7
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM