We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to render chart from code behind

Chart can be rendered from the code behind by initializing the required properties in controller and passing those properties via ViewData to client side.


The following code illustrates the initialization of chart properties in the controller.



      //Namespace to get the datavisualization (chart) component properties

      using Syncfusion.JavaScript.DataVisualization.Models;


       //Initializing the chart model

      ChartProperties chartModel = new ChartProperties();



      //Passing chart properties using the ViewData

      ViewData["ChartModel"] = chartModel;


      private void InitializeChart(ChartProperties chartModel)


            //Initialize the data source for chart

            List<LineChartData> data = new List<LineChartData>();

            data.Add(new LineChartData(2005, 28));



            Series series = new Series();

            series.DataSource = data;

            series.XName = "Xvalue";

            series.YName = "YValue1";






Binding the chart properties passed via ViewData from the controller in the client side as below.



@{Html.EJ().Chart("container", (Syncfusion.JavaScript.DataVisualization.Models.ChartProperties)ViewData["ChartModel"]).Render(); }





The following screenshot displays the line chart rendered by passing properties from server.


SampleChart from server

Article ID: Published Date: Last Revised Date: Platform: Control:
8576 03/10/2018 03/23/2018 ASP.NET MVC Chart
Did you find this information helpful?
Add Comment
You must log in to leave a comment

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon