Articles in this section
Category / Section

How to add or remove series dynamically in Vue Chart?

1 min read

Description

This article shows how to add or remove series from the Vue Chart.

Solution

To add or remove a series dynamically, you can make use of the addSeries or removeSeries method respectively. The addSeries method can be used to set the series values to the chart, whereas the removeSeries method can be used to remove a particular series from the chart by specifying its index.

Code Snippet

addSeries: function() {
     this.$refs.chart.addSeries([{
       type: 'Line',
       dataSource: [
          { x: 'Jan', y: 20 }, 
          { x: 'Feb', y: 22 }, 
          { x: 'Mar', y: 24 }, 
          { x: 'Apr', y: 21 },
          { x: 'May', y: 19 }, 
          { x: 'Jun', y: 23 }
       ],
       xName: 'x', yName: 'y',width: 2,
       marker: {
         visible: true,
         isFilled: true
       }						
     }]);;
   },
   removeSeries: function() {
     let count = this.$refs.chart.ej2Instances.series.length;
     for (let i = 0; i < count; i++) {
         this.$refs.chart.removeSeries(i);
     }                        
   }

The following image illustrates the output of the above code.

image.png

View Sample in Stackblitz

Conclusion

I hope you enjoyed learning how to add or remove series dynamically in Vue Chart.

You can refer to our Vue Charts feature tour page to learn about its other features and documentation, and how to quickly get started for configuration specifications. You can also explore our Vue Charts example to understand how to create and visualize data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comment section below. You can also contact us through our support forums, support portal, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied