corelibraries-devexpress-dot-xtracharts-46b3fed6.md
The base class for a custom aggregate function callback.
Namespace : DevExpress.XtraCharts
Assembly : DevExpress.XtraCharts.v25.2.dll
NuGet Package : DevExpress.Charts
public abstract class CustomAggregateFunction :
ICustomAggregateFunction
Public MustInherit Class CustomAggregateFunction
Implements ICustomAggregateFunction
The following members return CustomAggregateFunction objects:
Follow the steps below to create an aggregate function.
Create a class that inherits the CustomAggregateFunction class.
Implement its CustomAggregateFunction.Calculate method that then is called for each unique argument. Its groupInfo parameter is an object of the GroupInfo class and contains information about the argument and corresponding values:
Initialize the ScaleGridOptionsBase.CustomAggregateFunction property with an object of the newly created class.
Set the ScaleGridOptionsBase.AggregateFunction property to Custom.
private void Form1_Load(object sender, EventArgs e) {
Series series = chartControl.Series["Random Data"];
series.DataSource = GenerateData(100_000);
series.ArgumentDataMember = "Argument";
series.ValueDataMembers.AddRange("Value", "Value", "Value", "Value");
XYDiagram diagram = chartControl.Diagram as XYDiagram;
diagram.AxisX.DateTimeScaleOptions.AggregateFunction = AggregateFunction.Custom;
diagram.AxisX.DateTimeScaleOptions.CustomAggregateFunction = new OhlcAggregateFunction();
}
class OhlcAggregateFunction : CustomAggregateFunction {
public override double[] Calculate(GroupInfo groupInfo) {
double open = groupInfo.Values1.First();
double close = groupInfo.Values1.Last();
double high = Double.MinValue;
double low = Double.MaxValue;
foreach (double value in groupInfo.Values1) {
if (high < value) high = value;
if (low > value) low = value;
}
return new double[] { high, low, open, close };
}
}
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
Dim series As Series = chartControl.Series("Random Data")
series.DataSource = GenerateData(100_000)
series.ArgumentDataMember = "Argument"
series.ValueDataMembers.AddRange("Value", "Value", "Value", "Value")
Dim diagram As XYDiagram = TryCast(chartControl.Diagram, XYDiagram)
diagram.AxisX.DateTimeScaleOptions.AggregateFunction = AggregateFunction.Custom
diagram.AxisX.DateTimeScaleOptions.CustomAggregateFunction = New OhlcAggregateFunction()
End Sub
Private Class OhlcAggregateFunction
Inherits CustomAggregateFunction
Public Overrides Function Calculate(ByVal groupInfo As GroupInfo) As Double()
Dim open As Double = groupInfo.Values1.First()
Dim close As Double = groupInfo.Values1.Last()
Dim high As Double = Double.MinValue
Dim low As Double = Double.MaxValue
For Each value As Double In groupInfo.Values1
If high < value Then
high = value
End If
If low > value Then
low = value
End If
Next value
Return New Double() { high, low, open, close }
End Function
End Class
Object CustomAggregateFunction
See Also