I'm getting the following error from my Chart Component. I've imported ChartsModule into my app.module.ts file, I'm not sure what is going on?

    Can't bind to 'ChartType' since it isn't a known property of 'canvas'. ("
    [options]="barChartOptions"
    [legend]="barChartLegend"
    [ERROR ->][ChartType]="barChartType">

Here's my chart.component.ts file:



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() {
  }

}

Here's the HTML template for my component:

  <canvas baseChart
    [datasets]="barChartData"
    [labels]="barChartLabels"
    [options]="barChartOptions"
    [legend]="barChartLegend"
    [ChartType]="barChartType">
  </canvas>
</div>

Here's the app.module.ts file with the correct imports:

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 { }

Also, here's my angular.json file styles and scripts:

 "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"
            ],

1 Answers

1
Maihan Nijat On

The chartType is camel case.

Use below:

<canvas baseChart
 [datasets]="barChartData"
 [labels]="barChartLabels"
 [options]="barChartOptions"
 [legend]="barChartLegend"
 [chartType]="barChartType">
</canvas>