public async Task RefreshChartData() { IEnumerable <DashboardChartData> newDatas = await GenerateChartDatas.Invoke(); await Chart.Clear(); await Chart.AddLabels(newDatas.Select(x => x.Label).ToArray()); List <string> colors = new List <string>(); for (int i = 0; i < newDatas.Count(); i++) { string sliceColor = null; if (i < 9) { sliceColor = SliceColorGenerator?.Invoke(i); } if (!string.IsNullOrWhiteSpace(sliceColor)) { colors.Add(sliceColor); } else { colors.Add(DEFAULT_SLICE_COLOR); } } PieChartDataset <long> newChartDataset = new PieChartDataset <long>() { Data = newDatas.Select(x => x.Value).ToList(), BackgroundColor = colors, BorderColor = colors }; CurrentDataset = newChartDataset; await Chart.AddDatasetsAndUpdate(newChartDataset); }