.netCHARTING v7.0 Documentation Send comments on this topic.
Data Sources
Getting Started > General Tutorials > Chart Surface Objects > Data Sources

Glossary Item Box

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: AnnotationDataSource.aspx

 

Datasources can also be acquired by getting them from a series or series collection like so:

[C#]
DataSource ds = mySeriesCollection.GetDataSource();
[Visual Basic]
Dim ds AS mySeriesCollection.GetDataSource()

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 

Evaluating Tokens

A datasource object can be used to evaluate tokens manually as shown in this snippet:

[C#]
DataSource ds = mySeries.GetDataSource();
string result = ds.EvaluateExpression("Name:%Name, Sum:%Sum");
[Visual Basic]
Dim ds AS mySeries.GetDataSource()
Dim result AS string
result = ds.EvaluateExpression("Name:%Name, Sum:%Sum")
Sample: DataSourceExpressions.aspx

 

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.GetDataSource();
// 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.GetDataSource();
LegendBox.DataSoruce.SplitInto = DataSourceType.ElementGroup;

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

' Or it can be 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.

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

SeriesCollection

Series

  • Elements

Element Group

  • Series
  • Elements

Element

  • None

Axis Marker

  • None

Scale Range

  • None

 

  

Sample: 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: AnnotationDataSource.aspx
©2011. All Rights Reserved.