Skip to content

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

kendo-bot
Copy link
Collaborator

No description provided.

@kendo-bot kendo-bot requested a review from a team as a code owner April 16, 2025 14:52
@xristianstefanov xristianstefanov self-assigned this Apr 16, 2025
@xristianstefanov xristianstefanov added the merge-to-production Use this label to get a comment to choose whether to merge the PR to production label Apr 16, 2025
Copy link
Contributor

Hello @xristianstefanov,

Check the below option if you would like to automatically generate PR to production. The automation uses the branch for the cherry-pick, and then will delete the branch. Please, do not delete it manually.

  • create PR to production

Comment on lines +40 to +96
<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"
}
];
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<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"
}
];
}
<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 {
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"
}
];
public class GraphDataPoint
{
public required string Color { get; set; }
public required int Value { get; set; }
public required string Label { get; set; }
}
}

Change the data collection property name to PascalCase and move the GraphDataModel last in the code block


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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.
Stacked Charts are designed to display the combined values of multiple series stacked together. Assigning unique colors to individual data points in this scenario can reduce the visual clarity of the stack relationships and prevent the legend from accurately representing the data.


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:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Here is an example configuration that applies a specific color to each series in a stacked bar chart:
Here is an example configuration that applies a specific color to each `ChartSeries` in a Stacked Bar Chart:

}
];
}
`````
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
`````


Here is an example configuration that applies a specific color to each series in a stacked bar chart:

`````Razor
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
`````Razor
````RAZOR

@Tsvetomir-Hr
Copy link
Contributor

You can also add, ##See Also section for CEO

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merge-to-production Use this label to get a comment to choose whether to merge the PR to production
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants