blazorbootstrap
blazorbootstrap copied to clipboard
Chart background color not respected
When using the Pie chart we are trying to use custom background color for a specific data label. However when we set the background color in the PieChartDataSetData it isn't repsected and get's assigned a color from the PieChartDataSet in order of the list.
If we don't use a color list in PieChartDataSet all labels become black. Did we misconfigure the pie chart or is this an limitation at the moment?
How we create the pie chart:
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
statusChartBaseData = new ChartData
{
Labels = new List<string>(),
Datasets = new List<IChartDataset>() { new PieChartDataset() { Label = "Status", BackgroundColor = Colors.AsList, } }
};
await StatusChart.InitializeAsync(statusChartBaseData, statusPieChartOptions);
}
await base.OnAfterRenderAsync(firstRender);
}
How we populate the PieChartDataSetData. Our data is dynamic based on filters and api data that's why we populate later on and update.
var statuses = result.Data.GroupBy(status => status.Status);
await StatusChart.UpdateAsync(statusChartBaseData, statusPieChartOptions);
var i = 0;
foreach (var status in statuses)
{
await StatusChart.AddDataAsync(statusChartBaseData, status.Key, new PieChartDatasetData("Status", status.Count(), Colors.StatusColor(status.Key)));
}