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

Plugin called 60 times #14

Open
vasyl-shumskyi opened this issue Apr 29, 2020 · 3 comments
Open

Plugin called 60 times #14

vasyl-shumskyi opened this issue Apr 29, 2020 · 3 comments

Comments

@vasyl-shumskyi
Copy link

vasyl-shumskyi commented Apr 29, 2020

Thanks for an awesome plugin!

I have a strange issue on very basic setup. Plugin called 60 times for some reason.

It happens with every interaction with chart including hover. This slows down chart rendering.

Check out the attached screenshot with word HELLO appeared in debug console 60 times:

Screen Shot 2020-04-30 at 08 44 10

See the code below:

 <canvas id="myChart"></canvas>

<script src="https://cdn.jsdelivr.net/npm/[email protected]"></script>

<script src="https://github.com/ciprianciurea/chartjs-plugin-doughnutlabel/releases/download/2.0.3/chartjs-plugin-doughnutlabel.js"></script>


<script>
var ctx = document.getElementById('myChart').getContext('2d');

var myDoughnutChart = new Chart(ctx, {
  type: 'doughnut',
      data: {
        labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July'],
        datasets: [{
            label: 'My First dataset',
            backgroundColor: 'rgb(255, 99, 132)',
            borderColor: 'rgb(255, 99, 132)',
            data: [0, 10, 5, 2, 20, 30, 45]
        }]
    },
  options: {
    plugins: {
      doughnutlabel: {
        labels: [

          {
            text: total,
            font: { size: '50' },
            color: 'gray'
          }

        ]
      }
    }		
  }
});

function total() {
  console.log('HELLO')
  return 'HELLO'
}
</script>

Can you verify if it happens on your side as well?

@bes1002t
Copy link

bes1002t commented Jul 13, 2020

any improvement so far?

@alexkuc
Copy link

alexkuc commented Feb 10, 2021

This is caused by the use of hook:

beforeDatasetDraw: function(chart, args, options) {

So the improvement would be to use a different hook, possibly afterDraw?

@alexkuc
Copy link

alexkuc commented Feb 15, 2021

I have created a PR of this plugin (https://github.com/alexkuc/chartjs-plugin-doughnutlabel-rebourne) which allows you to override core plugin api so you can use something alternative instead of relying on a hardcoded value.

Ps. I assume that original maintainers of this repo are busy with something else; if they will become available, I am more than happy to merge my fork into this one

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

3 participants