-
Notifications
You must be signed in to change notification settings - Fork 77
Added new kb article chart-legend-colors-not-matching-stacked-bar-chart #2921
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
xristianstefanov
merged 6 commits into
master
from
new-kb-chart-legend-colors-not-matching-stacked-bar-chart-2f9c733521c0426bba39f12ddef04d98
May 5, 2025
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a0c1e6b
Added new kb article chart-legend-colors-not-matching-stacked-bar-chart
07f9089
Update knowledge-base/chart-legend-colors-not-matching-stacked-bar-ch…
xristianstefanov e456fad
Update knowledge-base/chart-legend-colors-not-matching-stacked-bar-ch…
xristianstefanov 963b48f
Update knowledge-base/chart-legend-colors-not-matching-stacked-bar-ch…
xristianstefanov 1a658f1
Update knowledge-base/chart-legend-colors-not-matching-stacked-bar-ch…
xristianstefanov 37ccd37
Update knowledge-base/chart-legend-colors-not-matching-stacked-bar-ch…
xristianstefanov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
97 changes: 97 additions & 0 deletions
97
knowledge-base/chart-legend-colors-not-matching-stacked-bar-chart.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
--- | ||
title: Legend Colors Do Not Match Data Points in Stacked Bar Chart | ||
description: Explains why the legend colors might not match the data points in a stacked bar chart and provides a solution. | ||
type: troubleshooting | ||
page_title: Ensure Legend Colors Match Data Points in Stacked Bar Charts | ||
slug: chart-kb-legend-colors-not-matching-stacked-bar-chart | ||
tags: charts, bar chart, stacked series, legend, color | ||
res_type: kb | ||
ticketid: 1684367 | ||
--- | ||
|
||
## Environment | ||
|
||
<table> | ||
<tbody> | ||
<tr> | ||
<td>Product</td> | ||
<td>Charts for Blazor</td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
|
||
## Description | ||
|
||
When creating a Chart with Stacked Series, the colors of the data points render correctly on the Chart itself, but the legend colors do not match the colors of the data points. This discrepancy occurs when using the `ColorField` parameter. | ||
|
||
## Cause | ||
|
||
This behavior is by design. Using the `ColorField` parameter to assign a unique color to each data point within a single series is supported in **non-stacked** Charts, but not in stacked Charts. | ||
|
||
Stacked Charts are designed to visualize the cumulative value of multiple series stacked atop one another. Applying individual colors to each data point in this context would compromise the visual clarity of the stack relationships and make it difficult for the legend to accurately reflect the data. | ||
|
||
## Solution | ||
|
||
To ensure that the legend colors match the data points in a stacked Chart, use the `Color` parameter of the `ChartSeries`. This parameter sets a uniform color for all data points (bars) within a single series and determines the color shown in the legend for that series. | ||
|
||
Here is an example configuration that applies a specific color to each series in a stacked bar chart: | ||
xristianstefanov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
`````Razor | ||
xristianstefanov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
<TelerikChart Width="100%" Height="100%"> | ||
<ChartSeriesItems> | ||
@foreach (var series in _graphDataPoints) | ||
{ | ||
<ChartSeries Field="@nameof(GraphDataPoint.Value)" | ||
Type="ChartSeriesType.Bar" | ||
Name="@series.Label" | ||
Color="@series.Color" | ||
Data="@([series])"> | ||
<ChartSeriesStack Enabled="true" /> | ||
</ChartSeries> | ||
} | ||
</ChartSeriesItems> | ||
<ChartLegend Position="ChartLegendPosition.Right" /> | ||
</TelerikChart> | ||
|
||
@code { | ||
public class GraphDataPoint | ||
{ | ||
public required string Color { get; set; } | ||
public required int Value { get; set; } | ||
public required string Label { get; set; } | ||
} | ||
|
||
private List<GraphDataPoint> _graphDataPoints { get; set; } = [ | ||
new GraphDataPoint | ||
{ | ||
Label = "Early Settlement Candidate", | ||
Value = 1024, | ||
Color = "#D46663" | ||
}, | ||
new GraphDataPoint | ||
{ | ||
Label = "Needs Discovery to Strategize", | ||
Value = 980, | ||
Color = "#F89995" | ||
}, | ||
new GraphDataPoint | ||
{ | ||
Label = "Potential Dispositive Candidate", | ||
Value = 1006, | ||
Color = "#FFC7C7" | ||
}, | ||
new GraphDataPoint | ||
{ | ||
Label = "Potential Trial Candidate", | ||
Value = 1003, | ||
Color = "#BCDCCF", | ||
}, | ||
new GraphDataPoint | ||
{ | ||
Label = "Settlement Candidate", | ||
Value = 987, | ||
Color = "#79C8AB" | ||
} | ||
]; | ||
} | ||
xristianstefanov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
````` | ||
xristianstefanov marked this conversation as resolved.
Show resolved
Hide resolved
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.