How do I migrate my code to use the DataEngine?


QUESTION

How do I migrate my code to use the DataEngine?

 ANSWER

The DataEngine object has the same properties as its Chart/Series data property counterparts and is simple to change.

Code without the DataEngine.
This process does not allow access to the individual elements. The chart accesses the database when it begins generating.

[C#]

Chart.DefaultSeries.ConnectionString = ConfigurationSettings.AppSettings["DNCConnectionString"];
Chart.Series.Type = SeriesType.Spline;
Chart.Series.StartDate=new System.DateTime(2002,1,1,0,0,0);
Chart.Series.EndDate = new System.DateTime(2002,1,1,23,59,59);
Chart.Series.SqlStatement= @"SELECT OrderDate,Sum(Total) FROM Orders WHERE OrderDate >= #STARTDATE# AND OrderDate <= #ENDDATE# GROUP BY Orders.OrderDate ORDER BY Orders.OrderDate";
Chart.SeriesCollection.Add();

 
[Visual Basic]

Chart.DefaultSeries.ConnectionString = ConfigurationSettings.AppSettings("DNCConnectionString")
Chart.Series.Type = SeriesType.Spline
Chart.Series.StartDate = New System.DateTime(2002,1,1,0,0,0)
Chart.Series.EndDate = New System.DateTime(2002,1,1,23,59,59)
Chart.Series.SqlStatement= "SELECT OrderDate,Sum(Total) FROM Orders WHERE OrderDate >= #STARTDATE# AND OrderDate <= #ENDDATE# GROUP BY Orders.OrderDate ORDER BY Orders.OrderDate"
Chart.SeriesCollection.Add()

Code with the DataEngine.
This process uses very similar code as above, but it accesses the database when the de.GetSeries() method is called.

[C#]

DataEngine de = new DataEngine();
de.ConnectionString = ConfigurationSettings.AppSettings["DNCConnectionString"];
de.StartDate=new System.DateTime(2002,1,1,0,0,0);
de.EndDate = new System.DateTime(2002,1,1,23,59,59);
de.SqlStatement= @"SELECT OrderDate,Sum(Total) FROM Orders WHERE OrderDate >= #STARTDATE# AND OrderDate <= #ENDDATE# GROUP BY Orders.OrderDate ORDER BY Orders.OrderDate";
SeriesCollection sc = de.GetSeries();
sc[0].Type = SeriesType.Spline;
Chart.SeriesCollection.Add(sc);

 
[Visual Basic]

Dim de As DataEngine = New DataEngine()
de.ConnectionString = ConfigurationSettings.AppSettings("DNCConnectionString")
de.StartDate = New System.DateTime(2002,1,1,0,0,0)
de.EndDate = New System.DateTime(2002,1,1,23,59,59)
de.SqlStatement= "SELECT OrderDate,Sum(Total) FROM Orders WHERE OrderDate >= #STARTDATE# AND OrderDate <= #ENDDATE# GROUP BY Orders.OrderDate ORDER BY Orders.OrderDate"
Dim sc As SeriesCollection = de.GetSeries()
sc(0).Type = SeriesType.Spline
Chart.SeriesCollection.Add(sc)

As you can see all the same properties are available with the DataEngine as are with Chart.Series. However, using the DataEngine object allows you to get a fully populated series collection with elements that can be manipulated before they are added to the chart.

For more information, please see this kb:
How do I access series and element generated from my database or data table?


Posted Wednesday, February 16, 2005 by Support
http://www.dotnetcharting.com/kb/KnowledgebaseArticle10957.aspx