Back to Devexpress

ChartControl.RegisterSummaryFunction(String, String, Int32, SummaryFunctionArgumentDescription[], SummaryFunction) Method

windowsforms-devexpress-dot-xtracharts-dot-chartcontrol-dot-registersummaryfunction-x28-string-string-int32-summaryfunctionargumentdescription-summaryfunction-x29.md

latest9.4 KB
Original Source

ChartControl.RegisterSummaryFunction(String, String, Int32, SummaryFunctionArgumentDescription[], SummaryFunction) Method

Registers the custom summary function with the specified settings.

Namespace : DevExpress.XtraCharts

Assembly : DevExpress.XtraCharts.v25.2.UI.dll

NuGet Package : DevExpress.Win.Charts

Declaration

csharp
public void RegisterSummaryFunction(
    string name,
    string displayName,
    int resultDimension,
    SummaryFunctionArgumentDescription[] argumentDescriptions,
    SummaryFunction function
)
vb
Public Sub RegisterSummaryFunction(
    name As String,
    displayName As String,
    resultDimension As Integer,
    argumentDescriptions As SummaryFunctionArgumentDescription(),
    function As SummaryFunction
)

Parameters

NameTypeDescription
nameString

A String value containing the function’s name.

| | displayName | String |

A String value containing the function’s display name, which is used for localization purposes.

| | resultDimension | Int32 |

An integer value representing the dimension of the resulting series point’s values.

| | argumentDescriptions | SummaryFunctionArgumentDescription[] |

An array of SummaryFunctionArgumentDescription objects containing argument descriptions.

| | function | SummaryFunction |

A SummaryFunction delegate to be registered.

|

Remarks

The RegisterSummaryFunction method is intended to register custom summary functions within a chart control. To unregister a specific summary function, the ChartControl.UnregisterSummaryFunction method should be called. Also, you may remove all custom summary functions from the chart, and add all default functions to it by calling the ChartControl.ResetSummaryFunctions method.

Example

The following example demonstrates how to create a custom summary function, which returns an OHLC point calculated by the passed array of values. To accomplish this task, create a SummaryFunction delegate and register it using the ChartControl.RegisterSummaryFunction method:

csharp
// Declare the Financial summary function. 
private static SeriesPoint[] CalculateProductValue( 
        Series series, 
        object argument, 
        string[] functionArguments, 
        DataSourceValues[] values, 
        object[] colors
) { 
    string functionArgument = functionArguments[0]; 
    int lastIndex = values.Length - 1; 

    double open = Convert.ToDouble(values[0][functionArgument], CultureInfo.InvariantCulture); 
    double close = Convert.ToDouble(values[lastIndex][functionArgument], CultureInfo.InvariantCulture); 
    double high = Math.Max(open, close); 
    double low = Math.Min(open, close); 
    for (int i = 1; i < lastIndex; i++) { 
        high = Math.Max(high, Convert.ToDouble(values[i][functionArgument], CultureInfo.InvariantCulture)); 
        low = Math.Min(low, Convert.ToDouble(values[i][functionArgument], CultureInfo.InvariantCulture)); 
    } 
    // Return the result. 
    return new SeriesPoint[] { 
        new SeriesPoint(argument, high, low, open, close) 
    }; 
} 

private void Form1_Load(object sender, EventArgs e) { 
    chartControl.DataSource = new CurrencyRateLoader("../../Data/EurUsdRate.xml").Load();
    // Register the summary function in a chart. 
    chartControl.RegisterSummaryFunction( 
            name: "FINANCIAL", 
            displayName: "Financial", 
            resultScaleType: ScaleType.Numerical, 
            resultDimension: 4, 
            argumentDescriptions: new SummaryFunctionArgumentDescription[] { 
                new SummaryFunctionArgumentDescription("Value", ScaleType.Numerical) 
            }, 
            function: CalculateProductValue
    );

    Series series = chartControl.Series["EurUsd"]; 
    series.ArgumentDataMember = "DateTime";
    // Note that ValueDataMembers are not specified.
    series.DateTimeSummaryOptions.SummaryFunction = "FINANCIAL([Value])"; 
}
vb
' Declare the Financial summary function.
Private Shared Function CalculateProductValue(
        ByVal series As Series, 
        ByVal argument As Object, 
        ByVal functionArguments() As String, 
        ByVal values() As DataSourceValues, 
        ByVal colors() As Object
) As SeriesPoint()
    Dim functionArgument As String = functionArguments(0)
    Dim lastIndex As Integer = values.Length - 1

    Dim openValue As Double = Convert.ToDouble(values(0)(functionArgument), CultureInfo.InvariantCulture)
    Dim closeValue As Double = Convert.ToDouble(values(lastIndex)(functionArgument), CultureInfo.InvariantCulture)
    Dim highValue As Double = Math.Max(openValue, closeValue)
    Dim lowValue As Double = Math.Min(openValue, closeValue)
    For i As Integer = 1 To lastIndex - 1
        highValue = Math.Max(highValue, Convert.ToDouble(values(i)(functionArgument), CultureInfo.InvariantCulture))
        lowValue = Math.Min(lowValue, Convert.ToDouble(values(i)(functionArgument), CultureInfo.InvariantCulture))
    Next i
    ' Return the result.
    Return New SeriesPoint() { 
        New SeriesPoint(argument, high, low, open, close_Renamed) 
    }
End Function

Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
    chartControl.DataSource = (New CurrencyRateLoader("../../Data/EurUsdRate.xml")).Load()
    ' Register the summary function in a chart.
    chartControl.RegisterSummaryFunction(
            name:= "FINANCIAL", 
            displayName:= "Financial", 
            resultScaleType:= ScaleType.Numerical, 
            resultDimension:= 4, 
            argumentDescriptions:= New SummaryFunctionArgumentDescription() { 
                New SummaryFunctionArgumentDescription("Value", ScaleType.Numerical) 
            }, 
            [function]:= AddressOf CalculateProductValue
    )

    Dim series As Series = chartControl.Series("EurUsd")
    series.ArgumentDataMember = "DateTime"
    ' Note that ValueDataMembers are not specified.
    series.DateTimeSummaryOptions.SummaryFunction = "FINANCIAL([Value])"
End Sub

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the RegisterSummaryFunction(String, String, Int32, SummaryFunctionArgumentDescription[], SummaryFunction) method.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

winforms-charts-apply-the-best-fit-function-to-a-series/CS/LineOfBestFit/Form1.cs#L80

csharp
InitializeComponent();
chartControl1.RegisterSummaryFunction("BESTFIT", "BESTFIT", 1, null, GetPointForLinearRegression);
DataSet ds = new DataSet();

winforms-charts-apply-the-best-fit-function-to-a-series/VB/LineOfBestFit/Form1.vb#L70

vb
InitializeComponent()
chartControl1.RegisterSummaryFunction("BESTFIT", "BESTFIT", 1, Nothing, New SummaryFunction(AddressOf GetPointForLinearRegression))
Dim ds As DataSet = New DataSet()

See Also

UnregisterSummaryFunction(String)

ResetSummaryFunctions()

ChartControl Class

ChartControl Members

DevExpress.XtraCharts Namespace