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

Line loosing dashed style after rebind

2 Answers 27 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Ola
Top achievements
Rank 1
Ola asked on 24 Jan 2012, 11:37 PM
Hi,

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

2 Answers, 1 is accepted

Sort by
0
Sia
Telerik team
answered on 27 Jan 2012, 10:54 AM
Hello Ola,

In my opinion you hit a limitation of the Silverlight framework. Please check this forum thread where a solution is suggested and let us know how it works on your end.

Kind regards,
Sia
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Ola
Top achievements
Rank 1
answered on 27 Jan 2012, 11:15 AM
The solution using ZoomScrollSettingsPropertyChanged worked!

Thank you!!!

Regards,
Ola
Tags
Chart
Asked by
Ola
Top achievements
Rank 1
Answers by
Sia
Telerik team
Ola
Top achievements
Rank 1
Share this question
or