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. Image for the cookie policy date

Need Chart code sample

I need code for add series and assign datasource in code behind side in vb.net or C# for chart controls

1 Reply

SK Sanjith Kesavan Syncfusion Team June 23, 2016 12:28 PM UTC

Hi Sathayaraj, 

Thanks for contacting Syncfusion support. We have analyzed your query and prepared sample as per your requirement. For add the series and datasource for the series in code behind, please follow the below code. 

<ej:Chart runat="server" ID="Chart1"></ej:Chart> 

protected void Page_Load(object sender, EventArgs e) 
            Series series = new Series(); 
            series.Type = Syncfusion.JavaScript.DataVisualization.SeriesType.Spline; 
            List<data> data = new List<data>(); 
            data.Add(new data(1, 20)); 
            data.Add(new data(2, 30)); 
            data.Add(new data(3, 10)); 
            data.Add(new data(4, 15)); 
            data.Add(new data(5, 30)); 
            series.DataSource = data; 
            series.XName = "xvalue"; 
            series.YName = "yvalue"; 

In the above code, we have initialized the chart in the ASPX page. In code behind, we have created the series for the chart and added datasource for it. Now the chart will render like below. 

In the below link, we have attached sample for your reference. 
Sample link: C#sample 

Same procedure applies for VB.Net also. Please find the below code, what we have written in VB.Net for create the series in code behind and add datasource for it.  

Dim series As New Series() 
        series.Type = Syncfusion.JavaScript.DataVisualization.SeriesType.Spline 
        Dim data As New List(Of data)() 
        data.Add(New data(1, 20)) 
        data.Add(New data(2, 30)) 
        data.Add(New data(3, 10)) 
        data.Add(New data(4, 15)) 
        data.Add(New data(5, 30)) 
        series.DataSource = data 
        series.XName = "xvalue" 
        series.YName = "yvalue" 

Please find the sample from the below link. 
Sample link: VBsample 


Live Chat Icon For mobile
Up arrow icon