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.
57 lines
1.6 KiB
C#
57 lines
1.6 KiB
C#
using Microsoft.AspNetCore.Components;
|
|
using Plotly.Blazor;
|
|
using Plotly.Blazor.LayoutLib;
|
|
using Plotly.Blazor.Traces;
|
|
using Schaad.Accounting.Interfaces;
|
|
|
|
namespace Schaad.Accounting.UI.Components.Pages.Charts;
|
|
|
|
public partial class BookingTextOverTime : ComponentBase
|
|
{
|
|
private PlotlyChart chart = null!;
|
|
private Config? config;
|
|
private Plotly.Blazor.Layout? layout;
|
|
private IList<ITrace> data = new List<ITrace>();
|
|
|
|
[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 Title { Text = "Nach Buchungstext im Verlauf" },
|
|
BarMode = BarModeEnum.Stack,
|
|
XAxis = new List<XAxis>
|
|
{
|
|
new()
|
|
{
|
|
Type = Plotly.Blazor.LayoutLib.XAxisLib.TypeEnum.Date
|
|
}
|
|
}
|
|
};
|
|
|
|
var newData = new List<ITrace>();
|
|
var dataSeries = await chartService.GetBookingTextExpensesPerMonthAsync(AccountId);
|
|
foreach (var dataSerie in dataSeries)
|
|
{
|
|
newData.Add(new Bar
|
|
{
|
|
Name = dataSerie.Name,
|
|
X = dataSerie.X.Select(d => (object)d).ToList(),
|
|
Y = dataSerie.Y.Select(d => (object)d).ToList(),
|
|
});
|
|
}
|
|
data = newData;
|
|
|
|
await base.OnInitializedAsync();
|
|
}
|
|
}
|