LineSeries Dashed / Dotted Line Style

3 posts, 0 answers
  1. pratik mehta
    pratik mehta avatar
    17 posts
    Member since:
    May 2010

    Posted 29 Jul 2010 Link to this post

    Hi,

    I want to display some lines in chart as dotted or dashed. I am using below code to display line as dotted as dashed.
    In my code  i am not generating Legend items manually.

    private Style GetLineSeriesStyle(int lineType)
       {
           Style lineStyle;
           Style pathStyle;
           switch (lineType)
           {
               case 1:
                   pathStyle = new Style(typeof(System.Windows.Shapes.Path));
                   pathStyle.Setters.Add(new Setter(Shape.StrokeDashArrayProperty, "2"));
                   pathStyle.Setters.Add(new Setter(Shape.StrokeThicknessProperty, 2));
                   pathStyle.Setters.Add(new Setter(Shape.StrokeProperty, new SolidColorBrush(Colors.Yellow)));
                   lineStyle = new Style(typeof(Telerik.Windows.Controls.Charting.SelfDrawingSeries));
                   lineStyle.Setters.Add(new Setter(SelfDrawingSeries.BorderLineStyleProperty, pathStyle));
                   break;
               case 2:
                   pathStyle = new Style(typeof(System.Windows.Shapes.Path));
                   pathStyle.Setters.Add(new Setter(Shape.StrokeDashArrayProperty, "2"));
                   pathStyle.Setters.Add(new Setter(Shape.StrokeThicknessProperty, 2));
                   pathStyle.Setters.Add(new Setter(Shape.StrokeProperty, new SolidColorBrush(Colors.Red)));
                   lineStyle = new Style(typeof(Telerik.Windows.Controls.Charting.SelfDrawingSeries));
                   lineStyle.Setters.Add(new Setter(SelfDrawingSeries.BorderLineStyleProperty, pathStyle));
                   break;
               default:
                   Random oRandom = new Random();
                   Color oColor = Color.FromArgb(Convert.ToByte(oRandom.Next(100, 255)), Convert.ToByte(oRandom.Next(100, 255)), Convert.ToByte(oRandom.Next(100, 255)), Convert.ToByte(oRandom.Next(100, 255)));
                   pathStyle = new Style(typeof(System.Windows.Shapes.Path));
                   pathStyle.Setters.Add(new Setter(Shape.StrokeProperty, new SolidColorBrush(oColor)));
                   pathStyle.Setters.Add(new Setter(Shape.StrokeLineJoinProperty, "2"));
                   pathStyle.Setters.Add(new Setter(Shape.StrokeThicknessProperty, 2));
                   lineStyle = new Style(typeof(Telerik.Windows.Controls.Charting.SelfDrawingSeries));
                   lineStyle.Setters.Add(new Setter(SelfDrawingSeries.BorderLineStyleProperty, pathStyle));
                   break;
           }
           return lineStyle;
       }

     

     

     


    Now in follwing example My series color and legend color are mismatching.
    i tried by commenting below code

    pathStyle.Setters.Add(new Setter(Shape.StrokeProperty, new SolidColorBrush(Colors.Red)));

    in above code base. but in that case i am not able to see any line in my chart area.

    Can you please let me know hot display dashed ot dotted line without touching Color property.
    And i do not want to add Legend manually.


    Thanks

    Pratik Mehta

     

     

  2. pratik mehta
    pratik mehta avatar
    17 posts
    Member since:
    May 2010

    Posted 02 Aug 2010 Link to this post

    can anyone help me on this?

    Thanks

    Pratik Mehta

  3. Vladimir Milev
    Admin
    Vladimir Milev avatar
    1061 posts

    Posted 02 Aug 2010 Link to this post

    Hi pratik mehta,

    The recommended approach to styling all elements consistently, including legend items would be the CreateItemStyle delegate. Also, check this blog post for details.

    Regards,
    Vladimir Milev
    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
Back to Top