Powered by MSDN

US - English
NEW! Silverlight 5 is available Learn More

Dashed line in Lineseries RSS

4 replies

Last post Apr 15, 2009 08:40 PM by Tom Adcock

(0)
  • mithunster

    mithunster

    Member

    4 Points

    45 Posts

    Dashed line in Lineseries

    Apr 02, 2009 07:19 PM | LINK

    How can i have a dashed (dotted) line series instead of a solid line? I am using the March toolkit.

     Thanks.

  • fullsailrick

    fullsailrick

    Contributor

    3699 Points

    829 Posts

    Re: Dashed line in Lineseries

    Apr 02, 2009 09:42 PM | LINK

    Hi! Every line has a StrokeDashOffset property, and you can give that a value to produce a dashed line.
  • JustinAngel

    JustinAngel

    Contributor

    4455 Points

    606 Posts

    Re: Dashed line in Lineseries

    Apr 02, 2009 10:25 PM | LINK

    Yep, and it's pretty easy.

    We'll start off with a normal LineSeries chart.

    <chartingToolkit:Chart x:Name="chart">

        <chartingToolkit:LineSeries ItemsSource="{Binding}"

          DependentValuePath="Value"

          IndependentValuePath="Key" />

    </chartingToolkit:Chart>

                chart.DataContext = new KeyValuePair<int, int>[]

                {

                    new KeyValuePair<int, int>(10, 1),

                    new KeyValuePair<int, int>(20, 3),

                    new KeyValuePair<int, int>(30, 2),

                    new KeyValuePair<int, int>(40, 4)

                };

    Next, We'd like to specify a that the Polyline which is being drawn by the LineSeries has a Polyline.StrokeDashArray.
    We'll do that by changing the LineSeries.PolylineStyle.

    <chartingToolkit:Chart x:Name="chart">

        <chartingToolkit:LineSeries ItemsSource="{Binding}"

                                   DependentValuePath="Value"

                                   IndependentValuePath="Key">

            <chartingToolkit:LineSeries.PolylineStyle>

                <Style TargetType="Polyline">

                    <Setter Property="StrokeDashArray" Value="2 3 2" />

                </Style>

            </chartingToolkit:LineSeries.PolylineStyle>

        </chartingToolkit:LineSeries>

    </chartingToolkit:Chart>

     You might want to read up on how Path.StrokeDashArray works if you'd like to configure the spaces between dashed areas.

    Sincerely,

     

    --
    Justin Angel,
    Twitter @ http://twitter.com/JustinAngel
    Blog @ http://JustinAngel.net
  • Tom Adcock

    Tom Adcock

    Member

    25 Points

    10 Posts

    Re: Re: Dashed line in Lineseries

    Apr 13, 2009 08:02 PM | LINK

     Hi,

    Can you provide an example where a dashed line is set in the code? I need to set a dashed line and color dynamically.

     

    Thanks Tom 

  • Tom Adcock

    Tom Adcock

    Member

    25 Points

    10 Posts

    Re: Re: Re: Dashed line in Lineseries

    Apr 15, 2009 08:40 PM | LINK

    I'll answer my own question: 

     Style style4 = new Style(typeof(Control));
    Setter st4 = new Setter(Control.BackgroundProperty, new SolidColorBrush(Color.FromArgb(255,0,255,255)));
    style4.Setters.Add(st4);
    LineSeries4.DataPointStyle = style4;
              
                
    Style style5 = new Style(typeof(Polyline));
    Setter st5 = new Setter(Polyline.StrokeDashArrayProperty, "3");
    style5.Setters.Add(st5);
    LineSeries4.PolylineStyle = style5;

    Tom