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

Plugins not working in v4 #782

Closed
mgrsskls opened this issue Mar 28, 2022 · 9 comments · Fixed by #786 or #789
Closed

Plugins not working in v4 #782

mgrsskls opened this issue Mar 28, 2022 · 9 comments · Fixed by #786 or #789

Comments

@mgrsskls
Copy link

mgrsskls commented Mar 28, 2022

Expected Behavior

Plugins should be executed when passing to a chart component via :plugins="plugins".

Actual Behavior

Plugins are not executed.

I think this is because plugins is not added to the chart configuration here:

_chart.value = new ChartJS<TType, TData, TLabel>(
canvasEl2DContext,
{
type: chartType,
data: isProxy(data) ? new Proxy(chartData, {}) : chartData,
options: getChartOptions<TType>(options, props.plugins)
}
)

As you can see on https://www.chartjs.org/docs/latest/developers/plugins.html, plugins should be an array in the configuration object (second param).

Or am I missing something?

Thanks a lot!

Environment

  • vue.js version: 2.6.14
  • vue-chart.js version: 4.0.1
  • chart.js version: 3.7.1
  • npm version: - (yarn @ 1.22.18)
@apertureless
Copy link
Owner

@mgrsskls

getChartOptions should handle that.

vue-chartjs/src/utils.ts

Lines 80 to 99 in 5c9a69c

export function getChartOptions<TType extends ChartType = ChartType>(
options?: TChartOptions<TType>,
plugins?: PluginOptionsByType<TType>
): TChartOptions<TType> | undefined {
const chartOptions = options
if (
chartOptions !== undefined &&
'plugins' in chartOptions &&
typeof plugins !== 'undefined' &&
Object.keys(plugins).length > 0
) {
chartOptions.plugins = {
...chartOptions.plugins,
...plugins
}
}
return chartOptions
}

Which plugins are you trying to use?
Are you sure that these plugins work with chart.js 3+ ?

@thabarbados
Copy link
Collaborator

thabarbados commented Mar 28, 2022

@mgrsskls
Copy link
Author

Hi together, thanks for the quick response!

I am using a custom plugin, completely reduced it just for the case of debugging this.

I'm a little bit confused right now, but I'm also not a chart.js expert, so maybe I'm also completely on the wrong track… but here is a minimal repo: https://github.com/mgrsskls/vue-chartjs From my understanding you should get an alert, but that's not the case. I tried both cases: passing a plugins object directly to the vue-chartjs component and passing plugins in the chart options.

When I look at https://www.chartjs.org/docs/latest/developers/plugins.html, the plugins should be passed as an array via the chart options. The getChartOptions method returns an object though.

@thabarbados
Copy link
Collaborator

@mgrsskls thanks for your repo. Yes, it's my mistake. Sorry.
Plugins should be an array of this type https://github.com/chartjs/Chart.js/blob/c057c96693819b41e7b89860f916c0aa361bafa5/types/index.esm.d.ts#L805.
I will fix this soon.

thabarbados added a commit that referenced this issue Mar 29, 2022
change chart plugins type from object to array, fix tests and examples

#782
dangreen pushed a commit that referenced this issue Mar 29, 2022
change chart plugins type from object to array, fix tests and examples

#782
@thabarbados thabarbados reopened this Mar 29, 2022
@thabarbados
Copy link
Collaborator

@mgrsskls fixed in 4.0.3
You can check new types here

@jrahim54
Copy link

@thabarbados how does the new version support plugins like https://www.chartjs.org/chartjs-plugin-annotation/latest/ ? When I tried to register it to Chartjs I get a maximum call stack exceeded error.

@thabarbados
Copy link
Collaborator

@jrahim54 I need some time to understand why this is happening. After that, I will release a bug fix or make a new feature with support for such plugins.

@mgrsskls
Copy link
Author

@mgrsskls thanks for your repo. Yes, it's my mistake. Sorry.

No need to be sorry! :) Thanks for the quick fix, works for me!

thabarbados added a commit that referenced this issue Apr 1, 2022
changing vue2 charts instance type to be compatible with chartjs-plugin-annotation

#782
dangreen pushed a commit that referenced this issue Apr 1, 2022
changing vue2 charts instance type to be compatible with chartjs-plugin-annotation

#782
@thabarbados
Copy link
Collaborator

Hey @jrahim54 . After version 4.0.4 vue-chartjs works with chartjs-plugin-annotation without errors. You can check here

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