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 WebChartControl.SeriesTemplate property provides access to an object that serves as a template for auto-created series.

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

Specify Series Data Member

Then assign the required data fields to the SeriesBase.ArgumentDataMember and SeriesBase.ValueDataMembers properties using the WebChartControl.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 charts), so in these cases you should assign a data field to each value level.

SpecifySeriesTemplate

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 WebChartControl.SeriesTemplate property. For more information, see Series Scale Types.

To learn more on series template 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 WebChartControl.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 WebChartControl.SeriesTemplate property does not apply to series contained within the WebChartControl.Series collection of a web 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 WebChartControl.BoundDataChanged event of the chart control. The following example demonstrates how a secondary axis can be assigned to an auto-created series.

private void chartControl1_BoundDataChanged(object sender, EventArgs e) {
    for (int i = 0; i < chartControl1.Series.Count; i++) {
        ((BarSeriesView)chartControl1.Series[i].View).AxisY = 
            ((XYDiagram)chartControl1.Diagram).SecondaryAxesY[0];
    }
}

In fact, you can access and customize the same options as for a manually created series using the WebChartControl.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 WebChartControl.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 WebChartControl.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 WebChartControl.SeriesDataMember property. So, to toggle between ascending and descending sort order for an auto-created series, use the WebChartControl.SeriesSorting property. For more information, refer to Sorting Data.