Aggiunta gestione chart dispose + fix commenti

This commit is contained in:
Samuele Locatelli
2025-12-18 12:31:05 +01:00
parent b795597e29
commit b3f2afbe0b
2 changed files with 10 additions and 21 deletions
+10 -5
View File
@@ -1,4 +1,5 @@
@inject IJSRuntime JSRuntime
@implements IDisposable
@code {
[Parameter]
@@ -26,8 +27,6 @@
bgColors = pieLabels.Select(l => PieColor.ContainsKey(l) ? PieColor[l] : "rgba(0,0,0,0.3)").ToList();
bordColors = bgColors.Select(c => c.Replace("0.3", "1")).ToList();
// await JSRuntime.InvokeVoidAsync("chartsInterop.createPieChart", CanvasId, pieLabels, values, bgColors);
await JSRuntime.InvokeVoidAsync("chartsInterop.createPieChart", CanvasId, new
{
type = "pie",
@@ -47,12 +46,17 @@
},
options = new
{
responsive = true
responsive = true,
animation = false
}
});
}
}
public void Dispose()
{
// Chiama il metodo JS per pulire il dizionario
_ = JSRuntime.InvokeVoidAsync("chartsInterop.destroyChart", CanvasId);
}
private List<string> pieLabels = new();
private List<double> pieValues = new();
private List<string> bgColors = new();
@@ -91,7 +95,8 @@
},
options = new
{
responsive = true
responsive = true,
animation = false
}
});
}
-16
View File
@@ -76,22 +76,6 @@
}
},
//createPieChart: function (canvasId, labels, values, bgColors) {
// const ctx = document.getElementById(canvasId);
// new Chart(ctx, {
// type: "pie",
// data: {
// labels: labels,
// datasets: [{
// data: values,
// backgroundColor: bgColors,
// borderColor: bgColors.map(c => c.replace("0.6", "1")),
// borderWidth: 2
// }]
// },
// options: { responsive: true }
// });
//},
createBarChart: function (canvasId, labels, datasets) {
const ctx = document.getElementById(canvasId);