vue3-chart-v2 icon indicating copy to clipboard operation
vue3-chart-v2 copied to clipboard

Cannot read property 'clearRect' of null

Open tuannguyenminh2086 opened this issue 3 years ago • 5 comments

Hi @vutran6853 ,

Thanks for your awesome plugin. But when I integrate it with my code. and it get issues when update data:

Chart.js:2743 Uncaught TypeError: Cannot read property 'clearRect' of null at Object.clear (Chart.js:2743) at Chart.clear (Chart.js:9403) at Chart.draw (Chart.js:9820) at Chart.render (Chart.js:9798) at Object.callback (Chart.js:2207) at Object.advance (Chart.js:3543) at Object.startDigest (Chart.js:3516) at eval (Chart.js:3505)

Is there any support?

tuannguyenminh2086 avatar Jul 05 '21 08:07 tuannguyenminh2086

I had the same probem with a component that renders charts when the user clicks on a specific place. Something like:

<template>
  <chart-here
    v-if="currentChartData !== null"
    @close="currentChartData = null"
    :chart-data="currentChartData"
  />
  <div v-else>
    Rest of code...
  </div>
</template>

If you click on close before the animations are done, it throws the same TypeError. What I did is I canceled all animations manually before setting currentChartData to null:

<template>
  <chart-here
    v-if="currentChartData !== null"
    @close="closeCharts"
    :chart-data="currentChartData"
  />
  <div v-else>
    Rest of code...
  </div>
</template>

<script>
export default {
// ...
  methods: {
    closeCharts() {
      for (const chart of Object.values(window.Chart.instances)) {
        window.Chart.animationService.cancelAnimation(chart);
      }
      this.currentChartData = null;
    },
  },
// ...
}
</script>

This will cancel animations for all charts though. Maybe the components provided by this library that we extend could store internally the reference that they need and then cancel animations inside beforeUnmount hook.

antoniosarosi avatar Jul 23 '21 13:07 antoniosarosi

Getting this issue too, if a user presses back on browser and forward again quickly chart fails to render, or if you mutate the chart data quickly

elie464 avatar Aug 22 '21 06:08 elie464

anyone of you who had a solution for this issue now, please post here. @elie464 @tuannguyenminh2086 @antoniosarosi

ahmedrazaa avatar Feb 22 '22 06:02 ahmedrazaa

Hey @ahmedrazaa i just wrote my own wrapper components on chart.js library and called chart.update() on a watcher whenever the chart data changed. Seems to be working fine. You can see the notes from chart.js https://www.chartjs.org/docs/latest/developers/updates.html#updating-charts

elie464 avatar Feb 22 '22 06:02 elie464

Any news on this issue? I'm facing the same problem even with the the cancelAnimation trick

gabriellatavares avatar Jan 31 '23 17:01 gabriellatavares