Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I'm using Angular 17 and can't find NgChartsModule so i'cant import #2000

Open
KrisnaDhira opened this issue Aug 2, 2024 · 6 comments
Open

Comments

@KrisnaDhira
Copy link

KrisnaDhira commented Aug 2, 2024

Reproduction of the problem

ng2-charts is a port & modification of Chart.js component for Angular 2. Sometimes the issue is related with Chart.js instead of ng2-charts.
To confirm, if the issue shows in a pure Chart.js project, it is a issue of Chart.js.
Pure Chart.js starting template: https://jsfiddle.net/Hongbo_Miao/mvct2uwo/3/

If the issue does not show in a pure Chart.js project, and shows in a ng2-charts project, please try to provide a minimal demo of the problem.
ng2-charts starting template: http://plnkr.co/edit/Ka4NXG3pZ1mXnaN95HX5?p=preview

@jenilvora0408
Copy link

I also had the same issue. For Angular 17, it would be best if you install ng2-charts version 5.0.4.
It would allow you to import 'NgChartsModule' in standalone components as well.

@madieukhang
Copy link

Hi @KrisnaDhira
with new version using
BaseChartDirective instead of NgChartsModule
image

@aschoerg
Copy link

For anyone stumbling accross this, I struggled after migrating from Angular 14 to 18, ng-charts 4 to 6.

I could not make the providers: [provideCharts(withDefaultRegisterables())] to work. I only have modules and adding it to their providers did not work.

The trick for me was to do as @madieukhang said, and import the BaseChartDirective instead of NgChartsModule in my (sub) module.

But then no scales etc. were detected by chart.js. Looked in NgChartsModule... so just add the following lines in your (sub) module:

import { BaseChartDirective } from 'ng2-charts';
import { Chart, registerables } from 'chart.js';

Chart.register(...registerables);

@NgModule({
  imports: [ BaseChartDirective  ],
})
export class MySubModule { }

I have no idea if this is a desired way, at least it works. Maybe someone of the devs can help?

@aschoerg
Copy link

aschoerg commented Sep 10, 2024

... after playing around, I finally found out:

in your sub-module just add:

import { BaseChartDirective, provideCharts, withDefaultRegisterables } from 'ng2-charts';

@NgModule({
  imports: [ BaseChartDirective ],
  providers: [provideCharts(withDefaultRegisterables())]
})
export class MySubModule { }

The docs mislead me with the standalone component...

@lingoyak
Copy link

... after playing around, I finally found out:

in your sub-module just add:

import { BaseChartDirective, provideCharts, withDefaultRegisterables } from 'ng2-charts';

@NgModule({
  imports: [ BaseChartDirective ],
  providers: [provideCharts(withDefaultRegisterables())]
})
export class MySubModule { }

The docs mislead me with the standalone component...

Thanks for the info. It worked.

@Tobias243
Copy link

Anybody looking at this using nx and wondering why it's not working, try nx reset.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants