Skip to main content

Automatic Series Creation

  • 4 minutes to read

This topic describes automatic series creation based on a template. For alternative approaches that do not utilize templates, refer to the following help topics: Manually Create a Series and Specify Series Data Members.

The topic 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 is a template for auto-created series.

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

Specify Series Data Member

Then, use the WebChartControl.SeriesTemplate property to assign the required data fields to the SeriesBase.ArgumentDataMember and SeriesBase.ValueDataMembers properties. These properties determine the names of the data fields from which auto-created series should obtain data for point arguments and values. Note that some view types require multiple values per series point (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 series point argument type 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 are found within the WebChartControl.SeriesTemplate property. For more information, see the following help topic: Series Scale Types.

The next section of this topic discusses series template customization.

Obtain and Customize an Auto-Created Series

Use the series template’s SeriesBase.View property 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 how to change the view type for an automatically created series, refer to the following help topic: How to: Individually Change the View Type of Automatically Created Series.

Additionally, if you use the WebChartControl.SeriesTemplate property to customize settings, these settings will not apply to series contained within a web chart control’s WebChartControl.Series collection. Settings are only in effect for auto-created series. Like 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];
    }
}

You can also use the WebChartControl.SeriesTemplate property to access and customize the same options for a manually created series. 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 available options are detailed in the following help topic: 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

If you use the series name template to specify settings, these settings are not applied to the data bound series contained within the chart control’s WebChartControl.Series collection.

For an auto-created series, you can define the order in which automatically generated series objects are sorted within the chart control, based on their dynamically created series names. Series names are created from the data field specified by the WebChartControl.SeriesDataMember property. To toggle the ascending and descending sort order for an auto-created series, use the WebChartControl.SeriesSorting property. For more information, refer to the following help topic: Sorting Data.