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

Toggle Tooltip dynamically #1329

Open
fitimsijarinaa opened this issue Aug 3, 2021 · 4 comments
Open

Toggle Tooltip dynamically #1329

fitimsijarinaa opened this issue Aug 3, 2021 · 4 comments

Comments

@fitimsijarinaa
Copy link

fitimsijarinaa commented Aug 3, 2021

Reproduction of the problem

Hi,

I am using the "ng2-charts": "^3.0.0-rc.4" and "chart.js": "^3.5.0". I want to enable or disable the tooltip dynamically. This are my configurations:

public barChartOptions: ChartConfiguration["options"] = {
    responsive: true,
    plugins: {
      tooltip: {
        // Disable the on-canvas tooltip
        enabled: false,
      },
    }

Then I am using it like this right now:

   public toggleTootlip(enableTooltip: boolean): void { 
      this.chart?.options?.plugins?.tooltip?.enabled = enableTooltip;
      this.chart?.render();
  }

Is there a cleaner way to do it?

@fitimsijarinaa
Copy link
Author

@santam85 is there a way t update the ChartConfiguration and update without rerendering the charts?

@santam85
Copy link
Contributor

santam85 commented Aug 20, 2021

You can call the update() method on the directive instance, that should do the trick.

@ViewChild(BaseChartDirective) chart: BaseChartDirective | undefined;
[...]
chart.update()

@fitimsijarinaa
Copy link
Author

@santam85 this doesn't work for me unfortunately.

@santam85
Copy link
Contributor

Probably the tooltip plugin implementation does not check the value again after rendering. Maybe you could use the callbacks and prevents tooltip to show that way: https://www.chartjs.org/docs/latest/configuration/tooltip.html#tooltip-callbacks

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