aspnet-devexpress-dot-xtracharts-dot-web-dot-webchartcontrol-bb39288c.md
Occurs when the WebChartControl draws total labels for pie and donut series.
Namespace : DevExpress.XtraCharts.Web
Assembly : DevExpress.XtraCharts.v25.2.Web.dll
NuGet Package : DevExpress.Web.Visualization
public event CustomizePieTotalLabelEventHandler CustomizePieTotalLabel
Public Event CustomizePieTotalLabel As CustomizePieTotalLabelEventHandler
The CustomizePieTotalLabel event's data class is CustomizePieTotalLabelEventArgs. The following properties provide information specific to this event:
| Property | Description |
|---|---|
| Series | Returns a pie series whose total label is customized. |
| Text | Gets or sets the total label text. |
| TextColor | Gets or sets the total label’s text color. |
| TotalValue | Returns the total label value. |
This example shows how to format the Doughnut series total label text depending on the total value of the pie slice:
using DevExpress.Utils;
using DevExpress.XtraCharts;
using DevExpress.XtraCharts.Web;
using System;
using System.Collections.Generic;
namespace PieChartSample {
public partial class WebForm1 : System.Web.UI.Page {
protected void Page_Load(object sender, EventArgs e) {
WebChartControl chart = new WebChartControl();
chart.ID = "WebChart";
chart.RenderFormat = RenderFormat.Svg;
chart.Height = 400;
chart.Width = 400;
this.Controls.Add(chart);
Series series = new Series("Donut", ViewType.Doughnut);
series.DataSource = DataPoint.GetDataPoints();
series.SetDataMembers("Argument", "Value");
series.LabelsVisibility = DefaultBoolean.False;
chart.Series.Add(series);
PieSeriesView seriesView = (PieSeriesView)series.View;
seriesView.TotalLabel.Visible = true;
chart.CustomizePieTotalLabel += Chart_CustomizePieTotalLabel;
}
private void Chart_CustomizePieTotalLabel(object sender, CustomizePieTotalLabelEventArgs e) {
if (e.TotalValue > 1000) {
e.TextColor = System.Drawing.Color.Green;
e.Text = $"Total value:{Environment.NewLine}{Math.Round(e.TotalValue / 1000, 2)}K";
}
}
}
public class DataPoint {
public string Argument { get; set; }
public double Value { get; set; }
public static List<DataPoint> GetDataPoints() {
return new List<DataPoint> {
new DataPoint { Argument = "Russia", Value = 225.12},
new DataPoint { Argument = "Canada", Value = 148.456},
new DataPoint { Argument = "USA", Value = 211.78},
new DataPoint { Argument = "China", Value = 322.123},
new DataPoint { Argument = "Brazil", Value = 99.511965},
new DataPoint { Argument = "Australia", Value = 183.68685},
new DataPoint { Argument = "India", Value = 169.28759}
};
}
}
}
Imports DevExpress.Utils
Imports DevExpress.XtraCharts
Imports DevExpress.XtraCharts.Web
Imports System
Imports System.Collections.Generic
Namespace PieChartSample
Public Partial Class WebForm1
Inherits Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
Dim chart As WebChartControl = New WebChartControl()
chart.ID = "WebChart"
chart.RenderFormat = RenderFormat.Svg
chart.Height = 400
chart.Width = 400
Me.Controls.Add(chart)
Dim series As Series = New Series("Donut", ViewType.Doughnut)
series.DataSource = DataPoint.GetDataPoints()
series.SetDataMembers("Argument", "Value")
series.LabelsVisibility = DefaultBoolean.[False]
chart.Series.Add(series)
Dim seriesView As PieSeriesView = CType(series.View, PieSeriesView)
seriesView.TotalLabel.Visible = True
chart.CustomizePieTotalLabel += AddressOf Chart_CustomizePieTotalLabel
End Sub
Private Sub Chart_CustomizePieTotalLabel(ByVal sender As Object, ByVal e As CustomizePieTotalLabelEventArgs)
If e.TotalValue > 1000 Then
e.TextColor = Drawing.Color.Green
e.Text = $"Total value:{Environment.NewLine}{Math.Round(e.TotalValue / 1000, 2)}K"
End If
End Sub
End Class
Public Class DataPoint
Public Property Argument As String
Public Property Value As Double
Public Shared Function GetDataPoints() As List(Of DataPoint)
Return New List(Of DataPoint) From {
New DataPoint With {
.Argument = "Russia",
.Value = 225.12
},
New DataPoint With {
.Argument = "Canada",
.Value = 148.456
},
New DataPoint With {
.Argument = "USA",
.Value = 211.78
},
New DataPoint With {
.Argument = "China",
.Value = 322.123
},
New DataPoint With {
.Argument = "Brazil",
.Value = 99.511965
},
New DataPoint With {
.Argument = "Australia",
.Value = 183.68685
},
New DataPoint With {
.Argument = "India",
.Value = 169.28759
}
}
End Function
End Class
End Namespace
See Also