diff --git a/Lux.UI/Components/Compo/Charts/PieChart.razor b/Lux.UI/Components/Compo/Charts/PieChart.razor index 609d0bcc..657ea923 100644 --- a/Lux.UI/Components/Compo/Charts/PieChart.razor +++ b/Lux.UI/Components/Compo/Charts/PieChart.razor @@ -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 pieLabels = new(); private List pieValues = new(); private List bgColors = new(); @@ -91,7 +95,8 @@ }, options = new { - responsive = true + responsive = true, + animation = false } }); } diff --git a/Lux.UI/wwwroot/lib/js/chartsInterop.js b/Lux.UI/wwwroot/lib/js/chartsInterop.js index 74552039..822f4d3e 100644 --- a/Lux.UI/wwwroot/lib/js/chartsInterop.js +++ b/Lux.UI/wwwroot/lib/js/chartsInterop.js @@ -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);