How do I migrate my code to use the DataEngine?

Expand / Collapse
 

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?



Rate this Article:
     

Add Your Comments


Comment require login or registration.

Details
Last Modified:Wednesday, March 3, 2010
Last Modified By: Support
Type: HOWTO
Rated 3 stars based on 2 votes.
Article has been viewed 10,174 times.
Options