I have a component with two charts which I show on the button click. I use the same component of a chart but I give different chartData to it through two different getters. The chart looks like this:
<script>
import { Bar, mixins } from 'vue-chartjs';
export default {
extends: Bar,
mixins: [mixins.reactiveProp],
props: ['chartData', 'options'],
mounted() {
this.renderChart(this.chartData, this.options);
},
};
</script>
I know that reactiveProp renders a new chart if data has changed (and initialises nice animation). But currently two getters give the same data for this.chartData so when I try to switch the chart, it stays the same. Is there any way to update or destroy data so the chart will be re-rendered, even if it gets the same data from another getter? For some reasons, methods like update(), destroy(), clear() didn't work out but maybe I used them in the wrong place.
Here's my page with the chart:
<template>
<div>
<button @click="showAll = false">
Show old users
</button>
<button @click="showAll = true">
Show all users
</button>
<chart v-if="isChartData === true && showAll === false" :options="options" :chart-data="setDataOld" />
<chart v-if="isChartData === true && showAll === true" :options="options" :chart-data="setData" />
<div>
<template>
<chart v-if="isChartData === true && showAll === false" :options="options" :chart-data="setDataOld" :key="setDataOld" />:key="'setDataOld'". If you want to use an explicit string you need to use single quotes inside double quotes (or vice versa). Basically, you don't want your key to be an object, you want it to be some primitive value, and it doesn't have to be any specific value, it just needs to be different for chart one and chart two. Really, you could just use:key="1"and:key="2"in your case.