From 3e3d72090f963443a6de9e3e9cec31a78f797d2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20Dang=C3=A5rden?= Date: Tue, 19 Dec 2023 21:31:48 +0100 Subject: [PATCH] added dynamic donut sample --- .../ChartTypes/DonutCharts/DonutCharts.razor | 16 +++-- .../ChartTypes/DonutCharts/Dynamic.razor | 61 +++++++++++++++++++ 2 files changed, 72 insertions(+), 5 deletions(-) create mode 100644 docs/BlazorApexCharts.Docs/Components/ChartTypes/DonutCharts/Dynamic.razor diff --git a/docs/BlazorApexCharts.Docs/Components/ChartTypes/DonutCharts/DonutCharts.razor b/docs/BlazorApexCharts.Docs/Components/ChartTypes/DonutCharts/DonutCharts.razor index 3d1d066d..a7420238 100644 --- a/docs/BlazorApexCharts.Docs/Components/ChartTypes/DonutCharts/DonutCharts.razor +++ b/docs/BlazorApexCharts.Docs/Components/ChartTypes/DonutCharts/DonutCharts.razor @@ -1,16 +1,16 @@ @page "/donut-charts" - + - + - + - + @@ -20,4 +20,10 @@ - + + + + + + + \ No newline at end of file diff --git a/docs/BlazorApexCharts.Docs/Components/ChartTypes/DonutCharts/Dynamic.razor b/docs/BlazorApexCharts.Docs/Components/ChartTypes/DonutCharts/Dynamic.razor new file mode 100644 index 00000000..c6747523 --- /dev/null +++ b/docs/BlazorApexCharts.Docs/Components/ChartTypes/DonutCharts/Dynamic.razor @@ -0,0 +1,61 @@ + + + + @if (forecasts != null) + { + + + + + } + + +
+ + + +
+
+ +@code { + private List forecasts { get; set; } + private ApexChart chart; + + protected override async Task OnInitializedAsync() + { + await LoadDataAsync(2); // get small sample first + + await base.OnInitializedAsync(); + } + + private async Task LoadDataAsync(int? limit) + { + var tempForecast = await SampleData.GetForecastAsync(DateTime.Today); + + var groupedData = tempForecast.GroupBy(x => x.Summary) + .Select(x => new WeatherForecast() + { + Date = x.First().Date, + Summary = x.First().Summary, + TemperatureC = x.Sum(y => Math.Abs(y.TemperatureC)) // easier to compare with positive values + }) + .ToList(); + + forecasts = limit.HasValue + ? groupedData.Take(limit.Value).ToList() + : groupedData.ToList(); + } + + private async Task UpdateChartSeries() + { + await LoadDataAsync(null); // get full sample on update + await chart.UpdateOptionsAsync(true, true, false); + } +} \ No newline at end of file