Back to Devexpress

ChartSeriesPointCustomizationSettings.PointLabel Property

blazor-devexpress-dot-blazor-dot-chartseriespointcustomizationsettings-efb758a2.md

latest4.2 KB
Original Source

ChartSeriesPointCustomizationSettings.PointLabel Property

Provides access to the point’s label settings.

Namespace : DevExpress.Blazor

Assembly : DevExpress.Blazor.v25.2.dll

NuGet Package : DevExpress.Blazor

Declaration

csharp
public IChartSeriesLabel PointLabel { get; }

Property Value

TypeDescription
IChartSeriesLabel

The point label.

|

Remarks

Use this property in the CustomizeSeriesPoint event handler to specify the label color, position, and visibility.

To define appearance settings that apply to all the labels in a series, use the DxChartSeriesLabel component.

Tip

Individual label settings have a priority over the common label settings.

The following example demonstrates how to:

razor
@inject WeatherForecastService ForecastService

<DxChart Data="@ChartData" CustomizeSeriesPoint="@PreparePointLabel">
    <DxChartLineSeries SummaryMethod="@(i => (int)i.Average())"
                       ValueField="@((WeatherForecast i) => i.TemperatureF)"
                       ArgumentField="@(i => i.Date.Date)"
                       Name="Temperature, F">
        <DxChartSeriesLabel Position="RelativePosition.Outside">
            <DxChartSeriesLabelConnector Visible="true" Width="3" />
        </DxChartSeriesLabel>
    </DxChartLineSeries>
</DxChart>

@code {
    WeatherForecast[] ChartData;

    protected override async Task OnInitializedAsync() {
        ChartData = await ForecastService.GetForecastAsync();
    }

    protected void PreparePointLabel(ChartSeriesPointCustomizationSettings pointSettings) {
        double value = (double)pointSettings.Point.Value;
        if (value > 25 && value < 75)
            pointSettings.PointLabel.Visible = true;
    }
}
csharp
using System;

public class WeatherForecast {
    public DateTime Date { get; set; }
    public int TemperatureC { get; set; }
    public double TemperatureF => Math.Round((TemperatureC * 1.8 + 32), 2);
    public double Precipitation { get; set; }
}
csharp
using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Threading;
    using System.Threading.Tasks;

    public class WeatherForecastService {
    // ...
        private List<WeatherForecast> Forecast { get; set; }

        public WeatherForecastService() {
        // ...
            Forecast = CreateForecast();
        }

// ...
        private List<WeatherForecast> CreateForecast() {
            var rng = new Random();
            DateTime startDate = DateTime.Now;
            return Enumerable.Range(1, 15).Select(index => new WeatherForecast {
                Date = startDate.AddDays(index),
                TemperatureC = rng.Next(-20, 55),
            }).ToList();
        }

        public Task<WeatherForecast[]> GetForecastAsync(CancellationToken ct = default) {
            return Task.FromResult(Forecast.ToArray());
        }
    }
csharp
// ...
builder.Services.AddSingleton<WeatherForecastService>();

Run Demo: Charts - Series Label Customization

See Also

ChartSeriesPointCustomizationSettings Class

ChartSeriesPointCustomizationSettings Members

DevExpress.Blazor Namespace