chartjs-plugin-labels icon indicating copy to clipboard operation
chartjs-plugin-labels copied to clipboard

Update for Chart.JS 3.x Support

Open lincolnthree opened this issue 4 years ago • 10 comments

First, great plugin, thank you!

This pull request updates this library for support of the upcoming Chart.JS 3.x release (currently in alpha.)

See documentation here: https://www.chartjs.org/docs/next/getting-started/v3-migration

lincolnthree avatar May 08 '20 16:05 lincolnthree

@lincolnthree I think this PR doesn't work with Chart.js 3.0.0 beta.

To register the plugin, the call is changed:

Chart.register(plugin);

instead of

Chart.plugins.register(plugin);

Furthermode the multilabels does not work because they are configured as an array. See issue #7754 in Chart,js.

With the current code, the optionParm argument of beforeUpdate method of plugin is an empty object, if you configured your plugin to manage multiple labels.

In my plugin code, I have changed, taking the configuration from chart instance instead of using the option argument, like that:

beforeDatasetsUpdate: function (chart) {
   if (!SUPPORTED_TYPES[chart.config.type]) {
      return;
   }
   const optionParams = chart.options.plugins.labels;
   var options = optionParams;
   if (!Array.isArray(optionParams)) {
      options = [optionParams];
   }
   ....
   ....

stockiNail avatar Sep 07 '20 10:09 stockiNail

That's probably right, since this PR was created before the .beta was released :) And since it doesn't seem like it's going to be merged, care to send a PR to my branch? I can pull it in and update it, which will also update this PR.

lincolnthree avatar Sep 07 '20 14:09 lincolnthree

Hey folks! Would love to see v3 support being merged and released.

What's the current blocker and how can we help it?

jipiboily avatar May 17 '21 18:05 jipiboily

@emn178 I don't want to be rude; I'm just curious: are you still maintaining the product available to review this PR maybe so that we can know what to collectively work on to get it merged and released with ChartJS v3 support? Would be awesome! :)

Thanks!

jipiboily avatar May 18 '21 18:05 jipiboily

@lincolnthree is this branch working for you in production right now?

It doesn't seem to work for me, but I have a weird setup with ChartjsNodeCanvas so it might totally be due to something in my setup.

jipiboily avatar May 18 '21 18:05 jipiboily

@jipiboily No. The v3 pre-release branch in my PR is no longer compatible and requires more changes to become current with Chart.is 3.x release.

lincolnthree avatar May 19 '21 12:05 lincolnthree

Thanks for the reply @lincolnthree. I'll see if / when I can get to figure this out. I'll update here if / when that happens.

Or did you find another plugin that works with v3 and does something similar?

jipiboily avatar May 19 '21 12:05 jipiboily

It doesn't seem to work, even using this PR and the changes proposed by @stockiNail in his first comment. What else should be changed to make it work with v3? Can we figure it out all together? Ref: https://www.chartjs.org/docs/next/getting-started/v3-migration.html

edit: made it work https://github.com/emn178/chartjs-plugin-labels/issues/140

DavideViolante avatar May 19 '21 12:05 DavideViolante

@DavideViolante, thank you for updating the plugin! I've encountered a problem.. how can I use two labels?

This: labels: [ { render: 'label', position: 'outside' }, { render: 'value' } ] Isn't working with the new chart.js.

dana-mb avatar Jun 04 '21 12:06 dana-mb

Thanks for pointing this out @dana-mb It seems like it doesn't work when mixing ouside and inside options. Outside or inside alone works. I don't know at the moment how to fix it, PRs are welcome on my fork...

DavideViolante avatar Jun 04 '21 13:06 DavideViolante