1+ <DemoContainer >
2+ <Button class =" mb-2" OnClick =UpdateChartSeries BackgroundColor =" TablerColor.Primary" >Update Series</Button >
3+
4+ @if (forecasts != null )
5+ {
6+ <ApexChart TItem =" WeatherForecast"
7+ Title =" Temp C"
8+ @ref =" chart" >
9+
10+ <ApexPointSeries TItem =" WeatherForecast"
11+ Items =" forecasts"
12+ Name =" Temp C"
13+ XValue =" @(e => e.Summary)"
14+ YValue =" @(e => e.TemperatureC)"
15+ SeriesType =" SeriesType.Donut" />
16+ </ApexChart >
17+ }
18+ </DemoContainer >
19+
20+ <div >
21+ <Table Items =" forecasts" >
22+ <Column Item =" WeatherForecast" Property =" e=> e.Summary" />
23+ <Column Item =" WeatherForecast" Property =" e=> e.TemperatureC" />
24+ </Table >
25+ </div >
26+
27+ @code {
28+ private List <WeatherForecast > forecasts { get ; set ; }
29+ private ApexChart <WeatherForecast > chart ;
30+
31+ protected override async Task OnInitializedAsync ()
32+ {
33+ await LoadDataAsync (2 ); // get small sample first
34+
35+ await base .OnInitializedAsync ();
36+ }
37+
38+ private async Task LoadDataAsync (int ? limit )
39+ {
40+ var tempForecast = await SampleData .GetForecastAsync (DateTime .Today );
41+
42+ var groupedData = tempForecast .GroupBy (x => x .Summary )
43+ .Select (x => new WeatherForecast ()
44+ {
45+ Date = x .First ().Date ,
46+ Summary = x .First ().Summary ,
47+ TemperatureC = x .Sum (y => Math .Abs (y .TemperatureC )) // easier to compare with positive values
48+ })
49+ .ToList ();
50+
51+ forecasts = limit .HasValue
52+ ? groupedData .Take (limit .Value ).ToList ()
53+ : groupedData .ToList ();
54+ }
55+
56+ private async Task UpdateChartSeries ()
57+ {
58+ await LoadDataAsync (null ); // get full sample on update
59+ await chart .UpdateOptionsAsync (true , true , false );
60+ }
61+ }
0 commit comments