Creating a dashed CustomLine on a chart

3 posts, 0 answers
  1. Rob
    Rob avatar
    8 posts
    Member since:
    Jan 2013

    Posted 14 Nov 2013 Link to this post

    Hi,

    I'm trying to draw a CustomLine on a add, I want it styled so it appears dashed.

    I am creating the line in code here....
    CustomLine line = new CustomLine();
    line.Style = (Style)Application.Current.FindResource("DashedCustomLine");
    line.Stroke = Brushes.Black;
    line.StrokeThickness = 1;
    line.YIntercept = 0;
    line.Slope = 1;

    The style is then....
    <Style x:Key="DashedCustomLine" TargetType="telerikCharting:CustomLine">
        <Setter Property="StrokeDashArray" Value="5,2" />
    </Style>

    However it seems there isn't a StrokeDashArray property on CustomLine, what property should I be using, or how should I be achieving this.

    I only wish to draw a simple line of identity on the chart, ie. x = y.

    Thanks
  2. Rob
    Rob avatar
    8 posts
    Member since:
    Jan 2013

    Posted 18 Nov 2013 Link to this post

    Anyone?
  3. UI for WPF is Visual Studio 2017 Ready
  4. Evgenia
    Admin
    Evgenia avatar
    1406 posts

    Posted 19 Nov 2013 Link to this post

    Hello Craig,

    Indeed there is no DashArray property for Custom Line annotations. What I can suggest is that you create a dummy (fake) line series with custom style like this:
    public partial class MainPage : UserControl
     
    {
     
        public MainPage()
     
        {
     
            InitializeComponent();
     
      
     
            List<ChartData> data = new List<ChartData>();
     
            data.Add(new ChartData() { YValue = 1 });
     
            data.Add(new ChartData() { YValue = 2 });
     
      
     
            Style pathStyle1 = new Style(typeof(Path));
     
            pathStyle1.Setters.Add(new Setter(Shape.StrokeDashArrayProperty, "1"));
     
            pathStyle1.Setters.Add(new Setter(Shape.StrokeProperty, new SolidColorBrush(Colors.Cyan)));
     
            pathStyle1.Setters.Add(new Setter(Shape.StrokeThicknessProperty, 3));
     
      
     
            Style lineStyle1 = new Style(typeof(Telerik.Windows.Controls.Charting.SelfDrawingSeries));
     
            lineStyle1.Setters.Add(new Setter(SelfDrawingSeries.BorderLineStyleProperty, pathStyle1));
     
      
     
            SeriesMapping seriesMapping = new SeriesMapping { LegendLabel = "TEST" };
     
            seriesMapping.ItemMappings.Add(new ItemMapping("YValue", DataPointMember.YValue));
     
            seriesMapping.SeriesDefinition = new LineSeriesDefinition() { SeriesStyle = lineStyle1, ShowItemLabels = false, ShowPointMarks = false };
     
      
     
            RadChart1.SeriesMappings.Add(seriesMapping);
     
            RadChart1.ItemsSource = data;
     
        }
     
    }
     
      
     
    public class ChartData
     
    {
     
        public double YValue
     
        {
     
            get;
     
            set;
     
        }
     
    }

    Here's the lineStyle1 applied above:
    <Style x:Name="lineStyle1" TargetType="telerikCharting:SelfDrawingSeries">
                    <Setter Property="BorderLineStyle">
                        <Setter.Value>
                            <Style TargetType="Path">
                                <Setter Property="StrokeDashArray" Value="1"/>
                                <Setter Property="Stroke" Value="Black" />
                                <Setter Property="StrokeThickness" Value="3" />
                            </Style>
                        </Setter.Value>
                    </Setter>
                </Style>

    Regards,
    Evgenia
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
Back to Top