下面是我找到的源码,但源码中的数据源是一个手动创造的表ds,我的想法是如果我想挂接SQLSERVER数据库中的一个表作为数据源,下面代码我该如何修改,我想主要修改DataSet CreateDataSet() 中的部分就可以,我应该如何修改
<%@ Page Language= "C# " %>
<%@ Register TagPrefix= "web " Namespace= "WebChart " Assembly= "WebChart " %>
<%@ Import Namespace= "System.Data " %>
<%@ Import Namespace= "System.Drawing " %> <script runat= "server ">
void Page_Load(object o, EventArgs e)
{
CreateChart();
}
void CreateChart()
{
DataSet ds = CreateDataSet();
///DataSet ds = SqlDataSource1;
LineChart chart5 = new LineChart();
chart5.Line.Color = Color.Green;
chart5.Fill.Color = Color.Green;
chart5.LineMarker = new DiamondLineMarker(8, Color.Green, Color.Yellow);
chart5.Legend = "Goal ";
foreach(DataRow row in ds.Tables[0].Rows)
{
chart5.Data.Add(new ChartPoint(row[ "date "].ToString(), (int)row[ "goal "]));
}
chartControl1.Charts.Add(chart5);
chartControl1.RedrawChart();
}
DataSet CreateDataSet() {
DataSet ds = new DataSet();
DataTable table = ds.Tables.Add( "Table ");
table.Columns.Add( "date ");
table.Columns.Add( "pri0 ", typeof(int));
table.Columns.Add( "pri1 ", typeof(int));
table.Columns.Add( "pri2 ", typeof(int));
table.Columns.Add( "pri3 ", typeof(int));
table.Columns.Add( "total ", typeof(int));
table.Columns.Add( "goal ", typeof(int));
Random rnd = new Random();