wpf-devexpress-dot-xpf-dot-charts-dot-manualtimespanscaleoptions-897bf165.md
Gets or sets the custom aggregate function callback that calculates the aggregated values.
Namespace : DevExpress.Xpf.Charts
Assembly : DevExpress.Xpf.Charts.v25.2.dll
NuGet Package : DevExpress.Wpf.Charts
[Browsable(false)]
public CustomAggregateFunction CustomAggregateFunction { get; set; }
<Browsable(False)>
Public Property CustomAggregateFunction As CustomAggregateFunction
| Type | Description |
|---|---|
| CustomAggregateFunction |
The custom aggregate function callback.
|
Do the following to create an aggregate function:
Set the AggregateFunction property to Custom.
Develop a class that inherits the CustomAggregateFunction class.
Override the CustomAggregateFunction.Calculate(GroupInfo) method.
Initialize the CustomAggregateFunction property with a newly created aggregate function class instance.
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:TimeSpanExample"
xmlns:dxc="http://schemas.devexpress.com/winfx/2008/xaml/charts"
x:Class="TimeSpanExample.MainWindow"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Window.DataContext>
<local:ChartViewModel/>
</Window.DataContext>
<Grid>
<dxc:ChartControl>
<dxc:XYDiagram2D>
<!-- Series settings are skipped. -->
<dxc:XYDiagram2D.AxisX>
<dxc:AxisX2D>
<dxc:AxisX2D.TimeSpanScaleOptions>
<dxc:ManualTimeSpanScaleOptions AggregateFunction="Custom">
<dxc:ManualTimeSpanScaleOptions.CustomAggregateFunction>
<local:StandardDeviationAggregateFunction/>
</dxc:ManualTimeSpanScaleOptions.CustomAggregateFunction>
</dxc:ManualTimeSpanScaleOptions>
</dxc:AxisX2D.TimeSpanScaleOptions>
</dxc:AxisX2D>
</dxc:XYDiagram2D.AxisX>
</dxc:XYDiagram2D>
</dxc:ChartControl>
</Grid>
</Window>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using DevExpress.Xpf.Charts;
namespace TimeSpanExample {
public class StandardDeviationAggregateFunction : CustomAggregateFunction {
public override string ToString() {
return "StdDev (Custom)";
}
public override double[] Calculate(GroupInfo groupInfo) {
double sum = 0.0;
foreach (double value in groupInfo.Values1) {
sum += value;
}
int len = groupInfo.Values1.Count();
double averageAmount = sum / len;
double standardDeviationSquareSum = 0.0;
foreach (double value in groupInfo.Values1) {
double deviation = value - averageAmount;
standardDeviationSquareSum += deviation * deviation;
}
double stdDev = Math.Sqrt(standardDeviationSquareSum / len);
return new double[1] { stdDev };
}
}
}
Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Windows
Imports DevExpress.Xpf.Charts
Namespace TimeSpanExample
Public Class StandardDeviationAggregateFunction
Inherits CustomAggregateFunction
Public Overrides Function ToString() As String
Return "StdDev (Custom)"
End Function
Public Overrides Function Calculate(ByVal groupInfo As GroupInfo) As Double()
Dim sum As Double = 0.0
For Each value As Double In groupInfo.Values1
sum += value
Next
Dim len As Integer = groupInfo.Values1.Count()
Dim averageAmount As Double = sum / len
Dim standardDeviationSquareSum As Double = 0.0
For Each value As Double In groupInfo.Values1
Dim deviation As Double = value - averageAmount
standardDeviationSquareSum += deviation * deviation
Next
Dim stdDev As Double = Math.Sqrt(standardDeviationSquareSum / len)
Return New Double(0) {stdDev}
End Function
End Class
End Namespace
See Also
ManualTimeSpanScaleOptions Class