This is a migrated thread and some comments may be shown as answers.

RadLegendControl Colours do not match associated Chart

2 Answers 70 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Chris
Top achievements
Rank 1
Chris asked on 23 May 2019, 08:29 AM

G'day,

I have a Chart area that I am adding any number of Series to dynamically from a file that my program loads. This can be any number of Series, I've managed to load a file that drew more than 100 lines on my chart. This part of it has been working quite well and it must be done dynamically due to loading the data from a file (I cannot think of another way to do it, at least).

In cleaning it up and adding a few nicer features to it, I am looking at adding a Legend for the chart.

I followed the guides from the Legend Control page and I was able to successfully add a Legend for my graph. However the Legend's colour set does not match my Chart's (DefaultDark at the moment for testing).

The XAML code for my chart is as follows:

<telerikChart:RadCartesianChart x:Name="MainChart" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="10,10,10,10" PaletteName="DefaultDark" Grid.Column="1">
    <telerikChart:RadCartesianChart.Grid>
        <telerikChart:CartesianChartGrid MajorLinesVisibility="XY"/>
    </telerikChart:RadCartesianChart.Grid>
    <telerikChart:RadCartesianChart.Behaviors>
        <telerikChart:ChartPanAndZoomBehavior ZoomMode="Both" PanMode="Both"/>
        <telerikChart:ChartTrackBallBehavior InfoMode="Multiple">
            <telerikChart:ChartTrackBallBehavior.LineStyle>
                <Style TargetType="Polyline">
                    <Setter Property="Stroke" Value="Tomato"/>
                    <Setter Property="StrokeThickness" Value="2"/>
                    <Setter Property="StrokeDashArray" Value="1,2"/>
                </Style>
            </telerikChart:ChartTrackBallBehavior.LineStyle>
            <telerikChart:ChartTrackBallBehavior.IntersectionTemplate>
                <DataTemplate>
                    <Ellipse Width="10" Height="10" Fill="Tomato"/>
                </DataTemplate>
            </telerikChart:ChartTrackBallBehavior.IntersectionTemplate>
        </telerikChart:ChartTrackBallBehavior>
    </telerikChart:RadCartesianChart.Behaviors>
    <telerikChart:RadCartesianChart.VerticalAxis>
        <telerikChart:LinearAxis x:Name="Vertical" Title="Pressure (kPa)" Minimum="0"/>
    </telerikChart:RadCartesianChart.VerticalAxis>
    <telerikChart:RadCartesianChart.HorizontalAxis>
        <telerikChart:LinearAxis x:Name="Horizontal" Title="Depth (mm)"/>
    </telerikChart:RadCartesianChart.HorizontalAxis>
</telerikChart:RadCartesianChart>

 

And to add in the LegendControl:

<telerikPrimitives:RadLegendControl x:Name="LegendForChart" LegendProvider="{Binding ElementName=MainChart}"/>

 

For some reason the items in the Legend are always blue instead of matching the colours from the Palette/matching the colours from each Series on the Chart.

What am I missing that could make these colours line up appropriately? Any help would be appreciated.

This is the code that adds the series to the chart, if needed.

ScatterLineSeries scatterLineSeries = new ScatterLineSeries
{
    ItemsSource = graphData,
    XValueBinding = new PropertyNameDataPointBinding("Depth"),
    YValueBinding = new PropertyNameDataPointBinding("Pressure"),
    DisplayName = $"G:{groupNumber} I:{insertionNumber}",
    LegendTitle = $"G:{groupNumber} I:{insertionNumber}",
};
 
MainChart.Series.Add(scatterLineSeries);

2 Answers, 1 is accepted

Sort by
0
Accepted
Didi
Telerik team
answered on 24 May 2019, 08:12 AM
Hello Chris,

Thank you for the provided snippets and the detailed explanation.

Regarding to the Palette colors, they are not applied correctly to the Legend when series are drawn with ContainerVisual. We have this logged in our Feedback portal and here is the link:

https://feedback.telerik.com/uwp/1365816-chart-palette-colors-are-not-applied-to-the-legend-when-series-are-drawn-with-containervisual

Solution:

Currently the workaround I could suggest is to create a CustomContainerVisualFactory class that inherits from ContainerVisualsFactory. Override the CanDrawContainerVisual method and return false. For more details check the CustomContainerVisualFactory.cs file inside the attached project.

I hope I was helpful.

Regards,
Didi
Progress Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Chris
Top achievements
Rank 1
answered on 27 May 2019, 01:41 AM

G'day Didi,

Thank you for the information and the provided solution. I've integrated this into my Project and it looks to be working as expected now with the Legend colours.

Tags
Chart
Asked by
Chris
Top achievements
Rank 1
Answers by
Didi
Telerik team
Chris
Top achievements
Rank 1
Share this question
or