I'm setting the colors of a StackingColumn100 chart via the PointColorMapping property, and the colors of the legend aren't matching the fill colors (I'm using 19.3.0.44).
I found a similar issue from 2019 with the same issue, but no reports on this same issue in Blazor:
https://www.syncfusion.com/forums/148064/stacked-bar-chart-legend-doesnt-match-column-color
<ChartSeriesCollection>
@foreach (var chartData in ChartDataList)
{
<ChartSeries DataSource="@chartData" XName="StatusName" YName="Count" ColumnSpacing="0.2" ColumnWidth="0.8" PointColorMapping="Color"
Name="@(GetSeriesName(chartData))" LegendShape="LegendShape.Rectangle"
Type="ChartSeriesType.StackingColumn100">
<ChartMarker>
<ChartDataLabel Visible="true" Position="Syncfusion.Blazor.Charts.LabelPosition.Middle">
<ChartDataLabelFont FontWeight="600" />
</ChartDataLabel>
</ChartMarker>
</ChartSeries>
} </ChartSeriesCollection>
|
<SfChart>
<ChartEvents OnLegendItemRender="LegendEvent"></ChartEvents>
</SfChart>
@code{
public void LegendEvent(LegendRenderEventArgs args)
{
if (args.Text == "UK")
{
args.Fill = "red";
}
else if (args.Text == "Germany")
{
args.Fill = "blue";
}
}
} |
Thank your for this explanation. The provided callback did work, but I opted to use the workaround below to set the fill color instead (seemed a little simpler).
Fill="@(chartData.Select(a => a.Color).FirstOrDefault())"
|
<SfChart>
<ChartSeriesCollection>
@foreach (SeriesData series in SeriesCollection)
{
<ChartSeries Fill="@series.Color" Type="ChartSeriesType.StackingColumn100">
</ChartSeries>
}
</ChartSeriesCollection>
</SfChart> |