How to dynamically bind the series from code behind
How to dynamically bind the series from code behind?
Essential chart supports dynamically binding the series from code behind. To bind the series dynamically from code behind, create a sample by giving points in the code behind and bind the data source to the chart. After binding the data source, create a series object using code behind. In the series, you must map the x and y values to the respective fields using the xName and yName properties, respectively. Then, add the series into the chart. Kindly find the code snippet below,
[ASP.NET]
//Assigning points in code behind
List<ChartData> data = new List<ChartData>();
data.Add(new ChartData(2005, 28));
data.Add(new ChartData(2006, 25));
data.Add(new ChartData(2007, 26));
data.Add(new ChartData(2008, 27));
data.Add(new ChartData(2009, 32));
data.Add(new ChartData(2010, 35));
//Assigning series in code behind
Series series = new Series();
series.XName = "Xvalue";
series.YName = "YValue1";
series.Name = "Dynamic Series";
series.Fill = "red";
this.Chart1.Series.Add(series);
//Binding Datasource to Chart
this.Chart1.DataSource = data;
this.Chart1.DataBind();
//Create chart in client-side
<ej:Chart ClientIDMode="Static" ID="Chart1" runat="server" IsResponsive="true" >
</ej:Chart>
screenshot:
Sample link: https://www.syncfusion.com/downloads/support/forum/140033/ze/webformsKB2007007198