Skip to main content

Data Aggregation

  • 8 minutes to read

The Chart Control can use an aggregate function to group raw data source values and show aggregates as series points. You can use aggregation to show grouped data and decrease the number of visible points in a chart. Data aggregation is only available for argument axes (x-axes).

Aggregated Data

Note

24.1 Demo Center: Launch the Data Aggregation demo

Aggregation vs Summaries

In addition to Aggregation, the Chart Control provides Summaries that also allow you to group raw data values.

Aggregation Summary
Store Data Chart stores raw data source values. Chart stores summarized values.
Change Detail Level Chart re-calculates data in memory. Chart re-loads data from the data source.
Behave on Zoom If the automatic scale options are used, Chart recalculates value aggregates when it is zoomed. Chart does not re-calculate aggregated values when it is zoomed.
Memory Consumption High Low

Aggregation Basics

When the aggregation is enabled, the chart splits the x-axis into intervals (the x-axis measurement unit value defines the intervals), and uses an aggregate function to aggregate data for each interval.

The AggregateFunction enumeration lists the available aggregate functions:

  • Average (a default function)
  • Count
  • Financial (Use it for financial series.)
  • Histogram (See the Histogram topic for more information.)
  • Maximum
  • Minimum
  • Sum
  • Custom (Refer to the Create an Aggregate Function section for more information.)

Scale options assigned to the x-axis’s ~ScaleOptions property store aggregation-related settings. You can use the following option types:

Options

Description

How to use

Automatic Date-Time, Automatic Time-Span, and Automatic Numeric

The chart control defines the optimal measurement unit for an axis based on the data set’s values, the Chart Control’s current size, and zoom level.

For date-time axes. Assign a AutomaticDateTimeScaleOptions object to the AxisX2D.DateTimeScaleOptions, AxisX3D.DateTimeScaleOptions or RadarAxisX2D.DateTimeScaleOptions property.
For time-span axes. Assign a AutomaticTimeSpanScaleOptions object to the AxisX2D.TimeSpanScaleOptions, AxisX3D.TimeSpanScaleOptions or RadarAxisX2D.TimeSpanScaleOptions property.
For numeric axes. Assign a AutomaticNumericScaleOptions object to the AxisX2D.NumericScaleOptions, AxisX3D.NumericScaleOptions or CircularAxisX2D.NumericScaleOptions property.

Manual Date-Time, Manual Time-Span, and Manual Numeric

You can use the MeasureUnit property to specify the axis measurement unit that defines how to divide an axis scale into intervals for aggregation.

For date-time axes. Assign a ManualDateTimeScaleOptions (or its descendant) object to the AxisX2D.DateTimeScaleOptions, AxisX3D.DateTimeScaleOptions or RadarAxisX2D.DateTimeScaleOptions property.
For time-span axes. Assign a ManualTimeSpanScaleOptions (or its descendant) object to the AxisX2D.TimeSpanScaleOptions, AxisX3D.TimeSpanScaleOptions or RadarAxisX2D.TimeSpanScaleOptions property.
For numeric axes. Assign a ManualNumericScaleOptions (or its descendant) object to the AxisX2D.NumericScaleOptions, AxisX3D.NumericScaleOptions or CircularAxisX2D.NumericScaleOptions property.

Qualitative

Chart aggregates point values if points have equal arguments.

For qualitative axes. Assign QualitativeScaleOptions to the AxisX2D.QualitativeScaleOptions or AxisX3D.QualitativeScaleOptions property.

Note

Axes that have the Continuous scale type (ContinuousDateTimeScaleOptions, ContinuousTimeSpanScaleOptions and ContinuousNumericScaleOptions) do not support aggregation.

Aggregate Date-Time Data

The following images show aggregated date-time data:

The examples below use an Average function to aggregate date-time data:

Automatic Mode

<dxc:XYDiagram2D>
    <dxc:XYDiagram2D.AxisX>
        <dxc:AxisX2D>
            <dxc:AxisX2D.DateTimeScaleOptions>
                <dxc:AutomaticDateTimeScaleOptions AggregateFunction="Average"/>
            </dxc:AxisX2D.DateTimeScaleOptions>                    
        </dxc:AxisX2D>
    </dxc:XYDiagram2D.AxisX>
    <!--...-->
</dxc:XYDiagram2D>

Manual Mode

<dxc:XYDiagram2D>
    <dxc:XYDiagram2D.AxisX>
        <dxc:AxisX2D>
            <dxc:AxisX2D.DateTimeScaleOptions>
                <dxc:ManualDateTimeScaleOptions AggregateFunction="Average" 
                                                MeasureUnit="Year" 
                                                GridAlignment="Year"/>      
            </dxc:AxisX2D.DateTimeScaleOptions>        
        </dxc:AxisX2D>
    </dxc:XYDiagram2D.AxisX>
    <!--...-->
</dxc:XYDiagram2D>

The examples above use the following API members:

Member Description
AxisX2D.DateTimeScaleOptions Provides access to the options that define the behavior of a date-time X-scale when its mode is manual, automatic or continuous.
AutomaticDateTimeScaleOptions Contains settings for a date-time axis data when its scale mode is automatic.
ManualDateTimeScaleOptions Contains settings for a date-time axis data when its scale mode is manual.

See also the following examples:

Form a Custom Measurement Unit

You can use the ManualDateTimeScaleOptions.MeasureUnit property with the ManualDateTimeScaleOptions.MeasureUnitMultiplier property to configure a custom measurement unit for time-span axes with a manual scale.

For instance, set the MeasureUnit to Month and the MeasureUnitMultiplier to 6 to specify a measurement unit of six months.

<dxc:XYDiagram2D>
    <dxc:XYDiagram2D.AxisX>
        <dxc:AxisX2D>
            <dxc:AxisX2D.DateTimeScaleOptions>
                <dxc:ManualDateTimeScaleOptions AggregateFunction="Average" 
                                                GridAlignment="Year" 
                                                MeasureUnit="Month" 
                                                MeasureUnitMultiplier="6"/>
            </dxc:AxisX2D.DateTimeScaleOptions>                    
        </dxc:AxisX2D>
    </dxc:XYDiagram2D.AxisX>
</dxc:XYDiagram2D>

Aggregate Time-Span Data

The following images show non-aggregated and aggregated time-span data:

The examples below use an Average function to aggregate time-span data:

Automatic Mode

<dxc:XYDiagram2D>
    <dxc:XYDiagram2D.AxisX>
        <dxc:AxisX2D>
            <dxc:AxisX2D.TimeSpanScaleOptions>
                <dxc:AutomaticTimeSpanScaleOptions AggregateFunction="Average"/>
            </dxc:AxisX2D.TimeSpanScaleOptions>                    
        </dxc:AxisX2D>
    </dxc:XYDiagram2D.AxisX>
</dxc:XYDiagram2D>

Manual Mode

<dxc:XYDiagram2D>    
    <dxc:XYDiagram2D.AxisX>
        <dxc:AxisX2D>
            <dxc:AxisX2D.TimeSpanScaleOptions>
                <dxc:ManualTimeSpanScaleOptions MeasureUnit="Hour" 
                                                AggregateFunction="Average"/>
            </dxc:AxisX2D.TimeSpanScaleOptions>                     
        </dxc:AxisX2D>
    </dxc:XYDiagram2D.AxisX>
</dxc:XYDiagram2D>    

The examples above use the following API members:

Member Description
AxisX2D.TimeSpanScaleOptions Gets or sets options of the time-span scale used by the argument axis.
AutomaticTimeSpanScaleOptions Contains scale settings for an axis when its scale mode is automatic.
ManualTimeSpanScaleOptions Contains settings for a time-span axis when its scale mode is manual. This scale mode allows you to specify a measurement unit.

Form a Custom Measurement Unit

You can use the ManualTimeSpanScaleOptions.MeasureUnit property with the ManualTimeSpanScaleOptions.MeasureUnitMultiplier property to configure a custom measurement unit for time-span axes with a manual scale.

For instance, set the MeasureUnit to Hour and the MeasureUnitMultiplier to 3 to specify a measurement unit of three hours.

<dxc:XYDiagram2D.AxisX>
    <dxc:AxisX2D GridLinesVisible="False">
        <dxc:AxisX2D.TimeSpanScaleOptions>
            <dxc:ManualTimeSpanScaleOptions AutoGrid="False" AggregateFunction="Average"
                                            MeasureUnit="Hour" MeasureUnitMultiplier="3"
                                            GridSpacing="3" GridAlignment="Hour"/>
        </dxc:AxisX2D.TimeSpanScaleOptions>
    </dxc:AxisX2D>
</dxc:XYDiagram2D.AxisX>

Aggregate Numeric Data

The following images show aggregated numeric data:

The examples below use an Average function to aggregate numeric data:

Automatic Mode

<dxc:XYDiagram2D>
    <dxc:XYDiagram2D.AxisX>
        <dxc:AxisX2D>
            <dxc:AxisX2D.NumericScaleOptions>
                <dxc:AutomaticNumericScaleOptions AggregateFunction="Average"/>
            </dxc:AxisX2D.NumericScaleOptions>
        </dxc:AxisX2D>
    </dxc:XYDiagram2D.AxisX>
</dxc:XYDiagram2D>

Manual Mode

<dxc:XYDiagram2D>
    <dxc:XYDiagram2D.AxisX>
        <dxc:AxisX2D>
            <dxc:AxisX2D.NumericScaleOptions>
                <dxc:ManualNumericScaleOptions AggregateFunction="Average" 
                                               MeasureUnit="1000"/>       
            </dxc:AxisX2D.NumericScaleOptions>
        </dxc:AxisX2D>
    </dxc:XYDiagram2D.AxisX>
</dxc:XYDiagram2D>

The examples above use the following API members:

Member Description
AxisX2D.NumericScaleOptions Provides access to the options that define the behavior of a numeric X-scale when its mode is manual, automatic or continuous.
AutomaticNumericScaleOptions Contains settings for a numeric axis data when its scale mode is automatic.
ManualNumericScaleOptions Contains settings for a numeric axis data when its scale mode is manual.

See also the following examples:

Aggregate Qualitative Data

The following images show non-aggregated and aggregated qualitative data:

The example below uses a Sum function to aggregate qualitative data:

<dxc:XYDiagram2D>
    <dxc:XYDiagram2D.AxisX>
        <dxc:AxisX2D>
            <dxc:AxisX2D.QualitativeScaleOptions>
                <dxc:QualitativeScaleOptions AggregateFunction="Sum"/>
            </dxc:AxisX2D.QualitativeScaleOptions>
        </dxc:AxisX2D>
    </dxc:XYDiagram2D.AxisX>   
</dxc:XYDiagram2D>

Aggregate an Individual Series’s Data

You can apply different aggregate functions to series that are bound to the same x-axis. In this case, the aggregate function applied to a series has higher priority than the axis’s aggregate function. To specify a series’s aggregate function, use the XYSeries.AggregateFunction property.

The following example uses the Financial function to aggregate the Stock series and the Sum function - the Bar series:

<dxc:XYDiagram2D>
    <dxc:StockSeries2D
        x:Name="stockSeries"
        DisplayName="Price"
        ArgumentDataMember="DateTimeStamp"
        OpenValueDataMember="Open"
        HighValueDataMember="High"
        LowValueDataMember="Low"
        CloseValueDataMember="Close"
        AggregateFunction="Financial">
    </dxc:StockSeries2D>
    <dxc:BarSideBySideSeries2D
        x:Name="volumeSeries"
        DisplayName="Volume"
        ArgumentDataMember="DateTimeStamp"
        ValueDataMember="Volume"
        AggregateFunction="Sum">
    </dxc:BarSideBySideSeries2D>
</dxc:XYDiagram2D>

Create a Custom Aggregate Function

The example below shows how to implement an aggregate function:

<dxc:XYDiagram2D>
    <dxc:XYDiagram2D.AxisX>
        <dxc:AxisX2D>
            <dxc:AxisX2D.DateTimeScaleOptions>
                <dxc:AutomaticDateTimeScaleOptions AggregateFunction="Custom">
                    <dxc:AutomaticDateTimeScaleOptions.CustomAggregateFunction>
                        <local:StandardDeviationAggregateFunction/>
                    </dxc:AutomaticDateTimeScaleOptions.CustomAggregateFunction>
                </dxc:AutomaticDateTimeScaleOptions>
            </dxc:AxisX2D.DateTimeScaleOptions>
            <!--...-->                      
        </dxc:AxisX2D>
    </dxc:XYDiagram2D.AxisX>
    <!--...-->
</dxc:XYDiagram2D>