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

Chart doesn't clear between component use #72

Open
robwestbrook opened this issue Dec 21, 2020 · 2 comments
Open

Chart doesn't clear between component use #72

robwestbrook opened this issue Dec 21, 2020 · 2 comments

Comments

@robwestbrook
Copy link

I have a candlestick chart component. I'm selecting a stock from a list, which passes a prop containing the ticker and and a prop containing the chart data points. Working well. The problem is when I pass new props to the component, the chart add the data points to the first. Every time I click on a new stock, the chart adds the data points again. The data points do not clear between component usage.

I've tried clearing the data using both the onDestroy and beforeUpdate lifecycle functions, to no effect.

Is there a way to clear data?

@YogliB
Copy link

YogliB commented Mar 30, 2021

Does this work as expected using the vanilla JS library?

@astronautintheocean
Copy link

This worked for me:

<script>
  import { onDestroy } from 'svelte';
  import { chart } from 'svelte-apexcharts';
  
  let options = {}; // add chart options here
  
  onDestroy(() => {
    options = null;
  });
</script>

{#if options}
  // render chart here
  <div use:chart={options} />
{/if}

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