diff --git a/MP.Stats/Components/ChartJs/BarPlot.razor b/MP.Stats/Components/ChartJs/BarPlot.razor index 4a799e78..bf9c0864 100644 --- a/MP.Stats/Components/ChartJs/BarPlot.razor +++ b/MP.Stats/Components/ChartJs/BarPlot.razor @@ -1,5 +1,125 @@ - +@using MP.Data +@inject IJSRuntime JSRuntime + +@code { + [Parameter] + public string Id { get; set; } = "MyHist"; + + [Parameter] + public string Legenda { get; set; } = "Legenda"; + + [Parameter] + public bool Horizontal { get; set; } = false; + [Parameter] + public string[]? Data { get; set; } + + [Parameter] + public string[]? Labels { get; set; } + + [Parameter] + public List lineColor { get; set; } = new List(); + [Parameter] + public List backColor { get; set; } = new List(); + + protected override async Task OnAfterRenderAsync(bool 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, tipo verticale + 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 + } + }; + // creazione di un oggetto anonymous type con tutte le opzioni da passare a chart.js, tipo verticale + var configHor = new + { + type = "bar", + options = new + { + indexAxis = "y", + 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 + } + }; + if (Horizontal) + { + await JSRuntime.InvokeVoidAsync("setup", Id, configHor); + } + else + { + await JSRuntime.InvokeVoidAsync("setup", Id, config); + } + } + } +} diff --git a/MP.Stats/Components/ChartJs/BarPlot.razor.cs b/MP.Stats/Components/ChartJs/BarPlot.razor.cs deleted file mode 100644 index 400b2f2b..00000000 --- a/MP.Stats/Components/ChartJs/BarPlot.razor.cs +++ /dev/null @@ -1,144 +0,0 @@ -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.ChartJs -{ - public partial class BarPlot - { - [Inject] - IJSRuntime JSRuntime { get; set; } - - [Parameter] - public string Id { get; set; } = "MyHist"; - - [Parameter] - public string Legenda { get; set; } = "Legenda"; - - [Parameter] - public bool Horizontal { get; set; } = false; - [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, tipo verticale - 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 - } - }; - // creazione di un oggetto anonymous type con tutte le opzioni da passare a chart.js, tipo verticale - var configHor = new - { - type = "bar", - options = new - { - indexAxis = "y", - 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 - } - }; - if (Horizontal) - { - await JSRuntime.InvokeVoidAsync("setup", Id, configHor); - } - else - { - await JSRuntime.InvokeVoidAsync("setup", Id, config); - } - } - } -} \ No newline at end of file diff --git a/MP.Stats/Components/ChartJs/Line.razor b/MP.Stats/Components/ChartJs/Line.razor index 6bcc1e83..82558606 100644 --- a/MP.Stats/Components/ChartJs/Line.razor +++ b/MP.Stats/Components/ChartJs/Line.razor @@ -10,11 +10,11 @@ [Parameter] public List DataTS { get; set; } = null!; - + [Parameter] - public string lineColor { get; set; } = ""; + public List lineColor { get; set; } = new List(); [Parameter] - public string backColor { get; set; } = ""; + public List backColor { get; set; } = new List(); [Parameter] public int lTens { get; set; } = 0; diff --git a/MP.Stats/Components/ChartJs/PieChart.razor b/MP.Stats/Components/ChartJs/PieChart.razor index b792e394..b1c7cfff 100644 --- a/MP.Stats/Components/ChartJs/PieChart.razor +++ b/MP.Stats/Components/ChartJs/PieChart.razor @@ -12,9 +12,9 @@ public List Data { get; set; } = null!; [Parameter] - public string lineColor { get; set; } = ""; + public List lineColor { get; set; } = new List(); [Parameter] - public string backColor { get; set; } = ""; + public List backColor { get; set; } = new List(); [Parameter] public int lTens { get; set; } = 0; @@ -30,10 +30,7 @@ /// protected override async Task OnAfterRenderAsync(bool firstRender) { - //if (!firstRender) - //{ await renderChart(); - //} } /// @@ -55,28 +52,34 @@ options = new { responsive = true, + plugins = new + { + legend = new + { + position = "top" + }, + title = new + { + display = true, + text = "Chart.js Pie Chart" + } + } // 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" } } diff --git a/MP.Stats/Components/ChartJs/StepLine.razor b/MP.Stats/Components/ChartJs/StepLine.razor index 5a332e51..bb36481a 100644 --- a/MP.Stats/Components/ChartJs/StepLine.razor +++ b/MP.Stats/Components/ChartJs/StepLine.razor @@ -10,11 +10,11 @@ [Parameter] public List DataTS { get; set; } = null!; - + [Parameter] - public string lineColor { get; set; } = ""; + public List lineColor { get; set; } = new List(); [Parameter] - public string backColor { get; set; } = ""; + public List backColor { get; set; } = new List(); /// /// Inizializzazione rendering componente @@ -28,10 +28,7 @@ /// protected override async Task OnAfterRenderAsync(bool firstRender) { - //if (!firstRender) - //{ await renderChart(); - //} } /// diff --git a/MP.Stats/MP.Stats.csproj b/MP.Stats/MP.Stats.csproj index 4253468b..6ec18fa2 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.2512 + 6.14.2202.2518 diff --git a/MP.Stats/Pages/Test.razor b/MP.Stats/Pages/Test.razor index c2d76c75..4c81435e 100644 --- a/MP.Stats/Pages/Test.razor +++ b/MP.Stats/Pages/Test.razor @@ -39,19 +39,19 @@ *@
- +
- +
- +
- +
-
- +
+
diff --git a/MP.Stats/Pages/Test.razor.cs b/MP.Stats/Pages/Test.razor.cs index a9cdc253..0c98050d 100644 --- a/MP.Stats/Pages/Test.razor.cs +++ b/MP.Stats/Pages/Test.razor.cs @@ -160,6 +160,9 @@ namespace MP.Stats.Pages dataList = TSData(DateTime.Today.AddHours(-randData.Count), randData).Select(r => new chartJsData.chartJsTSerie() { x = r.Key, y = r.Value }).ToList(); + + lineColors = new List() { "rgba(255, 99, 132, 1)", "rgba(255, 159, 64, 1)", "rgba(255, 205, 86, 1)", "rgba(75, 192, 192, 1)", "rgba(54, 162, 235, 1)", "rgba(153, 102, 255, 1)", "rgba(201, 203, 207, 1)" }; + bgColors = new List() { "rgba(255, 99, 132, 0.3)", "rgba(255, 159, 64, 0.3)", "rgba(255, 205, 86, 0.3)", "rgba(75, 192, 192, 0.3)", "rgba(54, 162, 235, 0.3)", "rgba(153, 102, 255, 0.3)", "rgba(201, 203, 207, 0.3)" }; } protected string[]? histData { get; set; } = null; @@ -172,6 +175,9 @@ namespace MP.Stats.Pages protected List randData { get; set; } = new List(); + protected List bgColors = new List(); + protected List lineColors = new List(); + protected List? dataList { get; set; } = null; #if false @@ -199,8 +205,8 @@ namespace MP.Stats.Pages string[] Labels = { "Red", "Blue", "Yellow", "Green", "Purple", "Orange" }; #if false - List backgroundColors = new List { 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 borderColors = new List { 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 backgroundColors = new List { ChartColor.Fromrgbaa(255, 99, 132, 0.2f), ChartColor.Fromrgbaa(54, 162, 235, 0.2f), ChartColor.Fromrgbaa(255, 206, 86, 0.2f), ChartColor.Fromrgbaa(75, 192, 192, 0.2f), ChartColor.Fromrgbaa(153, 102, 255, 0.2f), ChartColor.Fromrgbaa(255, 159, 64, 0.2f) }; + List borderColors = new List { ChartColor.Fromrgbaa(255, 99, 132, 1f), ChartColor.Fromrgbaa(54, 162, 235, 1f), ChartColor.Fromrgbaa(255, 206, 86, 1f), ChartColor.Fromrgbaa(75, 192, 192, 1f), ChartColor.Fromrgbaa(153, 102, 255, 1f), ChartColor.Fromrgbaa(255, 159, 64, 1f) }; #endif private List RandomizeData() diff --git a/MP.Stats/Resources/ChangeLog.html b/MP.Stats/Resources/ChangeLog.html index 84485819..51665d80 100644 --- a/MP.Stats/Resources/ChangeLog.html +++ b/MP.Stats/Resources/ChangeLog.html @@ -1,6 +1,6 @@ Modulo statistiche MAPO -

Versione: 6.14.2202.2512

+

Versione: 6.14.2202.2518


Note di rilascio:
    diff --git a/MP.Stats/Resources/VersNum.txt b/MP.Stats/Resources/VersNum.txt index bd6c22d1..a90a4ecd 100644 --- a/MP.Stats/Resources/VersNum.txt +++ b/MP.Stats/Resources/VersNum.txt @@ -1 +1 @@ -6.14.2202.2512 +6.14.2202.2518 diff --git a/MP.Stats/Resources/manifest.xml b/MP.Stats/Resources/manifest.xml index c23d66ac..c7d348d3 100644 --- a/MP.Stats/Resources/manifest.xml +++ b/MP.Stats/Resources/manifest.xml @@ -1,6 +1,6 @@ - 6.14.2202.2512 + 6.14.2202.2518 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