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 lineColor = PointColorGenerator?.Invoke(i); if (!string.IsNullOrWhiteSpace(lineColor)) { colors.Add(lineColor); } else { colors.Add(DEFAULT_POINT_COLOR); } } LineChartDataset <DashboardChartDatasetYValue> newChartDataset = new LineChartDataset <DashboardChartDatasetYValue>() { Data = newDatas.Select(x => new DashboardChartDatasetYValue() { Y = x.Value, DataId = x.DataId }).ToList(), Fill = true, BackgroundColor = DEFAULT_FILL_COLOR, PointBackgroundColor = colors, PointBorderColor = colors, PointRadius = 3.5f }; CurrentDataset = newChartDataset; await Chart.AddDataSet(newChartDataset); await Chart.Update(); }
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); }
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 barColor = BarColorGenerator?.Invoke(i); if (!string.IsNullOrWhiteSpace(barColor)) { colors.Add(barColor); } else { colors.Add(DEFAULT_BAR_COLOR); } } BarChartDataset <BarChartDatasetXValue> newBarChartDataset = new BarChartDataset <BarChartDatasetXValue>() { Type = "horizontalBar", Data = newDatas.Select(x => new BarChartDatasetXValue() { X = x.Value, DataId = x.DataId }).ToList(), BackgroundColor = colors, BorderColor = colors, }; CurrentDataset = newBarChartDataset; await Chart.AddDatasetsAndUpdate(newBarChartDataset); }