Ng2-charts: Error: "undefined" is not a chart type.

Created on 6 Mar 2019  路  2Comments  路  Source: valor-software/ng2-charts

Reproduction of the problem
https://ng2-charts7-demo-crzoce.stackblitz.io

Source - https://stackblitz.com/edit/ng2-charts7-demo-crzoce

I am trying to create a line chart using static data. I am getting an error in the console.
Error: "undefined" is not a chart type. Here is the component and the template.

--------------app.component.ts

import { Component, ViewChild } from '@angular/core';
import { Observable } from 'rxjs';
import { BaseChartDirective } from 'ng2-charts';
import { DataSeries, chartColors } from './models/data-series';
import { Chart} from 'chart.js';

@Component({
  selector: 'my-app',
  templateUrl: './app.component.html',
  styleUrls: [ './app.component.scss' ]
})
export class AppComponent  {

  constructor() {   
  }

  ngOnInit() { }

  public lineChartData: any[] = [
    { data: [32, 14, 46, 23, 38, 56], label: "Sentiment Analysis" },
    { data: [12, 18, 26, 13, 28, 26], label: "Image Recognition" },
    { data: [52, 34, 49, 53, 68, 62], label: "Forecasting" }
  ];
  public lineChartLabels: string[] = ["Jan", "Feb", "Mar", "Apr", "May", "Jun"];
  public lineChartOptions: any = {
    responsive: true
  };
  public lineChartColors: any[] = [
    {
      // grey
      backgroundColor: "rgba(148,159,177,0.2)",
      borderColor: "rgba(148,159,177,1)",
      pointBackgroundColor: "rgba(148,159,177,1)",
      pointBorderColor: "#fff",
      pointHoverBackgroundColor: "#fff",
      pointHoverBorderColor: "rgba(148,159,177,0.8)"
    },
    {
      // dark grey
      backgroundColor: "rgba(77,83,96,0.2)",
      borderColor: "rgba(77,83,96,1)",
      pointBackgroundColor: "rgba(77,83,96,1)",
      pointBorderColor: "#fff",
      pointHoverBackgroundColor: "#fff",
      pointHoverBorderColor: "rgba(77,83,96,1)"
    },
    {
      // grey
      backgroundColor: "rgba(148,159,177,0.2)",
      borderColor: "rgba(148,159,177,1)",
      pointBackgroundColor: "rgba(148,159,177,1)",
      pointBorderColor: "#fff",
      pointHoverBackgroundColor: "#fff",
      pointHoverBorderColor: "rgba(148,159,177,0.8)"
    }
  ];
  public lineChartLegend: true;
  public lineChartType: "line";

--------------app.component.html

     <canvas
    baseChart
    [datasets]="lineChartData"
    [labels]="lineChartLabels"
    [options]="lineChartOptions"
    [colors]="lineChartColors"
    [legend]="lineChartLegend"
    [chartType]="lineChartType"></canvas>

Most helpful comment

You have a little typo, it's hit me a few times in the past as well :)

public lineChartType: "line";

Should be:

public lineChartType = "line";

All 2 comments

You have a little typo, it's hit me a few times in the past as well :)

public lineChartType: "line";

Should be:

public lineChartType = "line";

Thank you. Wish the debugger showed that line.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Adwind picture Adwind  路  3Comments

Maistho picture Maistho  路  3Comments

dj-techs picture dj-techs  路  3Comments

tssobe picture tssobe  路  4Comments

vmironovs picture vmironovs  路  3Comments