Articles in this section
Category / Section

How to change zOrder of chart series dynamically in ASP.NET MVC?

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.

 CSHTML

<button id="click" onclick="seriesRender()">zOrder</button>
@(Html.EJ().Chart("chartcontainer")
  .Series(sr =>
            {
             sr.Points(pt =>
              {
                 pt.X("Jan").Y(900).Add();
                 pt.X("Feb").Y(820).Add();
                 pt.X("Mar").Y(880).Add();
                 pt.X("Apr").Y(725).Add();
                 pt.X("May").Y(765).Add();                 
               }).Name("Google").SeriesType(SeriesType.Line).Add();      
              sr.Points(pt =>
               {
                  pt.X("Jan").Y(190).Add();
                  pt.X("Feb").Y(226).Add();
                  pt.X("Mar").Y(194).Add();
                  pt.X("Apr").Y(250).Add();
                  pt.X("May").Y(222).Add();
                 }).Name("Bing").SeriesType(SeriesType.Column).Add();    
            }))   
     <script>
       function seriesRender() {
            var chart = $("#container").ejChart("instance");
             //zOrder of first series to 1
             chart.model.series[0].zOrder = 1;
            //zOrder of first series to 0
            chart.model.series[1].zOrder = 0;
            $("#container").ejChart("redraw");
      }
     </script>

The above code changes the rendering order of the series in chart, second series renders first, then the first series.

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 ASP.NET MVC 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 ASP.NET MVC 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