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

Do you know if this should work with React? #5

Closed
daveywb opened this issue Oct 5, 2021 · 9 comments
Closed

Do you know if this should work with React? #5

daveywb opened this issue Oct 5, 2021 · 9 comments
Labels
help wanted Extra attention is needed question Further information is requested

Comments

@daveywb
Copy link

daveywb commented Oct 5, 2021

Firstly, thanks for updating this for v3!

I'm trying to use this with React. I've npm installed the package, imported it into my file (import 'chart.js-plugin-labels-dv';), added labels:{render: 'label'} to the plugins object, but it doesn't seem to have any effect.

I'm using react-chartjs-2 (which works with v3 even though the name is a little misleading)

Should this work?

Thanks.

@DavideViolante DavideViolante added the question Further information is requested label Oct 6, 2021
@DavideViolante
Copy link
Owner

Honestly I don't know since I don't use React. It should work since it's working on Angular.
Try importing this instead

import Chart from 'chart.js/auto';

If you make this work I'll add info in the Readme.

@Shahzayb
Copy link

Shahzayb commented Jan 21, 2022

import React from 'react';
import Chart from 'chart.js/auto';
import * as helpers from 'chart.js/helpers';

function ChartProvider({children}) {
  React.useEffect(() => {
    window.Chart = Chart;
    Chart.helpers = helpers;
    import('chart.js-plugin-labels-dv');
  }, []);
  return children;
}

export default ChartProvider;
<ChartProvider>
  <App />
</ChartProvider>

@Shahzayb
Copy link

You can also use this https://github.com/chartjs/chartjs-plugin-datalabels

@Shahzayb
Copy link

Checkout https://github.com/chartjs/awesome for more plugins.

@DavideViolante
Copy link
Owner

Can someone confirm that @Shahzayb solution works with React? I wanted to add the info in the readme.

@Levy-D
Copy link

Levy-D commented Sep 6, 2022

This works for me, with one change:

import React from 'react';
import { Chart } from 'chart.js'; //Changed import
import * as helpers from 'chart.js/helpers';

export const LabelPluginProvider: React.FC = ({ children }) => {
    React.useEffect(() => {
        window.Chart = Chart;
        Chart.helpers = helpers;
        import('chart.js-plugin-labels-dv');
    }, []);
    return children;
};```

@DavideViolante
Copy link
Owner

Thanks @Levy-D , I added the info in the readme. Can you help @MrWhiteX with #14 too?

@leduccuong2104
Copy link

leduccuong2104 commented Apr 4, 2023

Chartjs plugin labels with Meteor, it not working

@keremilhan
Copy link

This works for me, with one change:

import React from 'react';
import { Chart } from 'chart.js'; //Changed import
import * as helpers from 'chart.js/helpers';

export const LabelPluginProvider: React.FC = ({ children }) => {
    React.useEffect(() => {
        window.Chart = Chart;
        Chart.helpers = helpers;
        import('chart.js-plugin-labels-dv');
    }, []);
    return children;
};```

This doesn't work for me. Can anyone help me?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed question Further information is requested
Projects
None yet
Development

No branches or pull requests

6 participants