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.
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Create charts dynamically base on user data

Thread ID:

Created:

Updated:

Platform:

Replies:

130261 May 3,2017 08:21 AM UTC May 3,2017 12:15 PM UTC ASP.NET Web Forms 3
loading
Tags: Chart
Trinh Thang Long
Asked On May 3, 2017 08:21 AM UTC

Hello,

I am working on a ASP.NET web form project which need to create several charts by using data from CSV files,
Currently I don't know how to create charts dynamically using behind code (.cs code) instead of  the <ej:Chart> tag predefined in the .aspx file.
For example, I have several CSV files (which I don't know exactly number of files beforehand because they are created by the end-user), like data1.csv, data2.csv...dataN.csv 
I would like to plot N graphs from those data files automatically each time the web page loaded. 
I've tried to search on the forum and KB for awhile but still not find the answer.

P/s: I don't want to use the multiple panes solution because the data format and scale are different so they should be separated to different graphs

Saravana Kumar Kanagavel [Syncfusion]
Replied On May 3, 2017 11:16 AM UTC

Hi Trinh, 
 
We have analyzed your query and created a sample based on your requirement. In the sample, we are dynamically creating the chart without using <ej:Chart> tag in ASPX page and we have bind the data from the CSV file to the chart. 
 
Please find the code example below 
[CS] 
            List<ChartData> list = new List<ChartData>(); 
            string path = Server.MapPath(@"~\App_Data\ChartData.csv"); 
            using (var fs = File.OpenRead(path))  
 
            using (var reader = new StreamReader(fs)) 
            { 
                while (!reader.EndOfStream) 
                { 
                    var line = reader.ReadLine(); 
                    var values = line.Split(','); 
                    list.Add(new ChartData(values[0], Convert.ToDouble(values[1]))); 
                } 
            } 
            
            Syncfusion.JavaScript.Web.Chart chart = new Syncfusion.JavaScript.Web.Chart(); 
            chart.PrimaryXAxis.ValueType = AxisValueType.Category; 
            Series series1 = new Series(); 
            series1.XName = "Xvalue"; 
            series1.YName = "YValue1"; 
            chart.DataSource = list; 
            chart.DataBind(); 
            chart.Size.Height = "450"; 
            chart.Size.Width = "600"; 
            chart.Model.Series.Add(series1); 
            holder.Controls.Add(chart); 
 
In the above code, we are getting the data from .csv file with specific path and binding that data to the chart series. Find the output of the sample below 
 
 
And please find the data in .csv file from the below 
 
 
 
We have attached the sample for your reference. And you can change this with respect to your requirement. 
Please let us know if you have any concern.

Regards,
Saravana Kumar K 
 


Trinh Thang Long
Replied On May 3, 2017 11:31 AM UTC

Excellent! This is exactly what I need, thank you very much for your quickly support!

Saravana Kumar Kanagavel [Syncfusion]
Replied On May 3, 2017 12:15 PM UTC

Hi Trinh, 
 
Thanks for your update. 
 
Please let us know if you need any further assistance on this. 
 
Regards, 
Saravana Kumar K. 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

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

;