chartjs-plugin-labels
chartjs-plugin-labels copied to clipboard
How to make plugin not be global?
I have many chart in any type in my application and I'm using chartjs-plugin-labels to write label on pie chartjs but that affect other charts, I can use of plugins: {labels: false}
and its work but I need to a way that to make plugin private just to specific charts.
I'm using of this in angular8
import * as Chart from 'chart.js';
import 'chartjs-plugin-labels';
How can I do it?
thanks
Have the same issue, thanks for workaround
Having a similar issue. I am unable to disable the plugin on other charts on the page with plugins: false. I have also tried: plugins: { labels: { render: false } } I also tried plugins: {labels: false} but that breaks the page. What is the recommended way to disable the plugin for individual charts?
I had the same problem. If you look at the source code in chartjs-plugin-labels.js, the plugin is registered as global:
Chart.plugins.register(/* plugin object */);
I copied the file and modified the source code to return the plugin rather than registering it globally. Then when creating the chart, I passed in the plugin. See more about passing a plugin directly to a chart here: https://www.chartjs.org/docs/2.9.4/developers/plugins.html.
Attached the updated code to just return and export the plugin object rather than globally registering it:
I fixed my issue.
TypeError: Cannot read property 'x' of null
ChartDataLabels plugin was registered globally in another chart that I had. instead I register locally and that fixed my issue. Docs
basically I just had to remove this line in all my chart definitions
// Register the plugin to all charts:
Chart.register(ChartDataLabels);
instead I just need it the ChartDataLabels in my plugins object:
plugins: [ChartDataLabels], ...```