Skip to main content
A newer version of this page is available. .

Automatic Series Creation

  • 4 minutes to read

This document describes automatic series creation based on a template. For alternative approaches, refer to Manually Create a Series and Specify Series Data Members.

This document consists of the following sections:

Define a Template for an Auto-Created Series

Automatic series creation is the most uniform approach for providing chart data. This approach is used when the number of series is either unknown or too large.

The ChartControl.SeriesTemplate property provides access to an object that serves as a template for auto-created series.

When a data source is assigned to the ChartControl.DataSource property, define the name of a data column upon which new series will be created (and named), using the ChartControl.SeriesDataMember property.

ProvideData_Template_0

Then assign the required data fields to the SeriesBase.ArgumentDataMember and SeriesBase.ValueDataMembers properties using the ChartControl.SeriesTemplate property. These properties determine the names of the data fields from which auto-created series should obtain data for their point arguments and values. Note that multiple values per series point are a prerequisite for series of some view types (e.g. Bubble or Stock), so in these cases you should assign a data field to each value level.

ProvideData_Series_2

As with manually created series, you do not usually need to change the argument scale type of the SeriesBase.ArgumentScaleType property (set to Auto mode by default) because the type of series point argument is detected automatically, based on the underlying data type. If you wish to change the Numerical value scale type, use the SeriesBase.ValueScaleType property. For auto-created series, these properties reside within the ChartControl.SeriesTemplate property. To learn more on this, refer to Series Scale Types.

To learn more on series templates customization, refer to the next section of this document (Obtain and Customize an Auto-Created Series).

Obtain and Customize an Auto-Created Series

Use the SeriesBase.View property of the series template to define a common view type for an auto-created series. Note that it is not possible to determine a custom view type for an auto-created series at design time. At runtime, you can do this within the ChartControl.BoundDataChanged event handler. To learn more on this, refer to How to: Individually Change the View Type of Automatically Created Series.

Moreover, any setting that is customized using the ChartControl.SeriesTemplate property does not apply to series contained within the ChartControl.Series collection of a chart control. These settings are only in effect for auto-created series. So, as with the view type, you cannot obtain and customize an individual auto-created series at design time.

At runtime, to individually customize these series, you can access them in the specific ChartControl.BoundDataChanged event of the chart control. The following example demonstrates how a secondary axis can be assigned to an auto-created series.

private void chart_BoundDataChanged(object sender, EventArgs e) {
    XYDiagram diagram = chart.Diagram as XYDiagram;
    if (diagram != null) {
        foreach (Series series in chart.Series) {
            BarSeriesView view = series.View as BarSeriesView;
            if (view != null) {
                view.AxisY = diagram.SecondaryAxesY[0]; 
            }
        }
    }
}

In fact, you can access and customize the same options as for a manually created series using the ChartControl.SeriesTemplate property. To access these settings at runtime, use the following code.


SideBySideBarSeriesLabel label = chart.Series[0].Label as SideBySideBarSeriesLabel;
if (label != null) {
    label.Position = BarSeriesLabelPosition.Top;
}

The options available are detailed in the following document: Specify Series Data Members.

Below are descriptions for options specific to auto-created series.

The SeriesNameTemplate option of an auto-created series allows you to define prefix and postfix text for the series names that are dynamically created as a result of binding a chart control to data, using the ChartControl.SeriesNameTemplate property. Expand this property in the Properties window to access the SeriesNameTemplate.BeginText and SeriesNameTemplate.EndText properties.

SeriesNameTemplate

Note that the settings available from the series name template are not applied to the data bound series contained within the ChartControl.Series collection of a chart control.

For an auto-created series, it is possible to define the order in which automatically generated series objects are sorted within the chart control, based on their dynamically created series names, which are taken from a data field specified by the ChartControl.SeriesDataMember property. So, to toggle between ascending and descending sort order of auto-created series, use the ChartControl.SeriesSorting property. For more information, refer to Sorting Data.

See Also