139 lines
4.3 KiB
C#
139 lines
4.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using Blazorise.Charts;
|
|
using Microsoft.AspNetCore.Components;
|
|
using MP.Stats.Data;
|
|
|
|
namespace MP.Stats.Components
|
|
{
|
|
public partial class ChartScarti
|
|
{
|
|
[Inject]
|
|
protected MessageService MessageService { get; set; }
|
|
[Inject]
|
|
protected MpStatsService StatService { get; set; }
|
|
|
|
protected SelectData _currFilter { get; set; } = new SelectData();
|
|
|
|
protected List<MP.Data.DatabaseModels.ResScarti> _listScarti { get; set; } = new List<MP.Data.DatabaseModels.ResScarti>();
|
|
|
|
[Parameter]
|
|
public List<MP.Data.DatabaseModels.ResScarti> ListScarti
|
|
{
|
|
get => _listScarti;
|
|
set
|
|
{
|
|
// salvo valori
|
|
_listScarti = value;
|
|
// ricalcolo charting data
|
|
recalcData();
|
|
var dataReload = Task.Run(async () =>
|
|
{
|
|
await HandleRedraw();
|
|
});
|
|
}
|
|
}
|
|
|
|
protected BarChart<double> ParetoGuasti;
|
|
|
|
object barChartOptions = new
|
|
{
|
|
//Title = new
|
|
//{
|
|
// Display = true,
|
|
// Text = "Causali Scarto"
|
|
//},
|
|
Scales = new
|
|
{
|
|
XAxes = new object[]
|
|
{
|
|
new {
|
|
Display = false
|
|
}
|
|
},
|
|
YAxes = new object[]
|
|
{
|
|
new {
|
|
Display = true,
|
|
ticks= new {
|
|
suggestedMin = 0
|
|
}
|
|
}
|
|
}
|
|
},
|
|
Tooltips = new
|
|
{
|
|
Mode = "nearest",
|
|
Intersect = false
|
|
},
|
|
Hover = new
|
|
{
|
|
Mode = "nearest",
|
|
Intersect = false
|
|
},
|
|
//Legend = new
|
|
//{
|
|
// Display = true,
|
|
// FullWidth = true
|
|
//},
|
|
Animation = false,
|
|
AspectRatio = 2.5
|
|
};
|
|
|
|
|
|
protected List<ChartKV> CurrData { get; set; } = new List<ChartKV>();
|
|
|
|
//protected override async Task OnAfterRenderAsync(bool firstRender)
|
|
//{
|
|
// if (firstRender)
|
|
// {
|
|
// await HandleRedraw();
|
|
// }
|
|
//}
|
|
protected async Task HandleRedraw()
|
|
{
|
|
await ParetoGuasti.Clear();
|
|
await ParetoGuasti.AddLabelsDatasetsAndUpdate(GetBarChartLabels(), GetBarChartDataset());
|
|
}
|
|
|
|
List<string> GetBarChartLabels()
|
|
{
|
|
var answ = CurrData.Select(x => x.label).ToList();
|
|
return answ;
|
|
}
|
|
|
|
BarChartDataset<double> GetBarChartDataset()
|
|
{
|
|
var answ = new BarChartDataset<double>
|
|
{
|
|
Label = "Causali Scarto",
|
|
Data = CurrData.Select(x => x.value).ToList(),
|
|
BackgroundColor = backgroundColors,
|
|
//BorderColor = borderColors,
|
|
HoverBorderWidth = 5
|
|
};
|
|
return answ;
|
|
}
|
|
|
|
|
|
List<string> backgroundColors = new List<string>
|
|
{ ChartColor.FromRgba(255, 99, 132, 0.2f), ChartColor.FromRgba(54, 162, 235, 0.2f), ChartColor.FromRgba(255, 206, 86, 0.2f), ChartColor.FromRgba(75, 192, 192, 0.2f), ChartColor.FromRgba(153, 102, 255, 0.2f), ChartColor.FromRgba(255, 159, 64, 0.2f) };
|
|
List<string> borderColors = new List<string>
|
|
{ ChartColor.FromRgba(255, 99, 132, 1f), ChartColor.FromRgba(54, 162, 235, 1f), ChartColor.FromRgba(255, 206, 86, 1f), ChartColor.FromRgba(75, 192, 192, 1f), ChartColor.FromRgba(153, 102, 255, 1f), ChartColor.FromRgba(255, 159, 64, 1f) };
|
|
|
|
private void recalcData()
|
|
{
|
|
if (ListScarti != null)
|
|
{
|
|
CurrData = ListScarti
|
|
.GroupBy(x => x.Causale)
|
|
.Select(y => new ChartKV() { label = y.First().Descrizione, value = y.Sum(c => c.Qta) })
|
|
.OrderByDescending(x => x.value)
|
|
.ToList();
|
|
}
|
|
}
|
|
}
|
|
}
|