Back to Devexpress

IChartSeriesLabel Interface

blazor-devexpress-dot-blazor-a460a701.md

latest5.2 KB
Original Source

IChartSeriesLabel Interface

Defines a point’s label settings.

Namespace : DevExpress.Blazor

Assembly : DevExpress.Blazor.v25.2.dll

NuGet Package : DevExpress.Blazor

Declaration

csharp
public interface IChartSeriesLabel

The following members return IChartSeriesLabel objects:

Remarks

IChartSeriesLabel properties allow you to configure point label settings. To access these settings, use the PointLabel property in a CustomizeSeriesPoint event handler.

The following properties are available:

VisibleAllows you to hide or display series labels.Alignment | HorizontalOffset | VerticalOffset | PositionSpecify label location.RotationAngleSpecifies the rotation angle of series labels.BackgroundColor | Border | ConnectorCustomize label appearance.Texts | Font | FormatPatternConfigure text content and settings for series labels.ShowForZeroValuesAllows you to hide or display labels for series points with zero values.

Example

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

IChartSeriesLabel Members

DevExpress.Blazor Namespace