Skip to content

Commit efcb1b1

Browse files
authored
Merge pull request #639 from drualcman/ApexGaugeUpdate
Add UpdateValueAsync to ApexGauge
2 parents 81a56a7 + 2386d91 commit efcb1b1

2 files changed

Lines changed: 57 additions & 40 deletions

File tree

src/Blazor-ApexCharts/ApexGauge.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
@namespace ApexCharts
22

3-
<ApexChart TItem="GaugeValue" Title="@Title" Options="options">
3+
<ApexChart TItem="GaugeValue" Title="@Title" Options="options" @ref=GaugeReference>
44

55
<ApexPointSeries TItem="GaugeValue"
66
SeriesType=SeriesType.RadialBar
Lines changed: 56 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,62 @@
1-
using Microsoft.AspNetCore.Components;
2-
using System;
3-
using System.Collections.Generic;
4-
5-
namespace ApexCharts
6-
{
1+
using Microsoft.AspNetCore.Components;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Threading.Tasks;
5+
6+
namespace ApexCharts
7+
{
78
/// <summary>
89
/// Component to create a single-value <see cref="SeriesType.RadialBar"/> chart in Blazor
9-
/// </summary>
10-
public partial class ApexGauge : IDisposable
11-
{
12-
/// <inheritdoc cref="Title.Text"/>
13-
[Parameter] public string Title { get; set; }
14-
15-
/// <inheritdoc cref="GaugeValue.Percentage"/>
16-
[Parameter] public decimal Percentage { get; set; }
17-
18-
/// <inheritdoc cref="GaugeValue.Label"/>
19-
[Parameter] public string Label { get; set; }
20-
10+
/// </summary>
11+
public partial class ApexGauge : IDisposable
12+
{
13+
/// <inheritdoc cref="Title.Text"/>
14+
[Parameter] public string Title { get; set; }
15+
16+
/// <inheritdoc cref="GaugeValue.Percentage"/>
17+
[Parameter] public decimal Percentage { get; set; }
18+
19+
/// <inheritdoc cref="GaugeValue.Label"/>
20+
[Parameter] public string Label { get; set; }
21+
2122
/// <summary>
2223
/// The options to customize the radial bar chart with
23-
/// </summary>
24-
[Parameter] public ApexChartOptions<GaugeValue> Options { get; set; } = new ApexChartOptions<GaugeValue>();
25-
24+
/// </summary>
25+
[Parameter] public ApexChartOptions<GaugeValue> Options { get; set; } = new ApexChartOptions<GaugeValue>();
26+
2627
private ApexChartOptions<GaugeValue> options;
2728

28-
/// <inheritdoc/>
29-
protected override void OnInitialized()
30-
{
31-
options = Options;
32-
}
33-
34-
private List<GaugeValue> GetItems()
35-
{
36-
return new List<GaugeValue> { new GaugeValue { Label = Label, Percentage = Percentage } };
37-
}
38-
39-
/// <inheritdoc/>
40-
public void Dispose()
41-
{
42-
GC.SuppressFinalize(this);
43-
}
44-
}
45-
}
29+
ApexChart<GaugeValue> GaugeReference;
30+
31+
/// <inheritdoc/>
32+
protected override void OnInitialized()
33+
{
34+
options = Options;
35+
}
36+
37+
38+
/// <summary>
39+
/// Allows you to update the series array overriding the existing one. If you want to append series to existing series, use the appendSeries() method
40+
/// </summary>
41+
/// <param name="animate">Should the chart animate on re-rendering</param>
42+
/// <remarks>
43+
/// Links:
44+
///
45+
/// <see href="https://apexcharts.github.io/Blazor-ApexCharts/methods/update-series">Blazor Example</see>,
46+
/// <see href="https://apexcharts.com/docs/methods/#updateSeries">JavaScript Documentation</see>
47+
/// </remarks>
48+
public Task UpdateValueAsync(bool animate = true) =>
49+
GaugeReference?.UpdateSeriesAsync(animate);
50+
51+
private List<GaugeValue> GetItems()
52+
{
53+
return new List<GaugeValue> { new GaugeValue { Label = Label, Percentage = Percentage } };
54+
}
55+
56+
/// <inheritdoc/>
57+
public void Dispose()
58+
{
59+
GC.SuppressFinalize(this);
60+
}
61+
}
62+
}

0 commit comments

Comments
 (0)