35 lines
1.1 KiB
C#
35 lines
1.1 KiB
C#
using Microsoft.AspNetCore.Components;
|
|
using Plotly.Blazor;
|
|
using Plotly.Blazor.Traces;
|
|
using Schaad.Accounting.Datasets.Charts;
|
|
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<ITrace>? data;
|
|
|
|
[Inject]
|
|
private IViewService viewService { get; set; } = null!;
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
config = ChartTheme.BaseConfig();
|
|
layout = ChartTheme.BaseLayout("Ausgaben nach Kategorie");
|
|
|
|
var accounts = (await viewService.GetAccountViewListAsync()).Where(a => a.Class == ClassIds.Expenses);
|
|
var totals = accounts
|
|
.GroupBy(a => a.SubClass)
|
|
.Select(g => new CategoryTotal(g.First().SubClassName, g.Sum(a => a.Balance)))
|
|
.Where(t => t.Value != 0)
|
|
.ToList();
|
|
|
|
data = new List<ITrace> { ChartTheme.BuildDonutTrace(ChartFormatting.FoldTail(totals)) };
|
|
|
|
await base.OnInitializedAsync();
|
|
}
|
|
}
|