Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@

<DemoContainer>
<ApexChart TItem="Order"
Title="Bar Lables"
Options="options">

<ApexPointSeries TItem="Order"
Items="orders"
SeriesType=SeriesType.RadialBar
Name="Gross Value"
XValue="@(e => e.Country)"
YAggregate="@(e => decimal.Round(e.Average(e => e.DiscountPercentage)))"
OrderByDescending="e=>e.Y" />
</ApexChart>
</DemoContainer>



@code {
private List<Order> orders = SampleData.GetOrders();
private ApexChartOptions<Order> 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];
}"
},
}
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,10 @@
</Snippet>
</CodeSnippet>

<CodeSnippet Title="Bar Labels" ClassName=@typeof(BarLabels).ToString()>
<Snippet>
<BarLabels />
</Snippet>
</CodeSnippet>

</DocExamples>
62 changes: 31 additions & 31 deletions src/Blazor-ApexCharts/Internal/Converters/DataPointConverter.cs
Original file line number Diff line number Diff line change
@@ -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
{
/// <summary>
/// Facilitates serialization of <see cref="IDataPoint{TItem}"/>
/// </summary>
/// <typeparam name="T"></typeparam>
internal class DataPointConverter<T> : JsonConverter<IDataPoint<T>>
{
/// <inheritdoc/>
/// <exception cref="NotImplementedException"></exception>
public override IDataPoint<T> Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
throw new NotImplementedException();
}

/// <inheritdoc/>
public override void Write(Utf8JsonWriter writer, IDataPoint<T> value, JsonSerializerOptions options)
{
if (value == null)
{
JsonSerializer.Serialize(writer, (IDataPoint<T>)null, options);
}
else
{
var type = value.GetType();
JsonSerializer.Serialize(writer, value, type, options);
}
}
}
}
/// <typeparam name="T"></typeparam>
internal class DataPointConverter<T> : JsonConverter<IDataPoint<T>>
{
/// <inheritdoc/>
/// <exception cref="NotImplementedException"></exception>
public override IDataPoint<T> Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
throw new NotImplementedException();
}
/// <inheritdoc/>
public override void Write(Utf8JsonWriter writer, IDataPoint<T> value, JsonSerializerOptions options)
{
if (value == null)
{
JsonSerializer.Serialize(writer, (IDataPoint<T>)null, options);
}
else
{
var type = value.GetType();
JsonSerializer.Serialize(writer, value, type, options);
}
}
}
}
49 changes: 47 additions & 2 deletions src/Blazor-ApexCharts/Models/ApexChartOptions.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -3637,6 +3638,9 @@ public class PlotOptionsRadialBar
/// <inheritdoc cref="ApexCharts.RadialBarDataLabels" />
public RadialBarDataLabels DataLabels { get; set; }

/// <inheritdoc cref="ApexCharts.RadialBarBarLabels" />
public RadialBarBarLabels BarLabels { get; set; }

/// <summary>
/// Angle to which the radialBars should end. The sum of the startAngle and endAngle should not exceed 360.
/// </summary>
Expand Down Expand Up @@ -3669,10 +3673,51 @@ public class PlotOptionsRadialBar
public Track Track { get; set; }
}


/// <summary>
/// Defines how to style labels for the radial bar chart
/// Defines how to style Bar labels for the radial bar chart
/// </summary>
public class RadialBarDataLabels
public class RadialBarBarLabels
{
/// <summary>
/// Enabled
/// </summary>
public bool Enabled { get; set; } = true;

/// <summary>
/// Use colors from the series
/// </summary>
public bool? UseSeriesColors { get; set; }

/// <summary>
/// X-Offset for bar labels
/// </summary>
public int? OffsetX { get; set; }

/// <summary>
/// Fontsize for the label
/// </summary>
public string FontSize { get; set; }


/// <summary>
/// To format the Label of the bar
/// <code>
/// formatter: function(seriesName, opts) {
/// return value
/// }
/// </code>
/// </summary>
[JsonConverter(typeof(FunctionStringConverter))]
public string Formatter { get; set; }


}

/// <summary>
/// Defines how to style labels for the radial bar chart
/// </summary>
public class RadialBarDataLabels
{
/// <inheritdoc cref="ApexCharts.RadialBarDataLabelsName" />
public RadialBarDataLabelsName Name { get; set; }
Expand Down