using Microsoft.AspNetCore.Components; using Plotly.Blazor; using Plotly.Blazor.Traces; using Schaad.Accounting.Interfaces; namespace Schaad.Accounting.UI.Components.Pages.Charts; public partial class Spendings : ComponentBase { private PlotlyChart chart = null!; private Config? config; private Plotly.Blazor.Layout? layout; private IList? data; [Inject] private IViewService viewService { get; set; } = null!; protected override async Task OnInitializedAsync() { config = new Config { Responsive = true }; layout = new Plotly.Blazor.Layout { }; var accounts = (await viewService.GetAccountViewListAsync()).Where(a => a.Class == ClassIds.Expenses); var values = new List(); var labels = new List(); foreach (var grp in accounts.GroupBy(a => a.SubClass).Select(a => new {Key = a.Key, List = a.ToList()})) { if (grp.List.Sum(g => g.Balance) != 0) { values.Add(grp.List.Sum(g => g.Balance)); labels.Add(grp.List.First().SubClassName); } } data = new List { new Pie { Values =values, Labels = labels } }; await base.OnInitializedAsync(); } }