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.

How to destroy chart before re-rendering?

See original GitHub issue

Expected Behavior

I have a chart that can be rendered multiple times, for example as we change filter criteria.

Actual Behavior

When I do this, it seems like all the charts “stack up” underneath each other. This is very obvious when I move the mouse over the charts. The various charts that I’ve seen pop in and out as I drag the mouse over the chart.

What I’ve Done

I’m using this.renderChart(data, options) to render each time the filter changes. Based upon information I’ve found through web searches, I tried usingthis._chart.destroy() before calling renderChart() but that produces a browser console error saying destroy() doesn’t exist.

Environment

  • vue.js version: 2.4.4
  • vue-chart.js vsion: 3.0.0
  • npm version: 5.3.0

Issue Analytics

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

github_iconTop GitHub Comments

9reactions
thc1967commented, Oct 20, 2017

Sometimes _chart doesn’t exist yet, so using code like this seems to work:

render: function () {
    if (this.$data._chart) {
        this.$data._chart.destroy();
    }
    this.renderChart({...
1reaction
aperturelesscommented, May 29, 2018

You can only access it inside your Chart component.

Read more comments on GitHub >

github_iconTop Results From Across the Web

React & Chartjs: How can I best destroy my chart when re ...
1 Answer 1 · Declare chart variable outside of class component · Run the build chart fn on both componentDidMount & componentDidUpdate ·...
Read more >
How to use chart destroy API and render new chart in Chart JS
How to use chart destroy API and render new chart in Chart JSIn this video we will explore how to use chart destroy...
Read more >
How to destroy chart.js chart in lightning component
Hi, Place the canvas tag inside any div tag. First time you can successfully draw the chart on the canvas .Next time when...
Read more >
[Solved]-How to clear/destroy Chart.js canvas when the chart ...
I had problems with data and size changes on rerendering, and i found a way to force updating it using ref (profitChartRef.current.chartInstance.destroy();) ...
Read more >
How to use chart destroy API and render new chart in Chart JS
In this case the destroy chart is a must use. We need to use chart.destroy() API to make the canvas a white slate...
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