Articles in this section
Category / Section

How to add new series dynamically in JavaScript Chart?

1 min read

Essential Chart supports dynamically customizing all the properties with the instance of Chart. You can create an instance for Chart by calling the ejChart constructor method with the string instance as parameter. To add a new series dynamically, add a series object to the series collection of chart instance. The following code example illustrates the above.

JS

<div id="container"></div>
<input type="button" onclick="AddSeries()" value="Add Series" />
<script type="text/javascript">
function AddSeries() {
    var Chart = $("#container").ejChart("instance");
    //Adding a new series dynamically using Chart instance
    Chart.model.series[Chart.model.series.length] = {
        points: [{ x: 'Australia', y: 20 }, { x:     'China', y: 15 }], 
        name: 'Dynamic Series' 
    }
    //Redrawing chart after updating series collection
    Chart.redraw();
}
$(function () {
    $("#container").ejChart({
        series: [{
            points: [{ x: 'India', y: 25 },
                { x: 'Australia', y: 32 },
                { x: 'China', y: 41 },
                { x: 'Japan', y: 30 },
                {x: 'France', y:28}
            ]
        }]
    });
});
</script>

The following screenshot illustrates the Chart without series.

Before adding a new series dynamically in Chart

Figure 1: Chart without series

The following screenshot illustrates the Chart after adding series.

After adding a new series dynamically in Chart

Figure 2: Chart after adding series

Sample link

A sample for dynamically adding a new series is available in the following link, Sample

 

JS Playground sample link: Dynamic Series


Conclusion

I hope you enjoyed learning how to add a new series dynamically in JavaScript Chart.

You can refer to our JavaScript charts feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our JavaScript Charts example to understand how to create and manipulate 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 comments section below. You can also contact us through our support forumsDirect-Trac, 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 sign in to leave a comment
Access denied
Access denied