mirror of
https://gitlab.com/Hukuta47/cartrix.git
synced 2026-12-05 20:40:55 +00:00
Сделал отображение диаграммы
This commit is contained in:
1 parent
cf5ea0861b
commit
2482e30cb3
2 files changed
+139
-11
No files matched your search
@@ -16,5 +16,5 @@
|
|||||||
|
|
||||||
@code
|
@code
|
||||||
{
|
{
|
||||||
bool sideBarExpanded = true;
|
bool sideBarExpanded = false;
|
||||||
}
|
}
|
||||||
@@ -2,30 +2,158 @@
|
|||||||
@page "/dashboard"
|
@page "/dashboard"
|
||||||
@inject HttpClient http
|
@inject HttpClient http
|
||||||
|
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.splinediagram {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
.lineddiagram {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@@media (max-width: 800px) {
|
||||||
|
.splinediagram {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.lineddiagram {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@@media (min-width: 801px) {
|
||||||
|
.splinediagram {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
|
||||||
|
.lineddiagram {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<RadzenCard class="splinediagram">
|
||||||
|
<div style="display: flex; gap: 15px; margin-bottom: 20px; align-items: center;">
|
||||||
|
<label>Выберите количество дней:</label>
|
||||||
|
<RadzenDropDown @bind-Value="selectedDays"
|
||||||
|
Data="availableDays"
|
||||||
|
Change="OnDaysChanged"
|
||||||
|
Style="width: 150px;" />
|
||||||
|
</div>
|
||||||
|
|
||||||
<RadzenChart>
|
<RadzenChart>
|
||||||
<RadzenAreaSeries Smooth="true" Data="recordPrintedPagesItems" CategoryProperty="Date" Title="2023" ValueProperty="Revenue" RenderingOrder="1">
|
<RadzenAreaSeries Smooth="true"
|
||||||
|
Data="groupedData"
|
||||||
|
CategoryProperty="DateString"
|
||||||
|
ValueProperty="TotalPrinted"
|
||||||
|
Title="Количество распечаток">
|
||||||
<RadzenSeriesDataLabels />
|
<RadzenSeriesDataLabels />
|
||||||
</RadzenAreaSeries>
|
</RadzenAreaSeries>
|
||||||
<RadzenCategoryAxis Padding="20" LabelAutoRotation="-45" />
|
|
||||||
|
<RadzenCategoryAxis Padding="20" LabelAutoRotation="-45">
|
||||||
|
<RadzenAxisTitle Text="Даты" />
|
||||||
|
</RadzenCategoryAxis>
|
||||||
|
|
||||||
<RadzenValueAxis>
|
<RadzenValueAxis>
|
||||||
<RadzenGridLines Visible="true" />
|
<RadzenGridLines Visible="true" />
|
||||||
<RadzenAxisTitle Text="Revenue in USD" />
|
<RadzenAxisTitle Text="Количество распечаток" />
|
||||||
</RadzenValueAxis>
|
</RadzenValueAxis>
|
||||||
</RadzenChart>
|
</RadzenChart>
|
||||||
|
</RadzenCard>
|
||||||
|
|
||||||
|
<RadzenCard class="lineddiagram">
|
||||||
|
<div style="display: flex; gap: 15px; margin-bottom: 20px; align-items: center;">
|
||||||
|
<label>Выберите количество дней:</label>
|
||||||
|
<RadzenDropDown @bind-Value="selectedDays"
|
||||||
|
Data="availableDays"
|
||||||
|
Change="OnDaysChanged"
|
||||||
|
Style="width: 150px;" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<RadzenChart Style="height: 720px">
|
||||||
|
<RadzenBarSeries Data="groupedData"
|
||||||
|
CategoryProperty="DateString"
|
||||||
|
ValueProperty="TotalPrinted">
|
||||||
|
<RadzenSeriesDataLabels />
|
||||||
|
</RadzenBarSeries>
|
||||||
|
|
||||||
|
<RadzenLegend Visible="false"/>
|
||||||
|
|
||||||
|
<RadzenValueAxis>
|
||||||
|
<RadzenGridLines Visible="true" />
|
||||||
|
<RadzenAxisTitle Text="Количество распечаток" />
|
||||||
|
</RadzenValueAxis>
|
||||||
|
</RadzenChart>
|
||||||
|
</RadzenCard>
|
||||||
|
|
||||||
|
|
||||||
@code {
|
@code {
|
||||||
|
private List<Shared.Models.Report.RecordPrintedPagesItem> recordPrintedPagesItems = new();
|
||||||
|
private List<GroupedPrintData> groupedData = new();
|
||||||
|
private readonly List<int> availableDays = new() { 7, 14, 21 };
|
||||||
|
private int selectedDays = 7;
|
||||||
|
|
||||||
List<Shared.Models.Report.RecordPrintedPagesItem> recordPrintedPagesItems = new();
|
protected override async Task OnInitializedAsync()
|
||||||
|
|
||||||
protected async override Task OnInitializedAsync()
|
|
||||||
{
|
{
|
||||||
|
await LoadData();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async Task OnDaysChanged(object value)
|
||||||
async Task GetrecordPrintedPagesItems()
|
|
||||||
{
|
{
|
||||||
var responce = http.GetAsync(Shared.Classes.ApiRoutes.Report.GetRecordPrintAtSeletedDays(5));
|
selectedDays = Convert.ToInt32(value);
|
||||||
|
await LoadData();
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task LoadData()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var response = await http.GetAsync(
|
||||||
|
Shared.Classes.ApiRoutes.Report.GetRecordPrintAtSeletedDays(selectedDays));
|
||||||
|
|
||||||
|
var json = await response.Content.ReadAsStringAsync();
|
||||||
|
var items = JsonConvert.DeserializeObject<List<Shared.Models.Report.RecordPrintedPagesItem>>(json) ?? new();
|
||||||
|
|
||||||
|
recordPrintedPagesItems = items;
|
||||||
|
BuildGroupedData();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"Ошибка: {ex.Message}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void BuildGroupedData()
|
||||||
|
{
|
||||||
|
var grouped = recordPrintedPagesItems
|
||||||
|
.GroupBy(x => x.Date)
|
||||||
|
.ToDictionary(g => g.Key, g => g.Sum(x => x.CounntPrinted));
|
||||||
|
|
||||||
|
var today = DateOnly.FromDateTime(DateTime.Now);
|
||||||
|
var startDate = today.AddDays(-(selectedDays - 1));
|
||||||
|
|
||||||
|
groupedData = Enumerable.Range(0, selectedDays)
|
||||||
|
.Select(i =>
|
||||||
|
{
|
||||||
|
var date = startDate.AddDays(i);
|
||||||
|
return new GroupedPrintData
|
||||||
|
{
|
||||||
|
Date = date,
|
||||||
|
DateString = date.ToString("dd.MM.yyyy"),
|
||||||
|
TotalPrinted = grouped.TryGetValue(date, out var total) ? total : 0
|
||||||
|
};
|
||||||
|
})
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public class GroupedPrintData
|
||||||
|
{
|
||||||
|
public DateOnly Date { get; set; }
|
||||||
|
public string DateString { get; set; } = string.Empty;
|
||||||
|
public int TotalPrinted { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user