Add piechart da raffinare

This commit is contained in:
Samuele Locatelli
2022-02-25 12:15:17 +01:00
parent 8e5a392c8c
commit 0a26d475f9
7 changed files with 102 additions and 16 deletions
@@ -0,0 +1,87 @@
@using MP.Data
@inject IJSRuntime JSRuntime
<canvas id="@Id"></canvas>
@code {
[Parameter]
public string Id { get; set; } = "MyTs";
[Parameter]
public List<double> Data { get; set; } = null!;
[Parameter]
public string lineColor { get; set; } = "";
[Parameter]
public string backColor { get; set; } = "";
[Parameter]
public int lTens { get; set; } = 0;
/// <summary>
/// Inizializzazione rendering componente
///
/// partendo da qui:
/// https://www.williamleme.com/posts/2020/003-chartjs-blazor/
/// https://www.puresourcecode.com/dotnet/blazor/using-chart-js-with-blazor/
/// https://www.tutorialsteacher.com/csharp/csharp-anonymous-type
/// </summary>
/// <param name="firstRender"></param>
/// <returns></returns>
protected override async Task OnAfterRenderAsync(bool firstRender)
{
//if (!firstRender)
//{
await renderChart();
//}
}
/// <summary>
/// Inizializzazione rendering componente
///
/// partendo da qui:
/// https://www.williamleme.com/posts/2020/003-chartjs-blazor/
/// https://www.puresourcecode.com/dotnet/blazor/using-chart-js-with-blazor/
/// https://www.tutorialsteacher.com/csharp/csharp-anonymous-type
/// </summary>
/// <param name="firstRender"></param>
/// <returns></returns>
protected async Task renderChart()
{
// creazione di un oggetto anonymous type con tutte le opzioni da passare a chart.js
var config = new
{
type = "pie",
options = new
{
responsive = true,
// plugins = {
// legend =
// {
// position = "top",
// },
// title = {
// display = true,
// text = 'Chart.js Pie Chart'
// }
//}
},
data = new
{
datasets = new[]
{
new
{
data = Data,
borderColor= lineColor,
backgroundColor= backColor,
lineTension= lTens,
stepped= false,
label= "Temperatura Rilevata"
}
}
}
};
await JSRuntime.InvokeVoidAsync("setup", Id, config);
}
}
+1 -1
View File
@@ -4,7 +4,7 @@
<TargetFramework>net6.0</TargetFramework>
<RootNamespace>MP.Stats</RootNamespace>
<UserSecretsId>826e877c-ba70-4253-84cb-d0b1cafd4440</UserSecretsId>
<Version>6.14.2202.2511</Version>
<Version>6.14.2202.2512</Version>
</PropertyGroup>
<ItemGroup>
+3
View File
@@ -50,5 +50,8 @@
<div class="col-6">
<Line Id="TestLineTS" DataTS="@dataList" lineColor="rgb(7, 173, 236)" backColor="rgba(107, 223, 255, 0.3)" lTens="@lineTens"></Line>
</div>
<div class="col-6">
<PieChart Id="Testpie" Data="@randData" lineColor="rgb(7, 173, 236)" backColor="rgba(107, 223, 255, 0.3)"></PieChart>
</div>
</div>
+8 -12
View File
@@ -132,16 +132,10 @@ namespace MP.Stats.Pages
#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
randData = RandomizeData();
var histDict = randData.GroupBy(r => r).Select(g => new
{
g.Key,
Count = g.Count()
@@ -151,10 +145,10 @@ namespace MP.Stats.Pages
// calcolo i valori raggruppati in numGroup...
int numGroup = (int)Math.Sqrt(numRec);
double minVal = rawData.Min();
double maxVal = rawData.Max();
double minVal = randData.Min();
double maxVal = randData.Max();
double step = (maxVal - minVal) / numGroup;
var histDictGroup = rawData.GroupBy(r => ((int)Math.Round((r - minVal) / step)) * step + minVal).Select(g => new
var histDictGroup = randData.GroupBy(r => ((int)Math.Round((r - minVal) / step)) * step + minVal).Select(g => new
{
g.Key,
Count = g.Count()
@@ -164,7 +158,7 @@ namespace MP.Stats.Pages
dataList = TSData(DateTime.Today.AddHours(-rawData.Count), rawData).Select(r => new chartJsData.chartJsTSerie()
dataList = TSData(DateTime.Today.AddHours(-randData.Count), randData).Select(r => new chartJsData.chartJsTSerie()
{ x = r.Key, y = r.Value }).ToList();
}
@@ -176,6 +170,8 @@ namespace MP.Stats.Pages
protected string[]? histGroupLabel { get; set; } = null;
protected List<double> randData { get; set; } = new List<double>();
protected List<chartJsData.chartJsTSerie>? dataList { get; set; } = null;
#if false
+1 -1
View File
@@ -1,6 +1,6 @@
<body>
<i>Modulo statistiche MAPO</i>
<h4>Versione: 6.14.2202.2511</h4>
<h4>Versione: 6.14.2202.2512</h4>
<br />
Note di rilascio:
<ul>
+1 -1
View File
@@ -1 +1 @@
6.14.2202.2511
6.14.2202.2512
+1 -1
View File
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<item>
<version>6.14.2202.2511</version>
<version>6.14.2202.2512</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>