Ng2-charts: "chart_js_1.Chart is not a constructor"

Created on 24 Jun 2017  路  8Comments  路  Source: valor-software/ng2-charts

Getting above error when I am trying to implement chart .

Most helpful comment

Hello I had the same issue, but I am not using ng2-charts, Im using pure Charts.js, I solved this attaching, the Chart.js libray into "scripts"{
"../node_modules/chart.js/dist/Chart.min.js"
}
on angular-cli.json, then in my controller I just wrote declare var Chart: any;, right after my imports.

All 8 comments

Did you fix this issue, facing same error while implementing ng2-charts

Update "chart.js": "1.1.1" to "chart.js": "^2.6.0" in package.json.
Install latest chart.js and ng2 charts
npm install ng2-charts --save
npm install chart.js --save

@meghsmayur thanks mate issue fixed.

I am trying to use Chart.js (2.7.1 from Cloudflare CDN) as well as the latest version of ng2-charts and am receiving this error in my project. It worked before upgrading to Angular 5 if that helps.

Hello I had the same issue, but I am not using ng2-charts, Im using pure Charts.js, I solved this attaching, the Chart.js libray into "scripts"{
"../node_modules/chart.js/dist/Chart.min.js"
}
on angular-cli.json, then in my controller I just wrote declare var Chart: any;, right after my imports.

thianlopezz's comment helped me resolve this though it's not angular-cli.json now, but in angular.json in the scripts add:

"scripts": [
              "./node_modules/chart.js/dist/Chart.min.js"
            ]

Then in the component don't import Chart.js but instead:

declare var Chart: any;
/**
   * Draws the chart on the context given the options
   * @param ctx
   * @param options
   */
  getChart(ctx, options){
    return new Chart(ctx, options);
  }

I am having the same issue. I have chart.js version 2.7.3 and ng2-charts version 1.6.0. I have already tried adding declare var Charts: any to the component and including the script in my .angular-cli.json file but nothing has worked.

This package is now updated for Angular 7 (and chart.js 2.7.45). If this issue persists, please provide a codepen/stackblitz/... example showing the issue.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

alexcastillo picture alexcastillo  路  5Comments

vmironovs picture vmironovs  路  3Comments

sarn3792 picture sarn3792  路  4Comments

brandonreid picture brandonreid  路  3Comments

tssobe picture tssobe  路  4Comments