-
-
Notifications
You must be signed in to change notification settings - Fork 836
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
[Feature Request] Expose _chart or provide update function #805
Comments
We have the same problem. The chart works great, except for the unreactive options. We use the annotation plugin and want to update annotations without destroying the chart and re-rendering it. It would be awesome if options would be reactive or the update function would be exposed. |
Alternatively, make options reactive too? Or is there anything that makes this idea bad? |
I also find myself needing access to the chart object, to call zoom (and likely other) plugin methods |
Not sure if this will help or not, I'm currently using vue-chartjs with Vue 2 and the composition api. I can get a reference to the chart using a template ref: <template>
<bar ref="chart" />
</template>
<script>
import { onMounted } from '@vue/composition-api';
export default {
setup(props, { refs }) {
onMounted(() => {
const currentChart = refs.chart.getCurrentChart();
// chartjs API is available on currentChart - https://www.chartjs.org/docs/latest/developers/api.html
});
}
}
</script> For reactive options, I'm able to re-render the chart with a template ref and a watch function, calling <template>
<bar :chart-data="chartData" :chart-options="chartOptions" ref="chart" />
</template>
<script>
import {
ref,
watch,
} from '@vue/composition-api';
export default {
setup(props, { refs }) {
const chartData = ref({ ...yourData })
const chartOptions = ref({ someOption: true });
watch(chartOptions, () => {
refs.chart.renderChart(chartData.value, chartOptions.value);
});
// some time later
// chartOptions.value.someOption = false;
return {
chartData,
chartOptions,
}
}
}
</script> |
trying to migrate to newest version, our charts depend on being able to update options. I used to do this by watching the options and updating manually using |
the temporary Vue 3 workaround for my needs seems to be watching the options and set a flag on the component to trigger v-if re-rendering the chart itself. I'm using vue's nextTick function to trigger a re render with <template>
<Scatter v-if="showChart" :chart-data="chartData" :chart-options="options"></Scatter>
</template> import { nextTick } from "vue";
...
data() {
return {
showChart: true
}
},
watch: {
async options() {
this.showChart = false;
await nextTick(() => {
this.showChart = true;
});
},
}, id rather not have to do this though please, it defeats the purpose of the whole reactivity update 😕 |
Hi folks. |
add options watcher and expose updateChart function #805
Hi guys. We made options reactive and exposed chart references in release 4.1.0. |
With 4.1.0, tested that the scales/stacked options can be toggled and reflected on the chart |
Thank you! 🥰 |
Would you like to work on this feature?
What problem are you trying to solve?
Since chart options is not reactive, so I am suggesting that you either expose the _chart object or provide a update function that could force update the chart component.
I'm trying to get a bar chart that switch between stacked and unstacked, and I couldn't find a way to update the chart (unless I actually create two charts and switch between them)
Describe the solution you'd like
Expose _chart reference, or provide update function that trigger the _chart.update() function
Describe alternatives you've considered
No response
Documentation, Adoption, Migration Strategy
No response
The text was updated successfully, but these errors were encountered: