Add dynamic charts using ASP.NET CHART CONTROL, c#
Posted
by dhareni
on Stack Overflow
See other posts from Stack Overflow
or by dhareni
Published on 2008-12-02T19:03:21Z
Indexed on
2010/04/26
18:23 UTC
Read the original article
Hit count: 285
I wanted to add dynamic charts in the webpage. It goes like this...
I get the start and end date from user and draw separate charts for each date bewteen the start and end date.
I get the data from sql database and bind it with the chart like this:
SqlConnection UsageLogConn = new
SqlConnection(ConfigurationManager.ConnectionStrings["UsageConn"].ConnectionString);
UsageLogConn.Open();//open connection
string sql = "SELECT v.interval,dateadd(mi,(v.interval-1)*2,'" + startdate + " 00:00:00') as 'intervaltime',COUNT(Datediff(minute,'" + startdate + " 00:00:00',d.DateTime)/2) AS Total FROM usage_internet_intervals v left outer join (select * from Usage_Internet where " + name + " LIKE ('%" + value + "%') and DateTime BETWEEN '" + startdate + " 00:00:00' AND '" + enddate + " 23:59:59') d on v.interval = Datediff(minute,'" + startdate + " 00:00:00',d.DateTime)/2 GROUP BY v.interval,Datediff(minute,'" + startdate + " 00:00:00',d.DateTime)/2 ORDER BY Interval";
SqlCommand cmd = new SqlCommand(sql, UsageLogConn);
SqlDataAdapter mySQLadapter = new SqlDataAdapter(cmd);
Chart1.DataSource = cmd;
// set series members names for the X and Y values
Chart1.Series["Series 1"].XValueMember = "intervaltime";
Chart1.Series["Series 1"].YValueMembers = "Total";
UsageLogConn.Close();
// data bind to the selected data source
Chart1.DataBind();
cmd.Dispose();
The above code adds only one chart for one date and I have added 'chart1' to design view and its not created dynamic. But I wanted to add more charts dynamic at runtime to the webpage.
Can anyone help me with this?
I am using VS 2008, ASP.NET 3.5 and the charting lib is: using System.Web.UI.DataVisualization.Charting;
© Stack Overflow or respective owner