Vue Chart - Show and Hide a Series
The Chart provides an API for showing and hiding a series at runtime. The most common use-case for this API is to show or hide a series when a user clicks the chart legend. To implement this scenario, you need to handle the legendClick event in the following manner. The isVisible(), hide() and show() are methods of the Series object.
App.vue
- <template>
- <DxChart
- @legend-click="legendClickHandler($event)"
- ... >
- </DxChart>
- </template>
- <script>
- import DxChart from 'devextreme-vue/chart';
- export default {
- components: {
- DxChart
- },
- methods: {
- legendClickHandler(e) {
- const series = e.target;
- if (series.isVisible()) {
- series.hide();
- } else {
- series.show();
- }
- }
- }
- }
- </script>
You can hide a series on component initialization. To do this, assign false to the visible property of the object that configures the series.
App.vue
- <template>
- <DxChart ... >
- <DxSeries :visible="false" ... />
- </DxChart>
- </template>
- <script>
- import DxChart, {
- DxSeries
- } from 'devextreme-vue/chart';
- export default {
- components: {
- DxChart,
- DxSeries
- }
- }
- </script>
NOTE
You can hide series to reduce the number of rendered component elements. This can improve Chart performance on large datasets. For more information on how to improve component performance, refer to the following topic: Enhance Performance on Large Datasets.