question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

new Chart() after destroy() doesn't recreate responsive wrapper

See original GitHub issue

Problem observed building an SPA. Running

var chart = new Chart(ctx, {
	options: {
		responsive: true
	}
})

will create an initial chart wiht this structure:

div (my wrapper)
	div.chartjs-size-monitor
	canvas.chartjs-render-monitor

Then

chart.destroy();
chart = new Chart(ctx, {
	options: {
		responsive: true
	}
})

will miss the required resizer:

div (my wrapper)
	canvas.chartjs-render-monitor

Potentially root cause can probably also be oberved when running

gulp unittest --inputs test/specs/core.controller.tests.js --watch

and then updating core.controller.tests.js. Not clearing the browser instance inbetween seems to have negative side effects, too.

Can no longer repro the last case.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
andigcommented, Aug 8, 2017

As workaround its sufficient to clear the wrapper node (which is also often recommended on SO):

$('#plot').empty().append('<canvas></canvas>');
0reactions
andigcommented, Aug 25, 2017

Closing until I find a better test case.

Read more comments on GitHub >

github_iconTop Results From Across the Web

chart.js load totally new data - Stack Overflow
I had huge problems with this. First I tried .clear() then I tried .destroy() and I tried setting my chart reference to null....
Read more >
Customizing Chart.JS in React - Bits and Pieces
We check if the chart was built previously. If so, we use the destroy() method before we create our chart.
Read more >
[Solved]-Set an array to be displayed at Chart js-Chart.js
The easiest way would be to just destroy the chart (using the chart variable) and construct a new chart using the new data....
Read more >
angular-chart-new - npm Package Health Analysis - Snyk
destroy() on the chart; $resize : call .resize() on the chart. angular-chart.js emits the following events on the scope ...
Read more >
Chart.js with Angular | andrew-flower.com
warning Modifying the original array of data will not update the array. After modifying the array, you would need to call the update()...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found