Back to Devexpress

XRChart.CustomizePieTotalLabel Event

xtrareports-devexpress-dot-xtrareports-dot-ui-dot-xrchart-7c509c2b.md

latest6.0 KB
Original Source

XRChart.CustomizePieTotalLabel Event

Occurs before the pie total label is painted.

Namespace : DevExpress.XtraReports.UI

Assembly : DevExpress.XtraReports.v25.2.dll

NuGet Package : DevExpress.Reporting.Core

Declaration

csharp
public event CustomizePieTotalLabelEventHandler CustomizePieTotalLabel
vb
Public Event CustomizePieTotalLabel As CustomizePieTotalLabelEventHandler

Event Data

The CustomizePieTotalLabel event's data class is CustomizePieTotalLabelEventArgs. The following properties provide information specific to this event:

PropertyDescription
SeriesReturns a pie series whose total label is customized.
TextGets or sets the total label text.
TextColorGets or sets the total label’s text color.
TotalValueReturns the total label value.

Remarks

Handle this event to customize the text in the pie total label:

Tip

You can use this event to conditionally customize the pie chart total label’s text. See the code sample below for details.

Refer to the Total Labels topic for information on total labels.

Example

The code sample below creates a pie chart, shows total labels, and customizes the label text.

csharp
using DevExpress.XtraCharts;
// ...
using System.IO;
using System.Drawing;
using DevExpress.Data.Filtering;
using DevExpress.XtraPrinting;
// ...
// Create a chart instance.
XRChart chart = new XRChart();
// Create a chart parameter and bind it to the CategoryID field. Prepend the field name with the data member name.
chart.Parameters.Add(new XRControlParameter("ChartCategoryID", null, "Products.CategoryID"));
// Create a chart series that displays products prices.
Series series = new Series("Series1", ViewType.Pie);
series.ArgumentDataMember = "Products.ProductName";
series.ValueDataMembers.AddRange(new string[] { "Products.UnitPrice" });
// Display products from a specific category only.
series.FilterString = "Products.CategoryID = ?ChartCategoryID";
// Add the series to the chart.
chart.Series.Add(series);
// Make the total label visible.
((PieSeriesView)series.View).TotalLabel.Visible = true;
// Add the CustomizePieTotalLabel event handler.
chart.CustomizePieTotalLabel += chart_CustomizePieTotalLabel;
// ...
private void chart_CustomizePieTotalLabel(object sender, CustomizePieTotalLabelEventArgs e) {
    // Set the total label's text color to red.
    e.TextColor = Color.Red;
    // Apply the currency format to the label text.
    e.Text = string.Format("{0:c2}", e.TotalValue);
}
vb
Imports DevExpress.XtraCharts
' ...
Imports System.IO
Imports System.Drawing
Imports DevExpress.Data.Filtering
Imports DevExpress.XtraPrinting
' ...
' Create a chart instance.
Dim chart As New XRChart()
' Create a chart parameter and bind it to the CategoryID field. Prepend the field name with the data member name.
chart.Parameters.Add(New XRControlParameter("ChartCategoryID", Nothing, "Products.CategoryID"))
' Create a chart series that displays products prices.
Dim series As New Series("Series1", ViewType.Pie)
series.ArgumentDataMember = "Products.ProductName"
series.ValueDataMembers.AddRange(New String() { "Products.UnitPrice" })
' Display products from a specific category only.
series.FilterString = "Products.CategoryID = ?ChartCategoryID"
' Add the series to the chart.
chart.Series.Add(series)
' Make the total label visible.
CType(series.View, PieSeriesView).TotalLabel.Visible = True
' Add the CustomizePieTotalLabel event handler.
AddHandler chart.CustomizePieTotalLabel, AddressOf chart_CustomizePieTotalLabel
' ...
Private Sub chart_CustomizePieTotalLabel(ByVal sender As Object, ByVal e As CustomizePieTotalLabelEventArgs)
    ' Set the total label's text color to red.
    e.TextColor = Color.Red
    ' Apply the currency format to the label text.
    e.Text = String.Format("{0:c2}", e.TotalValue)
End Sub

See Also

XRChart Class

XRChart Members

DevExpress.XtraReports.UI Namespace