简体   繁体   English

无法绑定到“ chartType”,因为它不是“ canvas”的已知属性

[英]Can't bind to 'chartType' since it isn't a known property of 'canvas'

I'm developing an Angular 6 application using ng2-charts. 我正在使用ng2-charts开发Angular 6应用程序。

However I receive the following error when I debug the project with Visual Studio Code and I see a blank page when I type "ng serve" and hit Enter: 但是,当我使用Visual Studio Code调试项目时,收到以下错误消息,并且在键入“ ng serve”并按Enter时看到空白页:

Can't bind to 'chartType' since it isn't a known property of 'canvas' 无法绑定到“ chartType”,因为它不是“ canvas”的已知属性

I have tried adding "import {ChartsModule} from 'ng2-charts/ng2-charts';" 我尝试添加“从'ng2-charts / ng2-charts'导入{ChartsModule};“; to the component.ts. 到component.ts。 However I still receive the same error. 但是,我仍然收到相同的错误。

Here is the HTML code for chart from the my-bar-chart.component.html file: 以下是my-bar-chart.component.html文件中图表的HTML代码:

<div style="display: block">
  <canvas mdbChart
      [chartType]="chartType"
      [datasets]="chartDatasets"
      [labels]="chartLabels"
      [colors]="chartColors"
      [options]="chartOptions"
      [legend]="true"
      (chartHover)="chartHovered($event)"
      (chartClick)="chartClicked($event)">
  </canvas>
</div>

Here is the my-bar-chart.commponent.ts file: 这是my-bar-chart.commponent.ts文件:

import { Component, OnInit } from '@angular/core';
import {NgbModule} from '@ng-bootstrap/ng-bootstrap';
import {ChartsModule} from 'ng2-charts/ng2-charts';

@Component({
  selector: 'app-my-bar-chart',
  templateUrl: './my-bar-chart.component.html',
  styleUrls: ['./my-bar-chart.component.css']
})

export class MyBarChartComponent implements OnInit {
  public chartType: string = 'horizontalBar';

  public chartDatasets: Array<any> = [
    { data: [65, 59, 80, 81, 56, 55, 40], label: 'My First dataset' }
  ];

  public chartLabels: Array<any> = ['Red', 'Blue', 'Yellow', 'Green', 'Purple', 'Orange'];

  public chartColors: Array<any> = [
    {
      backgroundColor: [
        'rgba(255, 99, 132, 0.2)',
        'rgba(54, 162, 235, 0.2)',
        'rgba(255, 206, 86, 0.2)',
        'rgba(75, 192, 192, 0.2)',
        'rgba(153, 102, 255, 0.2)',
        'rgba(255, 159, 64, 0.2)'
      ],
      borderColor: [
        'rgba(255,99,132,1)',
        'rgba(54, 162, 235, 1)',
        'rgba(255, 206, 86, 1)',
        'rgba(75, 192, 192, 1)',
        'rgba(153, 102, 255, 1)',
        'rgba(255, 159, 64, 1)'
      ],
      borderWidth: 2,
    }
  ];

  public chartOptions: any = {
    responsive: true
  };
  public chartClicked(e: any): void { }
  public chartHovered(e: any): void { }

  constructor() { }
  ngOnInit() {
  }

}

Here is the app.module.ts file: 这是app.module.ts文件:

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';

import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { ChartsModule } from 'ng2-charts/ng2-charts';
import { MyBarChartComponent } from './my-bar-chart/my-bar-chart.component';
import { MyDoughnutChartComponent } from './my-doughnut-chart/my-doughnut-chart.component';
import { MyRadarChartComponent } from './my-radar-chart/my-radar-chart.component';
import { MyPieChartComponent } from './my-pie-chart/my-pie-chart.component';
import { Routes, RouterModule } from '@angular/router';
import {NgbModule} from '@ng-bootstrap/ng-bootstrap';


const routes: Routes=[
  {path:'bar-chart',component:MyBarChartComponent},
  {path:'doughnut-chart',component: MyDoughnutChartComponent},
  {path:'radar-chart',component:MyRadarChartComponent},
  {path:'pie-chart',component:MyPieChartComponent},
  {path:'**',component:MyBarChartComponent}
];

@NgModule({
  declarations: [
    AppComponent,
    MyBarChartComponent,
    MyDoughnutChartComponent,
    MyRadarChartComponent,
    MyPieChartComponent
  ],
  imports: [
    BrowserModule,
    RouterModule.forRoot(routes),
    NgbModule.forRoot(),
    ChartsModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

I expect to see the chart when I type "ng serve" and hit Enter 当我输入“ ng serve”并按Enter时,我希望看到图表

You are not using the right directive. 您没有使用正确的指令。

Please consider this directive: baseChart according to the doc 请考虑以下指令:根据文档的 baseChart

暂无
暂无

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

相关问题 无法绑定到“数据集”,因为它不是“画布”的已知属性 - Can't bind to 'datasets' since it isn't a known property of 'canvas' 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' 具有Angular 4的ng2-chart:无法绑定到“数据”,因为它不是“ canvas”的已知属性 - ng2-chart with Angular 4: Can't bind to 'data' since it isn't a known property of 'canvas' 无法绑定到“控件”,因为它不是(myComponent)的已知属性 - Can't bind to 'control' since it isn't a known property of (myComponent) 无法绑定到“ useStickyClasses”,因为它不是“ div”的已知属性 - Can't bind to 'useStickyClasses' since it isn't a known property of 'div' Angular 7:无法绑定到“元素”,因为它不是 - Angular 7 : Can't bind to 'element' since it isn't a known property of 无法绑定到“ngModel”,因为它不是“输入”的已知属性 - Can't bind to 'ngModel' since it isn't a known property of 'input' 无法绑定到“matMenuTrigger”,因为它不是“a”的已知属性 - Can't bind to 'matMenuTrigger' since it isn't a known property of 'a' 无法绑定,因为它不是选择器组件的已知属性 - Can't bind to since it isn't a known property of selector component
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM