From b760d4fa1a6e761934645810e14cced40df97427 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Tue, 22 Feb 2022 17:27:38 +0100 Subject: [PATCH] Update gestione pagina test con grafici --- MP.Stats/Components/ChartJsBar.razor | 5 ++ MP.Stats/Components/ChartJsBar.razor.cs | 97 +++++++++++++++++++++++++ MP.Stats/Components/ChartJsHist.razor | 82 --------------------- MP.Stats/MP.Stats.csproj | 2 +- MP.Stats/Pages/Test.razor | 2 +- MP.Stats/Pages/Test.razor.cs | 1 - MP.Stats/Resources/ChangeLog.html | 2 +- MP.Stats/Resources/VersNum.txt | 2 +- MP.Stats/Resources/manifest.xml | 2 +- 9 files changed, 107 insertions(+), 88 deletions(-) create mode 100644 MP.Stats/Components/ChartJsBar.razor create mode 100644 MP.Stats/Components/ChartJsBar.razor.cs delete mode 100644 MP.Stats/Components/ChartJsHist.razor diff --git a/MP.Stats/Components/ChartJsBar.razor b/MP.Stats/Components/ChartJsBar.razor new file mode 100644 index 00000000..4a799e78 --- /dev/null +++ b/MP.Stats/Components/ChartJsBar.razor @@ -0,0 +1,5 @@ + + + + + diff --git a/MP.Stats/Components/ChartJsBar.razor.cs b/MP.Stats/Components/ChartJsBar.razor.cs new file mode 100644 index 00000000..1488f52c --- /dev/null +++ b/MP.Stats/Components/ChartJsBar.razor.cs @@ -0,0 +1,97 @@ +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; + +namespace MP.Stats.Components +{ + public partial class ChartJsBar + { + [Inject] + IJSRuntime JSRuntime { get; set; } + + [Parameter] + public string Id { get; set; } = "MyHist"; + + [Parameter] + public string Legenda { get; set; } = "Legenda"; + [Parameter] + public string[]? Data { get; set; } + + [Parameter] + public string[]? Labels { get; set; } + + [Parameter] + public string lineColor { get; set; } = ""; + [Parameter] + public string backColor { get; set; } = ""; + protected override async Task OnAfterRenderAsync(bool firstRender) + { + //if (!firstRender) + //{ + await renderChart(); + //} + } + + /// + /// 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 + /// + /// + /// + protected async Task renderChart() + { + // creazione di un oggetto anonymous type con tutte le opzioni da passare a chart.js + var config = new + { + type = "bar", + options = new + { + responsive = true, + scales = new + { + yAxes = new + { + suggestedMin = 0, + display = true, + ticks = new + { + beginAtZero = true, + maxTicksLimit = 10 + } + } + } + }, + data = new + { + datasets = new[] { + new { + data = Data, + borderColor = lineColor, + backgroundColor = backColor, + borderWidth = 1, + label = Legenda + } + }, + labels = Labels + } + }; + await JSRuntime.InvokeVoidAsync("setup", Id, config); + } + } +} \ No newline at end of file diff --git a/MP.Stats/Components/ChartJsHist.razor b/MP.Stats/Components/ChartJsHist.razor deleted file mode 100644 index 3f1489e1..00000000 --- a/MP.Stats/Components/ChartJsHist.razor +++ /dev/null @@ -1,82 +0,0 @@ -@inject IJSRuntime JSRuntime - - - -@code { - - [Parameter] - public string Id { get; set; } = "MyHist"; - - [Parameter] - public string[]? Data { get; set; } - [Parameter] - public string[]? Labels { get; set; } - - [Parameter] - public string lineColor { get; set; } = ""; - [Parameter] - public string backColor { get; set; } = ""; - - - protected override async Task OnAfterRenderAsync(bool firstRender) - { - //if (!firstRender) - //{ - await renderChart(); - //} - } - - - /// - /// 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 - /// - /// - /// - protected async Task renderChart() - { - // creazione di un oggetto anonymous type con tutte le opzioni da passare a chart.js - var config = new - { - type = "bar", - options = new - { - responsive = true, - scales = new - { - yAxes = new - { - suggestedMin = 0, - display = true, - ticks = new - { - beginAtZero = true, - maxTicksLimit = 10 - } - } - } - }, - data = new - { - datasets = new[] - { - new - { - data = Data, - borderColor = lineColor, - backgroundColor = backColor, - borderWidth = 1, - label= "Freq. Osservate" - } - }, - labels = Labels - } - }; - await JSRuntime.InvokeVoidAsync("setup", Id, config); - } - -} \ No newline at end of file diff --git a/MP.Stats/MP.Stats.csproj b/MP.Stats/MP.Stats.csproj index 6139ae63..90a77dfc 100644 --- a/MP.Stats/MP.Stats.csproj +++ b/MP.Stats/MP.Stats.csproj @@ -4,7 +4,7 @@ net6.0 MP.Stats 826e877c-ba70-4253-84cb-d0b1cafd4440 - 6.14.2202.2216 + 6.14.2202.2217 diff --git a/MP.Stats/Pages/Test.razor b/MP.Stats/Pages/Test.razor index f2fbb822..cb7cd1c8 100644 --- a/MP.Stats/Pages/Test.razor +++ b/MP.Stats/Pages/Test.razor @@ -44,7 +44,7 @@ *@
- +
diff --git a/MP.Stats/Pages/Test.razor.cs b/MP.Stats/Pages/Test.razor.cs index 8603a75e..f625f32d 100644 --- a/MP.Stats/Pages/Test.razor.cs +++ b/MP.Stats/Pages/Test.razor.cs @@ -13,7 +13,6 @@ using Microsoft.AspNetCore.Components.Web.Virtualization; using Microsoft.JSInterop; using MP.Data; using MP.Stats; -using MP.Stats.Shared; namespace MP.Stats.Pages { diff --git a/MP.Stats/Resources/ChangeLog.html b/MP.Stats/Resources/ChangeLog.html index 535c583f..3a2b10b0 100644 --- a/MP.Stats/Resources/ChangeLog.html +++ b/MP.Stats/Resources/ChangeLog.html @@ -1,6 +1,6 @@ Modulo statistiche MAPO -

Versione: 6.14.2202.2216

+

Versione: 6.14.2202.2217


Note di rilascio:
    diff --git a/MP.Stats/Resources/VersNum.txt b/MP.Stats/Resources/VersNum.txt index c0b0ea90..2f232fea 100644 --- a/MP.Stats/Resources/VersNum.txt +++ b/MP.Stats/Resources/VersNum.txt @@ -1 +1 @@ -6.14.2202.2216 +6.14.2202.2217 diff --git a/MP.Stats/Resources/manifest.xml b/MP.Stats/Resources/manifest.xml index 2609579b..c874573a 100644 --- a/MP.Stats/Resources/manifest.xml +++ b/MP.Stats/Resources/manifest.xml @@ -1,6 +1,6 @@ - 6.14.2202.2216 + 6.14.2202.2217 https://nexus.steamware.net/repository/SWS/MP-STATS/stable/LAST/MP.Stats.zip https://nexus.steamware.net/repository/SWS/MP-STATS/stable/LAST/ChangeLog.html false