首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >(NG2-CHARTS)无法绑定到图表类型,因为它不是的已知属性

(NG2-CHARTS)无法绑定到图表类型,因为它不是的已知属性
EN

Stack Overflow用户
提问于 2019-05-16 22:48:58
回答 1查看 344关注 0票数 0

我从我的图表组件中得到以下错误。我已经在我的app.module.ts文件中导入了ChartsModule,我不确定发生了什么?

代码语言:javascript
复制
    Can't bind to 'ChartType' since it isn't a known property of 'canvas'. ("
    [options]="barChartOptions"
    [legend]="barChartLegend"
    [ERROR ->][ChartType]="barChartType">

这是我的chart.component.ts文件:

代码语言:javascript
复制
const SAMPLE_BARCHART_DATA: any[] = [
  { data: [65, 59, 80, 81, 57, 54, 30], label: 'Fall Sales'},
  { data: [25, 39, 20, 41, 56, 53, 30], label: 'Spring Sales'},
];

const SAMPLE_BARCHART_LABELS: string[] = ['w1', 'w2' , 'w3', 'w4', 'w5', 'w6', 'w7'];

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


export class BarChartComponent implements OnInit {

  constructor() { }

  public barChartData: any[] = SAMPLE_BARCHART_DATA;
  public barChartLabels: string[] = SAMPLE_BARCHART_LABELS;
  public barChartType = 'bar';
  public barChartLegend = false;
  public barChartOptions: any = {
    scaleShowVerticalLines: false,
    responsive: true
  };

  ngOnInit() {
  }

}

下面是我的组件的HTML模板:

代码语言:javascript
复制
  <canvas baseChart
    [datasets]="barChartData"
    [labels]="barChartLabels"
    [options]="barChartOptions"
    [legend]="barChartLegend"
    [ChartType]="barChartType">
  </canvas>
</div>

下面是包含正确导入的app.module.ts文件:

代码语言:javascript
复制
import { NgModule } from '@angular/core';
import { RouterModule} from '@angular/router';
import { appRoutes } from '../routes';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { NavbarComponent } from './navbar/navbar.component';
import { SidebarComponent } from './sidebar/sidebar.component';
import { SectionDashboardComponent } from './Sections/section-dashboard/section-dashboard.component';
import { SectionComputerManagementComponent } from './Sections/section-computer-management/section-computer-management.component';
import { SectionHelpdeskLinksComponent } from './Sections/section-helpdesk-links/section-helpdesk-links.component';
import { BarChartComponent } from './charts/bar-chart/bar-chart.component';
import { LineChartComponent } from './charts/line-chart/line-chart.component';
import { PieChartComponent } from './charts/pie-chart/pie-chart.component';
import { ChartsModule } from 'ng2-charts';


@NgModule({
  declarations: [
    AppComponent,
    NavbarComponent,
    SidebarComponent,
    SectionDashboardComponent,
    SectionComputerManagementComponent,
    SectionHelpdeskLinksComponent,
    BarChartComponent,
    LineChartComponent,
    PieChartComponent
  ],
  imports: [
    BrowserModule,
    AppRoutingModule,
    RouterModule.forRoot(appRoutes),
    ChartsModule,
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

此外,以下是我的angular.json文件样式和脚本:

代码语言:javascript
复制
 "styles": [
              "../ngsight/node_modules/bootstrap/dist/css/bootstrap.min.css",
              "src/styles.css"
            ],
            "scripts": [
              "../ngsight/node_modules/jquery/dist/jquery.min.js",
              "../ngsight/node_modules/popper.js/dist/umd/popper.min.js",
              "../ngsight/node_modules/chart.js/dist/chart.min.js",
              "../ngsight/node_modules/bootstrap/dist/js/bootstrap.min.js",
              "../ngsight/node_modules/chart.js/dist/Chart.bundle.min.js"
            ],
EN

回答 1

Stack Overflow用户

发布于 2019-05-16 22:54:32

chartType是驼峰式的案例。

请在下面使用:

代码语言:javascript
复制
<canvas baseChart
 [datasets]="barChartData"
 [labels]="barChartLabels"
 [options]="barChartOptions"
 [legend]="barChartLegend"
 [chartType]="barChartType">
</canvas>
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56171283

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档