From 67be122cb826c9865c75ac5db93eaabe566dfb68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20Dang=C3=A5rden?= Date: Wed, 12 Nov 2025 23:01:13 +0100 Subject: [PATCH] Added support for Radial bar labels --- .../RadialBarCharts/BarLabels.razor | 44 +++++++++++++ .../RadialBarCharts/RadialBarCharts.razor | 6 ++ .../Internal/Converters/DataPointConverter.cs | 62 +++++++++---------- .../Models/ApexChartOptions.cs | 49 ++++++++++++++- 4 files changed, 128 insertions(+), 33 deletions(-) create mode 100644 docs/BlazorApexCharts.Docs/Components/ChartTypes/RadialBarCharts/BarLabels.razor diff --git a/docs/BlazorApexCharts.Docs/Components/ChartTypes/RadialBarCharts/BarLabels.razor b/docs/BlazorApexCharts.Docs/Components/ChartTypes/RadialBarCharts/BarLabels.razor new file mode 100644 index 00000000..a52a0f79 --- /dev/null +++ b/docs/BlazorApexCharts.Docs/Components/ChartTypes/RadialBarCharts/BarLabels.razor @@ -0,0 +1,44 @@ + + + + + + + + + + +@code { + private List orders = SampleData.GetOrders(); + private ApexChartOptions options = new(); + + protected override void OnInitialized() + { + options.PlotOptions = new PlotOptions + { + RadialBar = new PlotOptionsRadialBar + { + OffsetY= 0, + StartAngle= 0, + EndAngle = 270, + BarLabels = new RadialBarBarLabels + { + Enabled = true, + OffsetX = -12, + UseSeriesColors = true, + Formatter = @"function(seriesName, opts) { + return seriesName + ': ' + opts.w.globals.series[opts.seriesIndex]; + }" + }, + } + }; + } +} diff --git a/docs/BlazorApexCharts.Docs/Components/ChartTypes/RadialBarCharts/RadialBarCharts.razor b/docs/BlazorApexCharts.Docs/Components/ChartTypes/RadialBarCharts/RadialBarCharts.razor index 5e0f93a3..5301bee0 100644 --- a/docs/BlazorApexCharts.Docs/Components/ChartTypes/RadialBarCharts/RadialBarCharts.razor +++ b/docs/BlazorApexCharts.Docs/Components/ChartTypes/RadialBarCharts/RadialBarCharts.razor @@ -14,4 +14,10 @@ + + + + + + diff --git a/src/Blazor-ApexCharts/Internal/Converters/DataPointConverter.cs b/src/Blazor-ApexCharts/Internal/Converters/DataPointConverter.cs index 40ab26b2..dd2b6753 100644 --- a/src/Blazor-ApexCharts/Internal/Converters/DataPointConverter.cs +++ b/src/Blazor-ApexCharts/Internal/Converters/DataPointConverter.cs @@ -1,34 +1,34 @@ -using System; -using System.Text.Json; -using System.Text.Json.Serialization; - -namespace ApexCharts.Internal -{ +using System; +using System.Text.Json; +using System.Text.Json.Serialization; + +namespace ApexCharts.Internal +{ /// /// Facilitates serialization of /// - /// - internal class DataPointConverter : JsonConverter> - { - /// - /// - public override IDataPoint Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) - { - throw new NotImplementedException(); - } - - /// - public override void Write(Utf8JsonWriter writer, IDataPoint value, JsonSerializerOptions options) - { - if (value == null) - { - JsonSerializer.Serialize(writer, (IDataPoint)null, options); - } - else - { - var type = value.GetType(); - JsonSerializer.Serialize(writer, value, type, options); - } - } - } -} + /// + internal class DataPointConverter : JsonConverter> + { + /// + /// + public override IDataPoint Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + { + throw new NotImplementedException(); + } + + /// + public override void Write(Utf8JsonWriter writer, IDataPoint value, JsonSerializerOptions options) + { + if (value == null) + { + JsonSerializer.Serialize(writer, (IDataPoint)null, options); + } + else + { + var type = value.GetType(); + JsonSerializer.Serialize(writer, value, type, options); + } + } + } +} diff --git a/src/Blazor-ApexCharts/Models/ApexChartOptions.cs b/src/Blazor-ApexCharts/Models/ApexChartOptions.cs index 7237485f..11114728 100644 --- a/src/Blazor-ApexCharts/Models/ApexChartOptions.cs +++ b/src/Blazor-ApexCharts/Models/ApexChartOptions.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Runtime.CompilerServices; using System.Runtime.Serialization; using System.Text.Json.Serialization; using ApexCharts.Internal; @@ -3637,6 +3638,9 @@ public class PlotOptionsRadialBar /// public RadialBarDataLabels DataLabels { get; set; } + /// + public RadialBarBarLabels BarLabels { get; set; } + /// /// Angle to which the radialBars should end. The sum of the startAngle and endAngle should not exceed 360. /// @@ -3669,10 +3673,51 @@ public class PlotOptionsRadialBar public Track Track { get; set; } } + /// - /// Defines how to style labels for the radial bar chart + /// Defines how to style Bar labels for the radial bar chart /// - public class RadialBarDataLabels + public class RadialBarBarLabels + { + /// + /// Enabled + /// + public bool Enabled { get; set; } = true; + + /// + /// Use colors from the series + /// + public bool? UseSeriesColors { get; set; } + + /// + /// X-Offset for bar labels + /// + public int? OffsetX { get; set; } + + /// + /// Fontsize for the label + /// + public string FontSize { get; set; } + + + /// + /// To format the Label of the bar + /// + /// formatter: function(seriesName, opts) { + /// return value + /// } + /// + /// + [JsonConverter(typeof(FunctionStringConverter))] + public string Formatter { get; set; } + + + } + + /// + /// Defines how to style labels for the radial bar chart + /// + public class RadialBarDataLabels { /// public RadialBarDataLabelsName Name { get; set; }