Files
egwcorelib/EgwCoreLib.BlazorTest/Pages/TestMultiLine.razor.cs
T
2023-07-25 15:18:38 +02:00

97 lines
3.2 KiB
C#

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 EgwCoreLib.BlazorTest;
using EgwCoreLib.BlazorTest.Components;
using EgwCoreLib.BlazorTest.Shared;
using EgwCoreLib.Razor;
using EgwCoreLib.Razor.Data;
using static EgwCoreLib.Razor.Data.chartJsData;
namespace EgwCoreLib.BlazorTest.Pages
{
public partial class TestMultiLine
{
protected override async Task OnInitializedAsync()
{
currDS = null;
await Task.Delay(200);
await setupData();
}
protected List<chartJsData.chartJsDataSetXY>? currDS { get; set; } = null;
protected List<string>? ChLabels { get; set; } = null;
protected Random rnd = new Random();
private async Task setupData()
{
currDS = null;
List<chartJsData.chartJsDataSetXY> currDemo = new List<chartJsData.chartJsDataSetXY>();
ChLabels = new List<string>();
int numMesi = 6;
for (int iMese = 1; iMese <= numMesi; iMese++)
{
ChLabels.Add($"{iMese:00}");
}
for (int iSerie = 0; iSerie < 4; iSerie++)
{
// simulo 12 mesi...
List<chartJsXY> simData = new List<chartJsXY>();
for (int iMese = 1; iMese <= numMesi; iMese++)
{
simData.Add(new chartJsXY() { x = iMese, y = iMese + rnd.Next(-4, 4) });
}
int rCol = rnd.Next(0, 155);
int gCol = rnd.Next(0, 155);
int bCol = rnd.Next(0, 100);
chartJsData.chartJsDataSetXY singleData = new chartJsData.chartJsDataSetXY()
{
label = $"Data_{iSerie:00}",
data = simData,
borderColor = $"#{10 + rCol:X2}{30 + gCol:X2}{100 + bCol:X2}",
backgroundColor = $"rgba({60 + rCol},{80 + gCol},{155 + bCol},0.3)",
lineTension = 0,
stepped = iSerie % 5 == 0,
fill = iSerie % 3 == 0 ? "start" : "false"
};
// aggiungo
currDemo.Add(singleData);
}
currDS = currDemo;
await Task.Delay(10);
}
protected string[] histLabel(int num)
{
List<string> answ = new List<string>();
for (int i = 0; i < 50; i++)
{
answ.Add($"LBL_{i:00}");
}
return answ.ToArray();
}
protected string[] histData(int num)
{
List<string> answ = new List<string>();
for (int i = 0; i < 50; i++)
{
answ.Add($"{(double)(rnd.Next(10, 100)) / 10 + i}");
}
return answ.ToArray();
}
}
}