I wanted to add dynamic charts to a web page. It happens like this ...
I get the start and end dates from the user and draw separate charts for each date during the start and end dates.
I get data from sql database and bind it to the diagram as follows:
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();
In the above code, only one chart is added for one date, and I added "chart1" to create the view and its dynamics not created. But I wanted to add dynamic runtime diagrams to the web page.
Can anyone help me with this?
I am using VS 2008, ASP.NET 3.5 and the lib chart: using System.Web.UI.DataVisualization.Charting;
dhareni