QUESTION
How do I access series and element objects generated from my database or data table?
ANSWER
Using the method below is quick and easy however the data is not accessible until after it is pulled from the database and populated in the chart. The PostDataProcessing event can be used to manipulate any chart data after processing but before the chart is rendered from it. See the sample postdataprocessing.aspx for an example.
[C#]
Chart.Series.Data = myDataTable; Chart.SeriesCollection.Add();
// Element e = Chart.SeriesCollection[0].Elements[0]; // This Will Not Work here. This code could be used in the OnPostDataProcessing event.
// To use the event, the following line would need to be added the page load Chart.PostDataProcessing +=new PostDataProcessingEventHandler(OnPostDataProcessing);
// The same code would work in this event as the data is populated void OnPostDataProcessing(Object sender) { Element e = Chart.SeriesCollection[0].Elements[0]; } |
[Visual Basic]
Chart.Series.Data = myDataTable Chart.SeriesCollection.Add()
' Element e = Chart.SeriesCollection(0).Elements(0) ' This Will Not Work here. This code could be used in the OnPostDataProcessing event.
'To use the event, the following line would need to be added the page load AddHandler Chart.PostDataProcessing, AddressOf OnPostDataProcessing
'The same code would work in this event as the data is populated Sub OnPostDataProcessing(sender As [Object]) Element e = Chart.SeriesCollection(0).Elements(0) End Sub 'OnPostDataProcessing |
To get access to series and element data without using the OnPostDataProcessing event you can also use the the DataEngine object directly. It has the same data acquisition related properties as Chart.Series but it will return a fully populated SeriesCollection you can manipulate in any way.
Note: The generated elements will not have colors specified. This is determined at runtime. If you would like to access the color used see property: Chart.Palette.
This code will get the first element of the series generated from the data table.
[C#]
DataEngine de = new DataEngine(); de.Data = myDataTable;
SeriesCollection sc = de.GetSeries(); Element e = sc[0].Elements[0]; |
[Visual Basic]
Dim de As New DataEngine() de.Data = myDataTable
Dim sc As SeriesCollection = de.GetSeries() Element e = sc(0).Elements(0) |
For more information on using the data engine and it's features, see:
- Help file (included in download) > Getting Started > Data Tutorials > Data Engine
- Sample (included in download) > features/dataEngine.aspx