OK ripristino grafici di base x STAT
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<RootNamespace>MP.Stats</RootNamespace>
|
||||
<UserSecretsId>826e877c-ba70-4253-84cb-d0b1cafd4440</UserSecretsId>
|
||||
<Version>6.14.2202.2117</Version>
|
||||
<Version>6.14.2202.2119</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
+15
-131
@@ -1,145 +1,29 @@
|
||||
@page "/test"
|
||||
|
||||
@using MP.Stats.Components
|
||||
|
||||
<h1>Test</h1>
|
||||
|
||||
<button class="btn btn-info btn-sm" @onclick="@(async () => await HandleRedraw())">Redraw</button>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-3">
|
||||
@*<div class="col-3">
|
||||
<LineChart @ref="lineChart" TItem="double" OptionsObject="horizontalLineChartOptions" />
|
||||
</div>
|
||||
<div class="col-3">
|
||||
</div>
|
||||
<div class="col-3">
|
||||
<PieChart @ref="pieChart" TItem="double" OptionsObject="horizontalLineChartOptions" />
|
||||
</div>
|
||||
<div class="col-3">
|
||||
</div>
|
||||
<div class="col-3">
|
||||
<HorizontalBarChart @ref="barChartHoriz" TItem="double" OptionsObject="horizontalLineChartOptions" />
|
||||
</div>
|
||||
<div class="col-3">
|
||||
</div>
|
||||
<div class="col-3">
|
||||
<BarChart @ref="barChart" TItem="double" OptionsObject="horizontalLineChartOptions" />
|
||||
</div>*@
|
||||
<div class="col-6">
|
||||
<ChartHist Id="TestBar" Data="@histData" Labels="@histLabel" lineColor="rgb(7, 173, 236)" backColor="rgba(107, 223, 255, 0.5)"></ChartHist>
|
||||
</div>
|
||||
<div class="col-6">
|
||||
<ChartTSer Id="TestTS" DataTS="@dataList" lineColor="rgb(7, 173, 236)" backColor="rgba(107, 223, 255, 0.3)"></ChartTSer>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@code {
|
||||
PieChart<double> pieChart;
|
||||
LineChart<double> lineChart;
|
||||
HorizontalBarChart<double> barChartHoriz;
|
||||
BarChart<double> barChart;
|
||||
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
if (firstRender)
|
||||
{
|
||||
await HandleRedraw();
|
||||
}
|
||||
}
|
||||
|
||||
object horizontalLineChartOptions = new
|
||||
{
|
||||
//Title = new
|
||||
//{
|
||||
// Display = true,
|
||||
// Text = "Line chart sample"
|
||||
//},
|
||||
//Scales = new
|
||||
//{
|
||||
// XAxes = new object[]
|
||||
// {
|
||||
// new {
|
||||
// //ScaleLabel = new {
|
||||
// //Display = true, LabelString = "value" },
|
||||
// Stacked = true
|
||||
// }
|
||||
// }
|
||||
//},
|
||||
Tooltips = new
|
||||
{
|
||||
Mode = "nearest",
|
||||
Intersect = false
|
||||
},
|
||||
Hover = new
|
||||
{
|
||||
Mode = "nearest",
|
||||
Intersect = false
|
||||
},
|
||||
Legend = new
|
||||
{
|
||||
Display = true,
|
||||
FullWidth = true
|
||||
},
|
||||
AspectRatio = 2.5
|
||||
};
|
||||
|
||||
async Task HandleRedraw()
|
||||
{
|
||||
await pieChart.Clear();
|
||||
await pieChart.AddLabelsDatasetsAndUpdate(Labels, GetPieChartDataset());
|
||||
|
||||
await lineChart.Clear();
|
||||
await lineChart.AddLabelsDatasetsAndUpdate(Labels, GetLineChartDataset());
|
||||
|
||||
await barChart.Clear();
|
||||
await barChart.AddLabelsDatasetsAndUpdate(Labels, GetBarChartDataset());
|
||||
|
||||
await barChartHoriz.Clear();
|
||||
await barChartHoriz.AddLabelsDatasetsAndUpdate(Labels, GetHorizBarChartDataset());
|
||||
}
|
||||
|
||||
PieChartDataset<double> GetPieChartDataset()
|
||||
{
|
||||
return new PieChartDataset<double>
|
||||
{
|
||||
Label = "# of randoms",
|
||||
Data = RandomizeData(),
|
||||
BackgroundColor = backgroundColors,
|
||||
BorderColor = borderColors
|
||||
};
|
||||
}
|
||||
|
||||
LineChartDataset<double> GetLineChartDataset()
|
||||
{
|
||||
return new LineChartDataset<double>
|
||||
{
|
||||
Label = "# of randoms",
|
||||
Data = RandomizeData(),
|
||||
BackgroundColor = backgroundColors,
|
||||
BorderColor = borderColors,
|
||||
Fill = true,
|
||||
PointRadius = 2,
|
||||
BorderDash = new List<int> { }
|
||||
};
|
||||
}
|
||||
|
||||
BarChartDataset<double> GetBarChartDataset()
|
||||
{
|
||||
return new BarChartDataset<double>
|
||||
{
|
||||
Label = "# of randoms",
|
||||
Data = RandomizeData(),
|
||||
BackgroundColor = backgroundColors,
|
||||
BorderColor = borderColors,
|
||||
HoverBorderWidth = 5
|
||||
};
|
||||
}
|
||||
BarChartDataset<double> GetHorizBarChartDataset()
|
||||
{
|
||||
return new BarChartDataset<double>
|
||||
{
|
||||
Label = "# of randoms",
|
||||
Data = RandomizeData(),
|
||||
BackgroundColor = backgroundColors,
|
||||
BorderColor = borderColors,
|
||||
HoverBorderWidth = 5
|
||||
};
|
||||
}
|
||||
|
||||
string[] Labels = { "Red", "Blue", "Yellow", "Green", "Purple", "Orange" };
|
||||
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) };
|
||||
|
||||
List<double> RandomizeData()
|
||||
{
|
||||
var r = new Random(DateTime.Now.Millisecond);
|
||||
|
||||
return new List<double> { r.Next(3, 30) * r.NextDouble(), r.Next(3, 30) * r.NextDouble(), r.Next(3, 30) * r.NextDouble(), r.Next(3, 30) * r.NextDouble(), r.Next(3, 30) * r.NextDouble(), r.Next(3, 30) * r.NextDouble() };
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,177 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using System.Net.Http;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Components.Authorization;
|
||||
using Microsoft.AspNetCore.Components.Forms;
|
||||
using Microsoft.AspNetCore.Components.Routing;
|
||||
using Microsoft.AspNetCore.Components.Web;
|
||||
using Microsoft.AspNetCore.Components.Web.Virtualization;
|
||||
using Microsoft.JSInterop;
|
||||
using MP.Stats;
|
||||
using MP.Stats.Shared;
|
||||
using Blazorise;
|
||||
using Blazorise.Charts;
|
||||
using MP.Data;
|
||||
|
||||
namespace MP.Stats.Pages
|
||||
{
|
||||
public partial class Test
|
||||
{
|
||||
PieChart<double> pieChart;
|
||||
LineChart<double> lineChart;
|
||||
HorizontalBarChart<double> barChartHoriz;
|
||||
BarChart<double> barChart;
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
if (firstRender)
|
||||
{
|
||||
await HandleRedraw();
|
||||
}
|
||||
}
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
await HandleRedraw();
|
||||
}
|
||||
|
||||
|
||||
object horizontalLineChartOptions = new
|
||||
{
|
||||
//Title = new
|
||||
//{
|
||||
// Display = true,
|
||||
// Text = "Line chart sample"
|
||||
//},
|
||||
//Scales = new
|
||||
//{
|
||||
// XAxes = new object[]
|
||||
// {
|
||||
// new {
|
||||
// //ScaleLabel = new {
|
||||
// //Display = true, LabelString = "value" },
|
||||
// Stacked = true
|
||||
// }
|
||||
// }
|
||||
//},
|
||||
Tooltips = new
|
||||
{
|
||||
Mode = "nearest",
|
||||
Intersect = false
|
||||
}
|
||||
|
||||
,
|
||||
Hover = new
|
||||
{
|
||||
Mode = "nearest",
|
||||
Intersect = false
|
||||
}
|
||||
|
||||
,
|
||||
Legend = new
|
||||
{
|
||||
Display = true,
|
||||
FullWidth = true
|
||||
}
|
||||
|
||||
,
|
||||
AspectRatio = 2.5
|
||||
}
|
||||
|
||||
;
|
||||
private async Task HandleRedraw()
|
||||
{
|
||||
#if false
|
||||
await pieChart.Clear();
|
||||
await pieChart.AddLabelsDatasetsAndUpdate(Labels, GetPieChartDataset());
|
||||
await lineChart.Clear();
|
||||
await lineChart.AddLabelsDatasetsAndUpdate(Labels, GetLineChartDataset());
|
||||
await barChart.Clear();
|
||||
await barChart.AddLabelsDatasetsAndUpdate(Labels, GetBarChartDataset());
|
||||
await barChartHoriz.Clear();
|
||||
await barChartHoriz.AddLabelsDatasetsAndUpdate(Labels, GetHorizBarChartDataset());
|
||||
#endif
|
||||
// calcolo hist frequenza con EFCore: https://entityframeworkcore.com/knowledge-base/60871048/group-by-and-to-dictionary-in-ef-core-3-1
|
||||
var rawData = RandomizeData();
|
||||
var histDict = rawData.GroupBy(r => r).Select(g => new
|
||||
{
|
||||
g.Key,
|
||||
Count = g.Count()
|
||||
}).OrderBy(d => d.Key).ToDictionary(x => x.Key, x => x.Count.ToString());
|
||||
histData = histDict.Values.ToArray();
|
||||
histLabel = histDict.Keys.Select(x => $"{x}").ToArray();
|
||||
|
||||
|
||||
dataList = TSData(DateTime.Today.AddHours(-rawData.Count), rawData).Select(r => new chartJsData.chartJsTSerie()
|
||||
{ x = r.Key, y = r.Value}).ToList();
|
||||
}
|
||||
|
||||
protected string[]? histData { get; set; } = null;
|
||||
|
||||
protected string[]? histLabel { get; set; } = null;
|
||||
protected List<chartJsData.chartJsTSerie>? dataList { get; set; } = null;
|
||||
#if false
|
||||
|
||||
PieChartDataset<double> GetPieChartDataset()
|
||||
{
|
||||
return new PieChartDataset<double> { Label = "# of randoms", Data = RandomizeData(), BackgroundColor = backgroundColors, BorderColor = borderColors };
|
||||
}
|
||||
|
||||
LineChartDataset<double> GetLineChartDataset()
|
||||
{
|
||||
return new LineChartDataset<double> { Label = "# of randoms", Data = RandomizeData(), BackgroundColor = backgroundColors, BorderColor = borderColors, Fill = true, PointRadius = 2, BorderDash = new List<int> { } };
|
||||
}
|
||||
|
||||
BarChartDataset<double> GetBarChartDataset()
|
||||
{
|
||||
return new BarChartDataset<double> { Label = "# of randoms", Data = RandomizeData(), BackgroundColor = backgroundColors, BorderColor = borderColors, HoverBorderWidth = 5 };
|
||||
}
|
||||
|
||||
BarChartDataset<double> GetHorizBarChartDataset()
|
||||
{
|
||||
return new BarChartDataset<double> { Label = "# of randoms", Data = RandomizeData(), BackgroundColor = backgroundColors, BorderColor = borderColors, HoverBorderWidth = 5 };
|
||||
}
|
||||
#endif
|
||||
|
||||
string[] Labels = { "Red", "Blue", "Yellow", "Green", "Purple", "Orange" };
|
||||
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 List<int> RandomizeData()
|
||||
{
|
||||
double mean = 14;
|
||||
double stdDev = 2;
|
||||
var r = new Random(DateTime.Now.Millisecond);
|
||||
|
||||
|
||||
List<int> answ = new List<int>();
|
||||
for (int i = 0; i < 1000; i++)
|
||||
{
|
||||
double u1 = 1.0 - r.NextDouble(); // uniform (0,1] random doubles
|
||||
double u2 = 1.0 - r.NextDouble();
|
||||
double randStdNormal = Math.Sqrt(-2.0 * Math.Log(u1)) * Math.Sin(2.0 * Math.PI * u2);
|
||||
double randNormal = mean + stdDev * randStdNormal; // random normal (mean, stdDev^2)
|
||||
//answ.Add(r.Next(3, 30) * r.NextDouble());
|
||||
answ.Add((int)(randNormal * 10));
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
|
||||
private Dictionary<DateTime, decimal> TSData(DateTime inizio, List<int> yData)
|
||||
{
|
||||
Dictionary<DateTime, decimal> answ = new Dictionary<DateTime, decimal>();
|
||||
// usando i dati ricevuti aggiunge variabile x = tempo crescente
|
||||
int idx= 0;
|
||||
foreach (var item in yData)
|
||||
{
|
||||
answ.Add(inizio.AddHours(idx), item);
|
||||
idx++;
|
||||
}
|
||||
// restituisco!
|
||||
return answ;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<body>
|
||||
<i>Modulo statistiche MAPO</i>
|
||||
<h4>Versione: 6.14.2202.2117</h4>
|
||||
<h4>Versione: 6.14.2202.2119</h4>
|
||||
<br />
|
||||
Note di rilascio:
|
||||
<ul>
|
||||
|
||||
@@ -1 +1 @@
|
||||
6.14.2202.2117
|
||||
6.14.2202.2119
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<item>
|
||||
<version>6.14.2202.2117</version>
|
||||
<version>6.14.2202.2119</version>
|
||||
<url>https://nexus.steamware.net/repository/SWS/MP-STATS/stable/LAST/MP.Stats.zip</url>
|
||||
<changelog>https://nexus.steamware.net/repository/SWS/MP-STATS/stable/LAST/ChangeLog.html</changelog>
|
||||
<mandatory>false</mandatory>
|
||||
|
||||
Reference in New Issue
Block a user