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

How to specify pert-chart plugins? #1577

Open
ddcovery opened this issue Dec 27, 2022 · 3 comments
Open

How to specify pert-chart plugins? #1577

ddcovery opened this issue Dec 27, 2022 · 3 comments

Comments

@ddcovery
Copy link

Sorry, this is only a question I can't solve about plugins registration:

Standard chatjs accepts to register per-chart plugin this way:

const plugin = { /* plugin implementation */ };

// chart1 and chart2 use "plugin"
const chart1 = new Chart(ctx, {
    plugins: [plugin]
});

const chart2 = new Chart(ctx, {
    plugins: [plugin]
});

// chart3 doesn't use "plugin"
const chart3 = new Chart(ctx, {});

How can this be performed using ng2-charts?

thank you for advance

@ddcovery
Copy link
Author

ddcovery commented Dec 28, 2022

As I can see, your "getChartConfiguration()" doesn't allow to assign local pluggins to the chart

    getChartConfiguration() {
        return {
            type: this.type,
            data: this.getChartData(),
            options: this.getChartOptions(),
           // This is the point to add local pluggins :-/
        };
    }

Sometimes I need an specific "background" drawing for my particular chart (not as a generic chart plugin) and I need to implement a custom beforeDraw or afterDraw. Local plugins are really good for this kind of functionalities

@ddcovery
Copy link
Author

Sorry, I see you solved this in v4.
I'm using v3 ( I can't upgrade Angular in my project and I'm forced to use v3).

@on3dd
Copy link

on3dd commented Jul 15, 2024

In case anyone still wondering, you can add plugins via the plugins input of BaseChartDirective

In .component.html:

<canvas 
  baseChart
  type="doughnut"
  [data]="doughnutChartData"
  [options]="doughnutChartOptions"
  [plugins]="doughnutChartPlugins">
</canvas>

In .component.ts:

public doughnutChartData: ChartConfiguration<'doughnut'>['data'] = { ... }

public doughnutChartOptions: ChartConfiguration<'bar'>['options'] = { ... }

public doughnutChartPlugins: ChartConfiguration<'doughnut'>['plugins'] = [ ... ]

I wish there was a clearer explanation of this in the documentation so that you don't have to check the library's internals to find the answer to your questions..

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

2 participants