XRChart.RegisterSummaryFunction(String, String, Int32, SummaryFunctionArgumentDescription[], SummaryFunction) Method
OBSOLETE
This method is obsolete now. Use the static RegisterGlobalSummaryFunction method instead.
Registers the custom summary function with the specified settings.
Namespace: DevExpress.XtraReports.UI
Assembly:
DevExpress.XtraReports.v24.1.dll
NuGet Package:
DevExpress.Reporting.Core
Declaration
[Obsolete("This method is obsolete now. Use the static RegisterGlobalSummaryFunction method instead.", false)]
public void RegisterSummaryFunction(
string name,
string displayName,
int resultDimension,
SummaryFunctionArgumentDescription[] argumentDescriptions,
SummaryFunction function
)
<Obsolete("This method is obsolete now. Use the static RegisterGlobalSummaryFunction method instead.", False)>
Public Sub RegisterSummaryFunction(
name As String,
displayName As String,
resultDimension As Integer,
argumentDescriptions As SummaryFunctionArgumentDescription(),
function As SummaryFunction
)
Parameters
The RegisterSummaryFunction method is intended to register custom summary functions within a chart control. To unregister a specific summary function, the XRChart.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 XRChart.ResetSummaryFunctions method.
Example
The following example demonstrates how to create a custom summary function, which returns a product of two values (Price * Count). To accomplish this task, it is required to create a summary function delegate and register it via the ChartControl.RegisterSummaryFunction method.
The code below illustrates how this can be done.
Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Threading.Tasks
Imports System.Windows.Forms
Namespace RegisterSummaryFunctionExample
Friend NotInheritable Class Program
Private Sub New()
End Sub
''' <summary>
''' The main entry point for the application.
''' </summary>
<STAThread> _
Shared Sub Main()
Application.EnableVisualStyles()
Application.SetCompatibleTextRenderingDefault(False)
Application.Run(New Form1())
End Sub
End Class
End Namespace
Imports System
Imports System.Collections.Generic
Imports System.Text
Imports System.Windows.Forms
Imports DevExpress.XtraCharts
Namespace RegisterSummaryFunctionExample
Partial Public Class Form1
Inherits Form
Private Const summaryFunctionName As String = "PRODUCT"
' Declare the Product 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()
' Create an array of the resulting series points.
Dim points As New List(Of SeriesPoint)()
' Calculate the resulting series points as Price * Count.
For i As Integer = 0 To values.Length - 1
Dim value As Double = Convert.ToDouble(values(i)(functionArguments(0))) * Convert.ToDouble(values(i)(functionArguments(1)))
If value > 0 Then
points.Add(New SeriesPoint(argument, value))
End If
Next i
' Return the result.
Return points.ToArray()
End Function
Public Sub New()
InitializeComponent()
' This line of code is generated by Data Source Configuration Wizard
productsTableAdapter1.Fill(nwindDataSet1.Products)
End Sub
Private Function BuildSummaryFunction(ByVal price As String, ByVal count As String) As String
Return (New StringBuilder(summaryFunctionName)).Append("([").Append(price).Append("],[").Append(count).Append("])").ToString()
End Function
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
' Register the summary function in a chart.
chartControl1.RegisterSummaryFunction("PRODUCT", "PRODUCT", 1, New SummaryFunctionArgumentDescription() { _
New SummaryFunctionArgumentDescription("Price", ScaleType.Numerical), _
New SummaryFunctionArgumentDescription("Count", ScaleType.Numerical) _
}, AddressOf CalculateProductValue)
Dim series As Series = chartControl1.Series("Product")
series.SummaryFunction = BuildSummaryFunction("UnitPrice", "UnitsOnOrder")
End Sub
End Class
End Namespace
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace RegisterSummaryFunctionExample {
static class Program {
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main() {
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraCharts;
namespace RegisterSummaryFunctionExample {
public partial class Form1 : Form {
const string summaryFunctionName = "PRODUCT";
// Declare the Product summary function.
private static SeriesPoint[] CalculateProductValue(
Series series,
object argument,
string[] functionArguments,
DataSourceValues[] values,
object[] colors) {
// Create an array of the resulting series points.
List<SeriesPoint> points = new List<SeriesPoint>();
// Calculate the resulting series points as Price * Count.
for (int i = 0; i < values.Length; i++) {
double value = Convert.ToDouble(values[i][functionArguments[0]]) *
Convert.ToDouble(values[i][functionArguments[1]]);
if (value > 0)
points.Add(new SeriesPoint(argument, value));
}
// Return the result.
return points.ToArray();
}
public Form1() {
InitializeComponent();
// This line of code is generated by Data Source Configuration Wizard
productsTableAdapter1.Fill(nwindDataSet1.Products);
}
String BuildSummaryFunction(String price, String count) {
return
new StringBuilder(summaryFunctionName)
.Append("([")
.Append(price)
.Append("],[")
.Append(count)
.Append("])")
.ToString();
}
private void Form1_Load(object sender, EventArgs e) {
// Register the summary function in a chart.
chartControl1.RegisterSummaryFunction("PRODUCT", "PRODUCT", 1,
new SummaryFunctionArgumentDescription[] {
new SummaryFunctionArgumentDescription("Price", ScaleType.Numerical),
new SummaryFunctionArgumentDescription("Count", ScaleType.Numerical)},
CalculateProductValue);
Series series = chartControl1.Series["Product"];
series.SummaryFunction = BuildSummaryFunction("UnitPrice", "UnitsOnOrder");
}
}
}
See Also