@using MP.Data @inject IJSRuntime JSRuntime @code { [Parameter] public string Id { get; set; } = "MyTs"; [Parameter] public List Data { get; set; } = null!; [Parameter] public string lineColor { get; set; } = ""; [Parameter] public string backColor { get; set; } = ""; [Parameter] public int lTens { get; set; } = 0; /// /// 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 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 = "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); } }