maui-devexpress-dot-maui-dot-charts-dot-iserieslabeltextprovider-dot-gettext-x28-devexpress-dot-maui-dot-charts-dot-serieslabelvaluesbase-x29.md
Returns a string that a series label displays.
Namespace : DevExpress.Maui.Charts
Assembly : DevExpress.Maui.Charts.dll
NuGet Package : DevExpress.Maui.Charts
string GetText(
SeriesLabelValuesBase values
)
| Name | Type | Description |
|---|---|---|
| values | SeriesLabelValuesBase |
The SeriesLabelValuesBase class descendant object.
|
| Type | Description |
|---|---|
| String |
A series label text.
|
The GetText method’s argument type depends on the type of the series for which the method is called:
|
Series Type
|
GetText Argument Type
| | --- | --- | |
|
| |
Area, Bar, Line, Spline, Point, and Bubble
|
| |
Candlestick and Stock
|
| |
|
|
This example shows how to configure the pie series so that its labels display point values as thousands, millions or billions of dollars in the following way:
GetText method that returns a string for each label instance. A PieSeriesLabelValues object is an argument of this method when it is called for a pie series. Use the PieSeriesLabelValues.Value property to access series point values.<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:dxc="clr-namespace:DevExpress.Maui.Charts;assembly=DevExpress.Maui.Charts"
x:Class="SeriesLabelTextProviderExample.MainPage">
<dxc:PieChartView x:Name="chart" />
</ContentPage>
using System;
using Microsoft.Maui.Graphics;
using System.Globalization;
using System.Collections.Generic;
using DevExpress.Maui.Charts;
namespace SeriesLabelTextProviderExample {
public partial class MainPage : ContentPage {
public MainPage() {
InitializeComponent();
PieChartView pieChart = chart;
PieSeries pieSeries = new PieSeries() {
Data = new PieSeriesDataAdapter() {
LabelDataMember = "Label",
ValueDataMember = "Value",
DataSource = new List<DataItem>() {
new DataItem() { Label = "AAA", Value = 1230000 },
new DataItem() { Label = "BBB", Value = 3330000 },
new DataItem() { Label = "CCC", Value = 2100000 },
}
},
Label = new PieSeriesLabel() {
Position = PieSeriesLabelPosition.Inside,
TextProvider = new LabelTextProvider(),
Style = new PieSeriesLabelStyle(){
TextStyle = new TextStyle(){
Size = 18
}
}
}
};
pieChart.Series.Add(pieSeries);
}
}
public class LabelTextProvider : ISeriesLabelTextProvider {
string ISeriesLabelTextProvider.GetText(SeriesLabelValuesBase values) {
if (values is PieSeriesLabelValues seriesValues) {
double v = seriesValues.Value;
if (v >= 1000000000 || v <= -1000000000)
return (v / 1000000000.0).ToString("$#.###B", CultureInfo.InvariantCulture);
else if (v >= 1000000 || v <= -1000000)
return (v / 1000000.0).ToString("$#.###M", CultureInfo.InvariantCulture);
else if (v >= 1000 || v <= -1000)
return (v / 1000.0).ToString("$#.###K", CultureInfo.InvariantCulture);
else
return v.ToString();
}
return String.Empty;
}
}
public class DataItem {
public string Label { get; set; }
public double Value { get; set; }
}
}
See Also
ISeriesLabelTextProvider Interface