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);