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

Platform: ASP.NET MVC |
Control: Chart |
Published Date: March 10, 2018 |
Last Revised Date: July 1, 2019

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();

      InitializeChart(chartModel);

 

      //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.

Chart rendered by passing properties from server

 

Sample:  Chart from server

2X faster development

The ultimate ASP.NET MVC UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

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