Adds two charts to the per-account transactions view: a stacked bar chart of monthly totals and a pie chart of overall totals, both grouped by booking text, so recurring bookings (rent, subscriptions, etc.) are visible at a glance. Chart components are keyed on the account id so switching accounts remounts them instead of reusing a stale Plotly instance.
44 lines
1.3 KiB
C#
44 lines
1.3 KiB
C#
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 BookingTextBreakdown : ComponentBase
|
|
{
|
|
private PlotlyChart chart = null!;
|
|
private Config? config;
|
|
private Plotly.Blazor.Layout? layout;
|
|
private IList<ITrace>? data;
|
|
|
|
[Parameter, EditorRequired]
|
|
public string AccountId { get; set; } = null!;
|
|
|
|
[Inject]
|
|
private IChartService chartService { get; set; } = null!;
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
config = new Config
|
|
{
|
|
Responsive = true
|
|
};
|
|
|
|
layout = new Plotly.Blazor.Layout
|
|
{
|
|
Title = new Plotly.Blazor.LayoutLib.Title { Text = "Nach Buchungstext" }
|
|
};
|
|
|
|
var totals = await chartService.GetBookingTextTotalsAsync(AccountId);
|
|
data = new List<ITrace>
|
|
{
|
|
new Pie
|
|
{
|
|
// Values are shown as their absolute magnitude - a pie slice can't represent a signed amount.
|
|
Values = totals.Select(t => (object)Math.Abs(t.Value)).ToList(),
|
|
Labels = totals.Select(t => (object)t.Name).ToList()
|
|
}
|
|
};
|
|
}
|
|
}
|