How to draw a dashed line?

5 posts, 0 answers
  1. Dr. Hartmut Kocher
    Dr. Hartmut Kocher avatar
    6 posts
    Member since:
    Dec 2009

    Posted 18 May 2010 Link to this post

    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
  2. Sia
    Admin
    Sia avatar
    667 posts

    Posted 20 May 2010 Link to this post

    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.
  3. UI for WPF is Visual Studio 2017 Ready
  4. David
    David avatar
    57 posts
    Member since:
    Apr 2011

    Posted 12 Dec 2011 Link to this post

    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.
  5. Sia
    Admin
    Sia avatar
    667 posts

    Posted 15 Dec 2011 Link to this post

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

  6. David
    David avatar
    57 posts
    Member since:
    Apr 2011

    Posted 27 Dec 2011 Link to this post

    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.
Back to Top
UI for WPF is Visual Studio 2017 Ready