Glossary Item Box

.netCHARTING v3.2 Documentation Send comments on this topic.

Data Sources

Introduction

The DataSource class behaves like a container for chart objects such as Series, AxisMarkers and others to provide dynamic information needed to parse tokens or populate a legend box with entries. The type of data stored in the data source will determine what type of tokens will be replaced in a string.

The class does not relate to database or any other types data sources used to populate charts.

Creating DataSources

Creating a DataSource
The following code instantiates a data source containing a series collection.

[C#]
LegendEntry.DataSource = DataSource.FromSeriesCollection(mySeriesCollection);
[Visual Basic]
LegendEntry.DataSource = DataSource.FromSeriesCollection(mySeriesCollection)

The DataSource class also provides implicit casts that alleviate the need to instantiate a DataSource object.

[C#]

LegendEntry.DataSource = mySeriesCollection;
This feature is not supported in VB.Net

 

Sample: features/AnnotationDataSource.aspx

 

Complex DataSources
A DataSource object can contain additional information to properly parse tokens. This information specifies the relationships of SeriesCollections to Series and to Element objects. Specifically, what element is in which series and what SeriesCollection contains that Series. For example, to specify an element with relationships to it's parents, the following code can be used:

[C#]

LegendEntry.DataSource = DataSource.FromElement(mySeriesCollection,1,2);
[Visual Basic]

LegendEntry.DataSource = DataSource.FromElement(mySeriesCollection,1,2)

The parameters of this static constructor are: (Parent SeriesCollection, parent series index in the SeriesCollection, element Index in Series)

The specific reason the token parser may use additional information about an element is so that tokens such as '%PercentOfSeries' can be correctly calculated based on the values of the complete series. If these tokens are not needed a much simpler way to specify an element is by using the implicit cast functionality of DataSource. Simply put, to just specify the element itself (C# Only):

[C#]

LegendEntry.DataSource = myElement;

In VB.Net you can specify the element using a static constructor

[Visual Basic]
LegendEntry.DataSource = DataSource.FromElement(myElement);


Using DataSources 

Populating LegendBoxes

The DataSource class can also quickly populate a legend with entries by setting the LegendBox.DataSource property.

Example: This code will populate the legend entry with series entries in a SeriseCollection.

[C#]

LegendBox.DataSource = mySeriesColleciton;
// or
LegendEntry.DataSource = DataSource.FromSeriesCollection(mySeriesCollection);
[Visual Basic]

LegendEntry.DataSource = DataSource.FromSeriesCollection(mySeriesCollection)

There is however more flexibility available. The type of legend entries generated can also be specified. The series collection can be split into legend entries for each series, each element, or each element group. This option is defined by the DataSource.SplitInto property.

[C#]

LegendBox.DataSource = mySeriesColleciton;
LegendBox.DataSoruce.SplitInto = DataSourceType.ElementGroup;

// Or it can be specified in the static constructor:
LegendEntry.DataSource = DataSource.FromSeriesCollection(mySeriesCollection,DataSourceType.ElementGroup);
[Visual Basic]


' Specified in the static constructor:
LegendEntry.DataSource = DataSource.FromSeriesCollection(mySeriesCollection,DataSourceType.ElementGroup)

This functionality will enable you to show different and valuable information about your data in the same chart. 

This table shows what splits are available for each data source type.

ShowThis table shows what splits are available for each data source type.

SeriesCollection

Series

Element Group

Element

Axis Marker

Scale Range

 

  

Sample: features/LegendBoxDataSource.aspx
 
LegendEntry DataSource
Each legend entry can have a data source which is specified through the LegendEntry.DataSource property.
 
 
Annotation DataSource
Custom annotations can take data sources to process tokens in their labels.
 
Sample: features/AnnotationDataSource.aspx

2002 - 2005 Webavail Productions Inc. & Corporate Web Solutions Ltd.. All Rights Reserved.