Skip to content

Commit

Permalink
Allow the developer to set the Fill of RadzenSeriesAnnotation. Closes #…
Browse files Browse the repository at this point in the history
  • Loading branch information
akorchev committed Nov 15, 2024
1 parent 124033d commit 96b8901
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
11 changes: 8 additions & 3 deletions Radzen.Blazor/RadzenSeriesAnnotation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ public partial class RadzenSeriesAnnotation<TItem> : RadzenChartComponentBase, I
[Parameter]
public double OffsetY { get; set; }

/// <summary> The color of the annotation text. </summary>
[Parameter]
public string Fill { get; set; }

/// <summary> Determines whether the annotation is visible. Set to <c>true</c> by default.</summary>
[Parameter]
public bool Visible { get; set; } = true;
Expand Down Expand Up @@ -130,9 +134,10 @@ public RenderFragment Render(ScaleBase categoryScale, ScaleBase valueScale)
{
builder.OpenElement(0, "g");
builder.OpenComponent<Text>(1);
builder.AddAttribute(2, "Value", Text);
builder.AddAttribute(3, "Position", new Point{ X = x, Y = y });
builder.AddAttribute(4, "TextAnchor", textAnchor);
builder.AddAttribute(2, nameof(Rendering.Text.Value), Text);
builder.AddAttribute(3, nameof(Rendering.Text.Position), new Point{ X = x, Y = y });
builder.AddAttribute(4, nameof(Rendering.Text.TextAnchor), textAnchor);
builder.AddAttribute(5, nameof(Rendering.Text.Fill), Fill);
builder.SetKey($"{Text}-{Chart.Series.IndexOf(series)}");
builder.CloseComponent();
builder.CloseElement();
Expand Down
5 changes: 4 additions & 1 deletion Radzen.Blazor/Rendering/Text.razor
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<text class=@Class alignment-baseline="middle" text-anchor=@TextAnchor x=@Position.X.ToInvariantString() y=@Position.Y.ToInvariantString()>@Value</text>
<text class=@Class fill=@Fill alignment-baseline="middle" text-anchor=@TextAnchor x=@Position.X.ToInvariantString() y=@Position.Y.ToInvariantString()>@Value</text>
@code {
[Parameter]
public string Class { get; set; }
Expand All @@ -11,4 +11,7 @@

[Parameter]
public string TextAnchor { get; set; } = "middle";

[Parameter]
public string Fill { get; set; }
}
7 changes: 4 additions & 3 deletions RadzenBlazorDemos/Pages/ChartAnnotations.razor
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
</RadzenCard>

<RadzenChart>
<RadzenLineSeries Smooth="true" Data="@revenue2023" CategoryProperty="Date" Title="2023" ValueProperty="Revenue" RenderingOrder="1">
<RadzenSeriesAnnotation Visible="@annotation" TItem="DataItem" Data="@revenue2023[7]" OffsetY="-16" Text="Acquisition" />
<RadzenLineSeries Smooth="true" Data="@revenue2024" CategoryProperty="Date" Title="2024" ValueProperty="Revenue" RenderingOrder="1">
<RadzenSeriesAnnotation Visible="@annotation" TItem="DataItem" Data="@revenue2024[7]" OffsetY="-16" Text="Acquisition" />
<RadzenSeriesAnnotation Visible="@annotation" TItem="DataItem" Data="@revenue2024[5]" OffsetY="-16" Text="IPO" Fill="#ff504d" />
<RadzenMarkers MarkerType="MarkerType.Circle" />
</RadzenLineSeries>
<RadzenCategoryAxis Padding="20" />
Expand All @@ -35,7 +36,7 @@
return ((double)value).ToString("C0", CultureInfo.CreateSpecificCulture("en-US"));
}

DataItem[] revenue2023 = new DataItem[] {
DataItem[] revenue2024 = new DataItem[] {
new DataItem
{
Date = "Jan",
Expand Down

0 comments on commit 96b8901

Please sign in to comment.