-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #363 from apexcharts/add-sample
added dynamic donut sample
- Loading branch information
Showing
2 changed files
with
72 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
docs/BlazorApexCharts.Docs/Components/ChartTypes/DonutCharts/Dynamic.razor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<DemoContainer> | ||
<Button class="mb-2" OnClick=UpdateChartSeries BackgroundColor="TablerColor.Primary">Update Series</Button> | ||
|
||
@if (forecasts != null) | ||
{ | ||
<ApexChart TItem="WeatherForecast" | ||
Title="Temp C" | ||
@ref="chart"> | ||
|
||
<ApexPointSeries TItem="WeatherForecast" | ||
Items="forecasts" | ||
Name="Temp C" | ||
XValue="@(e => e.Summary)" | ||
YValue="@(e => e.TemperatureC)" | ||
SeriesType="SeriesType.Donut" /> | ||
</ApexChart> | ||
} | ||
</DemoContainer> | ||
|
||
<div> | ||
<Table Items="forecasts"> | ||
<Column Item="WeatherForecast" Property="e=> e.Summary" /> | ||
<Column Item="WeatherForecast" Property="e=> e.TemperatureC" /> | ||
</Table> | ||
</div> | ||
|
||
@code { | ||
private List<WeatherForecast> forecasts { get; set; } | ||
private ApexChart<WeatherForecast> 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); | ||
} | ||
} |