Skip to main content

Data Aggregation

  • 6 minutes to read

Data Aggregation groups raw data points into points with a larger argument measurement unit. For example, if data point arguments are measured in minutes, data aggregation can create points measured in hours or days - to display fewer points.

NonAggregatedChart

When data aggregation is enabled, the X-axis splits its range into intervals and the aggregate function automatically aggregates data for each interval. For example, the image above uses the Average aggregate function to aggregate chart data by Years.

Important

Data aggregation is available for the argument axis (X-axis) only.

Data aggregation is available depending on the X-Axis’s scale type and scale mode (ScaleOptionsBase.ScaleMode). The X-axis can use one of the following modes for date-time and numeric scales to aggregate data:

Mode Description
ScaleMode.Automatic The chart control automatically defines the most optimal measurement unit for an axis based on the data set’s values, and the Chart Control’s current size and zoom level. The ScaleGridOptionsBase.AggregateFunction property specifies the current aggregate function.
ScaleMode.Manual Use the DateTimeScaleOptions.MeasureUnit and DateTimeScaleOptions.MeasureUnitMultiplier properties to specify the measurement unit manually for the date-time axis, TimeSpanScaleOptions.MeasureUnit and TimeSpanScaleOptions.MeasureUnitMultiplier for the time-span axis, and NumericScaleOptions.MeasureUnit or NumericScaleOptions.CustomMeasureUnit for the numeric axis.
ScaleMode.Continuous Data aggregation is disabled for numeric, date-time, and time-span scales. This means an axis scale is not divided into intervals.

Use the following code to specify the X-axis’s mode:

XYDiagram diagram = webChartControl1.Diagram as XYDiagram;
// For qualitative data:
diagram.AxisX.QualitativeScaleOptions.AggregateFunction = AggregateFunction.Sum;
// For numeric data:
diagram.AxisX.NumericScaleOptions.ScaleMode = ScaleMode.Manual;
diagram.AxisX.NumericScaleOptions.MeasureUnit = DateTimeMeasureUnit.Thousands;
// For date-time data:
diagram.AxisX.DateTimeScaleOptions.ScaleMode = ScaleMode.Manual;
diagram.AxisX.DateTimeScaleOptions.MeasureUnit = DateTimeMeasureUnit.Minute;
diagram.AxisX.DateTimeScaleOptions.MeasureUnitMultiplier = 15;
// For time-span data:
diagram.AxisX.TimeSpanScaleOptions.ScaleMode = ScaleMode.Manual;
diagram.AxisX.TimeSpanScaleOptions.MeasureUnit = TimeSpanMeasureUnit.Minute;
diagram.AxisX.TimeSpanScaleOptions.MeasureUnitMultiplier = 5;

The following properties and types configure the axis scale parameters:

Property Description
AxisXBase.QualitativeScaleOptions Provides access to the options that define the behavior of a scale when its type is qualitative.
QualitativeScaleOptions Contains settings for an axis scale when its data type is qualitative.
AxisBase.NumericScaleOptions Stores the options that define the behavior of a scale when its type is numeric.
NumericScaleOptions Contains settings for an axis scale when its data type is numeric.
AxisBase.DateTimeScaleOptions Stores the options that define the behavior of a scale when its type is date-time.
DateTimeScaleOptions Contains settings for an axis scale when its data type is date-time.
AxisBase.TimeSpanScaleOptions Stores the settings of a scale when its type is time-span.
TimeSpanScaleOptions Settings of a scale when its type is time-span.

The sections below describe the following aggregation features in detail:

Aggregate Function

The ScaleGridOptionsBase.AggregateFunction property (available in ScaleMode.Automatic and ScaleMode.Manual scale modes) specifies a function that aggregates data at each interval on the X-axis. The AggregateFunction enumeration lists all available aggregate functions and the AggregateFunction property uses the enumeration’s AggregateFunction.Average value by default.

The following table uses the AggregateFunction.Minimum and AggregateFunction.Sum functions in ScaleMode.Automatic scale mode to display aggregate data.

ScaleGridOptionsBase.AggregateFunction = AggregateFunction.Minimum ScaleGridOptionsBase.AggregateFunction = AggregateFunction.Sum
Auto_AverageAggregation Auto_SumAggregation

To use a custom aggregate function, set the CustomAggregateFunction class descendant object to the ScaleGridOptionsBase.CustomAggregateFunction property. Note that the ScaleGridOptionsBase.AggregateFunction property should be set to Custom.

Use the WebChartControl.AxisScaleChanged event to obtain the axis‘ automatically calculated grid alignment and measurement unit values, when the scale mode is automatic. The event arguments contain the Axis object for which the event is raised. This event is raised when the scale mode, measure unit, grid alignment or grid spacing of the axis scale has been changed.

private void Page_Load(object sender, EventArgs e) {
    webChartControl1.AxisScaleChanged += OnChartAxisScaleChanged;
}

private void OnChartAxisScaleChanged(object sender, AxisScaleChangedEventArgs e) {
    AxisX axisX = e.Axis as AxisX;
    if (axisX == null) return;
    // In this event, you can access the properties of the corresponding axis, and
    // obtain the automatically calculated value for the axis date-time grid alignment and measure unit.
    axisX.Title.Visibility = DefaultBoolean.True;
    axisX.Title.Text = String.Format(
        "The Axis Grid Alignment Unit is {0} \r\nThe Axis Measure Unit is {1}", 
        e.Axis.DateTimeScaleOptions.GridAlignment.ToString(),
        e.Axis.DateTimeScaleOptions.MeasureUnit.ToString()
    );
}

When the AggregateFunction property is set to None, all series are grouped against point arguments and neither aggregate function is applied to data. This means that all points that have the same argument overlap each other. Set the ScaleOptionsBase.ScaleMode property to Continuous to disable aggregation.

Important

When a series uses a summary function, the X-axis cannot apply an aggregate function to data.

Qualitative Data Aggregation

The Chart Control aggregates qualitative data as follows: if multiple data rows have the same argument value, they are aggregated. The Chart Control does not aggregate qualitative data by default because the aggregate function is set to None. The following table contains disabled and enabled aggregation samples:

AxisX.QualitativeScaleOptions.AggregateFunction = AggregateFunction.None; AxisX.QualitativeScaleOptions.AggregateFunction = AggregateFunction.Average;
data-aggregation__qualitative-none data-aggregation__qualitative-avg

Numeric Data Aggregation

The Chart Control does not aggregate numeric data by default because the numeric scale mode is set to ScaleMode.Continuous:

Non-AggregatedNumericScale

The NumericMeasureUnit enumeration lists the values that the NumericScaleOptions.MeasureUnit property uses in the ScaleMode.Manual scale mode. The following table shows the difference between the predefined Hundreds and Thousands measurement units:

NumericScaleOptions.MeasureUnit = NumericMeasureUnit.Hundreds NumericScaleOptions.MeasureUnit = NumericMeasureUnit.Thousands
NumericAggregation_Hundreds NumericAggregation_Thousands

If predefined measurement units are not applicable to the specified data source, use the NumericScaleOptions.CustomMeasureUnit property to specify a custom numeric measurement unit.

Date-time Data Aggregation

Data aggregation is available for the X-axis by default because the date-time ScaleOptionsBase.ScaleMode property is set to ScaleMode.Manual. In this mode, the DateTimeScaleOptions.GridAlignment and DateTimeScaleOptions.MeasureUnit properties that define the Chart control’s grid appearance are available. The DateTimeScaleOptions.MeasureUnit property also configures the default text format for axis labels:

DefaultDateTimeAggregation

The DateTimeScaleOptions.MeasureUnit and DateTimeScaleOptions.MeasureUnitMultiplier properties determine the detail level for date-time values in the Manual scale mode. The DateTimeMeasureUnit enumeration stores predefined measurement units. The following table shows data aggregated by DateTimeMeasureUnit.Quarter and DateTimeMeasureUnit.Year.

DateTimeScaleOptions.MeasureUnit = DateTimeMeasureUnit.Quarter DateTimeScaleOptions.MeasureUnit = DateTimeMeasureUnit.Year
MeasureUnit_Quarter MeasureUnit_Year
See Also