I have a Chart with a couple of series. I want one of the series to display a dashed line. I also have a data grid, when I select a product from the grid the chart will display the data of the selected product.
First I tried to define a style and set it to the Serie in XAML:
<UserControl.Resources>
<Style x:Name="ForecastRedStyle" TargetType="charting:SelfDrawingSeries">
<Setter Property="BorderLineStyle">
<Setter.Value>
<Style TargetType="Path">
<Setter Property="StrokeDashArray" Value="1"/>
<Setter Property="Stroke" Value="#FF90362E" />
<Setter Property="StrokeThickness" Value="2" />
</Style>
</Setter.Value>
</Setter>
</Style>
</UserControl.Resources>
...
<telerik:SeriesMapping LegendLabel="Forecast 8-12">
<telerik:SeriesMapping.SeriesDefinition>
<telerik:LineSeriesDefinition ShowItemLabels="False" ShowItemToolTips="True"
ShowPointMarks="True" SeriesStyle="{StaticResource ForecastRedStyle}" />
</telerik:SeriesMapping.SeriesDefinition>
<telerik:SeriesMapping.ItemMappings>
<telerik:ItemMapping FieldName="StartDate"
DataPointMember="XValue" />
<telerik:ItemMapping FieldName="ForecastRed"
DataPointMember="YValue" />
</telerik:SeriesMapping.ItemMappings>
</telerik:SeriesMapping>
...
Result: It worked the first time the chart was displayed but as soon as I selected another product the style did not display anymore (the line was not dashed).
Second try: I put this in code behind.
private void gridProducts_SelectionChanged(object sender, SelectionChangeEventArgs e)
{
Style yellowStyle = new Style(typeof(Path));
yellowStyle.Setters.Add(new Setter(Shape.StrokeDashArrayProperty, "5,2"));
yellowStyle.Setters.Add(new Setter(Shape.StrokeProperty, "#FFC28F12"));
yellowStyle.Setters.Add(new Setter(Shape.StrokeThicknessProperty, 2));
Style yellowLineStyle = new Style(typeof(Telerik.Windows.Controls.Charting.LineSeries));
yellowLineStyle.Setters.Add(new Setter(LineSeries.BorderLineStyleProperty, yellowStyle));
Style redStyle = new Style(typeof(Path));
redStyle.Setters.Add(new Setter(Shape.StrokeDashArrayProperty, "1"));
redStyle.Setters.Add(new Setter(Shape.StrokeProperty, "#FF90362E"));
redStyle.Setters.Add(new Setter(Shape.StrokeThicknessProperty, 2));
Style redLineStyle = new Style(typeof(Telerik.Windows.Controls.Charting.LineSeries));
redLineStyle.Setters.Add(new Setter(LineSeries.BorderLineStyleProperty, redStyle));
radChart.SeriesMappings[2].SeriesDefinition = new LineSeriesDefinition();
radChart.SeriesMappings[3].SeriesDefinition = new LineSeriesDefinition();
radChart.SeriesMappings[2].SeriesDefinition = new LineSeriesDefinition() { SeriesStyle = yellowLineStyle, ShowItemLabels = false, ShowPointMarks = true, ShowItemToolTips = true };
radChart.SeriesMappings[3].SeriesDefinition = new LineSeriesDefinition() { SeriesStyle = redLineStyle, ShowItemLabels = false, ShowPointMarks = true, ShowItemToolTips = true };
}
Result: It works first time the chart is displayed. But it does not work when I select another product first time. But then it works every time I select another product after that.
Does anyone know what is going on here?
Regards,
Ola