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

How to draw a dashed line?

4 Answers 355 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Dr. Hartmut Kocher
Top achievements
Rank 1
Dr. Hartmut Kocher asked on 18 May 2010, 02:40 PM
How can I draw a dashed line in a line chart? Is there a way to set the pen instead of the brush only?

Regards
Hartmut

4 Answers, 1 is accepted

Sort by
0
Sia
Telerik team
answered on 20 May 2010, 01:43 PM
Hello Dr. Hartmut Kocher,

You can use the following XAML:
<Window x:Class="WpfApplication2Branch.Window1"
    Title="Window1"
    xmlns:TelerikControls="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls"
    xmlns:telerik="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Charting"
    xmlns:chart="clr-namespace:Telerik.Windows.Controls.Charting;assembly=Telerik.Windows.Controls.Charting">
    <Grid x:Name="LayoutRoot">
        <Grid.Resources>
            <Style x:Key="DottedLineStyle" TargetType="chart:SelfDrawingSeries">
                <Setter Property="BorderLineStyle">
                    <Setter.Value>
                        <Style TargetType="Path">
                            <Setter Property="StrokeDashArray" Value="1 2 3"/>
                            <Setter Property="Stroke" Value="#FF74C0D3" />
                            <Setter Property="StrokeThickness" Value="2" />
                        </Style>
                    </Setter.Value>
                </Setter>
            </Style>
        </Grid.Resources>
        <telerik:RadChart  x:Name="RadChart1" />
    </Grid>
</Window>

and code-behind respectively:
series1.Definition = new LineSeriesDefinition();
 
RadChart1.DefaultView.ChartArea.SeriesStyles.LineSeriesStyle = this.LayoutRoot.Resources["DottedLineStyle"] as Style;

Hope this helps.

Regards,
Sia
the Telerik team

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 Public Issue Tracking system and vote to affect the priority of the items.
0
David
Top achievements
Rank 2
answered on 12 Dec 2011, 03:46 PM
Hi,

I'm unable to get this code working in Q3 2011. I've tried both this code that references BorderLineStyle as Path and the sample from:

http://www.telerik.com/help/wpf/radchart-styling-and-appearance-styling-chart-series.html

that references BorderLineStyle as Shape, however I get the following error message in both instances:

'#FF74C0D3' is not a valid value for property 'Stroke'.

What is the TargetType for the BorderLineStyle so that I can create a style for a LineSeriesDefinition? The code I'm using for the RadChart is as follows:

<telerik:RadChart>
  <telerik:RadChart.SeriesMappings>
    <telerik:SeriesMapping>
      <telerik:SeriesMapping.SeriesDefinition>
        <telerik:LineSeriesDefinition
          SeriesStyle="{StaticResource DottedLineStyle}" />
      </telerik:SeriesMapping.SeriesDefinition>
    </telerik:SeriesMapping>
  </telerik:RadChart.SeriesMappings>
</telerik:RadChart>


Kind regards,
Dave.
0
Sia
Telerik team
answered on 15 Dec 2011, 09:45 AM
Hello David,

I have tested the same style with the latest official version and everything works as expected. Please send us a sample runnable project which demonstrates the unwanted behavior. Thus we will do our best to provide you with a working solution. Thank you in advance for your cooperation.

Regards,
Sia
the Telerik team

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

0
David
Top achievements
Rank 2
answered on 27 Dec 2011, 10:05 AM
Hi,

I've done some more testing with my code and found the error I was encountering was not caused by Telerik and was an issue with how I was binding my resources. I can confirm that the code posted in this thread does work successfully.

Kind regards,
Dave.
Tags
Chart
Asked by
Dr. Hartmut Kocher
Top achievements
Rank 1
Answers by
Sia
Telerik team
David
Top achievements
Rank 2
Share this question
or