This question is locked. New answers and comments are not allowed.
Hi
My team are in the progress of converting an existing solution from using RadChart to RadChartView due to performance issues. I'm currently working on the legend items, which is handled in a special way. Basically, each legend item can have 2 colors. One color for the box/icon and one color for the legend item text.
The way I've set this up at the moment is like this:
- As the chart series is created in code (not xaml) I set the LegendSettings to be a SeriesLegendSetting and set the Title accordingly. All series are of type LineSeries.
- In XAML I build a new ItemTemplate:
As you can see, the border's background is set to the legend item's MarkerFill property, and the text color is set to the legend item's MarkerStroke property.
In code, I've been trying various ways of setting the MarkerFill and MarkerStroke property. Currently, my code looks like this:
The Blue and Green color being for illustrative purposes, but the main concept being I'm trying to set this manually. When preparing to show a chart on the screen, I add items from the _legendItems collection to the chart's LegendItems collection:
When debugging at this point, the chart's LegendItems collection has the correct amount of items with the correct colors.
However, when the chart is rendered live, the series' color is completely overwriting my custom MarkerStroke/Fill properties.
Is there any way I can force the chart to use my legend items instead of auto-generating them from the series?
My team are in the progress of converting an existing solution from using RadChart to RadChartView due to performance issues. I'm currently working on the legend items, which is handled in a special way. Basically, each legend item can have 2 colors. One color for the box/icon and one color for the legend item text.
The way I've set this up at the moment is like this:
- As the chart series is created in code (not xaml) I set the LegendSettings to be a SeriesLegendSetting and set the Title accordingly. All series are of type LineSeries.
- In XAML I build a new ItemTemplate:
<telerik:RadLegend.ItemTemplate> <DataTemplate> <Grid Margin="10,5,0,5"> <Grid.ColumnDefinitions> <ColumnDefinition Width="Auto" /> <ColumnDefinition Width="*" /> </Grid.ColumnDefinitions> <Border Grid.Column="0" CornerRadius="3" Height="15" Width="15" Background="{Binding Path=MarkerFill}" /> <TextBlock Grid.Column="1" Text="{Binding Path=Title}" Foreground="{Binding Path=MarkerStroke}" Margin="3,0,0,0" /> </Grid> </DataTemplate> </telerik:RadLegend.ItemTemplate>As you can see, the border's background is set to the legend item's MarkerFill property, and the text color is set to the legend item's MarkerStroke property.
In code, I've been trying various ways of setting the MarkerFill and MarkerStroke property. Currently, my code looks like this:
private void SetLegendItem(GraphAxisYDTO axisDTO, GraphVariableDTO variableDTO){ if (_legendItems == null) _legendItems = new LegendItemCollection(); _legendItems.Add(new LegendItem { MarkerFill = new SolidColorBrush(Colors.Blue), MarkerStroke = new SolidColorBrush(Colors.Green), Title = variableDTO.Legend });}The Blue and Green color being for illustrative purposes, but the main concept being I'm trying to set this manually. When preparing to show a chart on the screen, I add items from the _legendItems collection to the chart's LegendItems collection:
foreach (var legendItem in _legendItems){ chart.LegendItems.Add(legendItem);}When debugging at this point, the chart's LegendItems collection has the correct amount of items with the correct colors.
However, when the chart is rendered live, the series' color is completely overwriting my custom MarkerStroke/Fill properties.
Is there any way I can force the chart to use my legend items instead of auto-generating them from the series?