Skip to main content

SeriesLabel.TextProvider Property

Gets or sets a rule used to generate custom text strings for series labels. This is a bindable property.

Namespace: DevExpress.Maui.Charts

Assembly: DevExpress.Maui.Charts.dll

NuGet Package: DevExpress.Maui.Charts

Declaration

public ISeriesLabelTextProvider TextProvider { get; set; }

Property Value

Type Description
ISeriesLabelTextProvider

An instance of a class that implements the ISeriesLabelTextProvider interface.

Example

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:

  • 1234 -> $1.234K
  • 123456789 -> $123.457M
  • 12345678901 -> $12.346B

PieSeriesLabelValues

  1. Create a class (LabelTextProvider) that implements the ISeriesLabelTextProvider interface.
  2. Implement the 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.
  3. Assign a LabelTextProvider object to the PieSeriesLabel.TextProvider property.
<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