Articles in this section
Category / Section

How to change zOrder of chart series dynamically in JavaScript?

1 min read

The zOrder property is used to arrange the series in series collection before rendering the chart. When two series overlap, the zOrder value determines the series that should appear in front. Series with lowest zOrder value is rendered first by default and series with highest zOrder value is displayed in front of all other series. This is illustrated in the following code example.

 JS

<div id="container"></div>
<button id="click" onclick="seriesRender()">zOrder</button>
<script type="text/javascript">
$(function () {
    $("#container").ejChart(
        {
             // ... 
            series: [
            {
                points: [{ x: 'Jan', y: 900 }, { x: 'Feb', y: 820 },
                    { x: 'Mar', y: 880 }, { x: 'Apr', y: 725 }, 
                    { x: 'May', y: 765 }],
                type: 'line'   
            },
            {
                points: [{ x: 'Jan', y: 190 }, { x: 'Feb', y: 226 },
                    { x: 'Mar', y: 194 }, { x: 'Apr', y: 250 }, 
                    { x: 'May', y: 222 }],
                type: 'line'   
            }],            
            // ...         
    });
});
function seriesRender() {
    var chart = $("#container").ejChart("instance");
    //Set zOrder of first series to 1
    chart.model.series[0].zOrder = 1;
    //Set zOrder of second series to 0
    chart.model.series[1].zOrder = 0;
    $("#container").ejChart("redraw");
}
</script>

 

JS Playground Link: Series Order

The following screenshot illustrates the chart before changing the zOrder of the series.

Figure 1: Chart before changing the zOrder of the series

The following screenshot illustrates the chart after changing zOrder of the series.

Figure 2: Chart after changing the zOrder of the series


Conclusion

I hope you enjoyed learning about how to change zOrder of chart series dynamically.

You can refer to our JavaScript Chart 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 Chart 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