Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
220
How to make MajorGridline in dashed style on XamWebChart?
posted

Hey guys , any idea how to do it ? Thanks .

 

  • 30692
    Suggested Answer
    Offline posted

    If you get creative with the styling you can do something like this:

    Markup:

    <UserControl x:Class="SilverlightApplication21.MainPage"
        mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480"
        xmlns:igChart="clr-namespace:Infragistics.Silverlight.Chart;assembly=Infragistics.Silverlight.DataVisualization.Chart.v9.2"
        xmlns:win="clr-namespace:System.Windows;assembly=System.Windows"
        xmlns:sys="clr-namespace:System;assembly=mscorlib"
        xmlns:local="clr-namespace:SilverlightApplication21">
       
        <UserControl.Resources>
            <Style x:Key="LineStyle" TargetType="igChart:Mark">
                <Setter Property="StrokeThickness" Value=".5"/>
                <Setter Property="Stroke" Value="#FFE6EFF7"/>
                <Setter Property="Fill" Value="#FFE6EFF7"/>
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="igChart:Mark">
                            <Grid x:Name="parentGrid">
                                <Grid.Resources>
                                    <local:DoublingConverter x:Key="DoublingConverter"/>
                                </Grid.Resources>
                                <local:BoundsRectangle x:Name="Bounds" />
     
                                <Path UseLayoutRounding="True" Stroke="{TemplateBinding Stroke}"
                                      StrokeThickness="{Binding Path=StrokeThickness, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource DoublingConverter}}"
                                      StrokeDashArray="3"
                                      Data="{Binding ElementName=Bounds, Path=PathData, Mode=OneWay}">
                                </Path>
                            </Grid>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
        </UserControl.Resources>
        <Grid x:Name="LayoutRoot">
     
     
            <igChart:XamWebChart>
                <igChart:XamWebChart.Axes>
                    <igChart:Axis AxisType="PrimaryY">
                        <igChart:Axis.MajorGridline>
                            <igChart:GridlineGroup Stroke="Red" StrokeThickness="3" GridlineStyle="{StaticResource LineStyle}" />
                        </igChart:Axis.MajorGridline>
                    </igChart:Axis>
                </igChart:XamWebChart.Axes>
     
                <igChart:XamWebChart.Series>
                    <igChart:Series>
     
                        <igChart:Series.DataPoints>
                            <igChart:DataPoint Value="1" />
                            <igChart:DataPoint Value="2" />
                            <igChart:DataPoint Value="3" />
                            <igChart:DataPoint Value="4" />
                            <igChart:DataPoint Value="5" />
                        </igChart:Series.DataPoints>
                    </igChart:Series>
                </igChart:XamWebChart.Series>
            </igChart:XamWebChart>
        </Grid>
    </UserControl>

    Code Behind (Sorry about the VB, forgot to change the project type, let me know if you have any problem translating):

     

    Partial Public Class MainPage
        Inherits UserControl
     
        Public Sub New()
            InitializeComponent()
        End Sub
     
    End Class
     
    Public Class BoundsRectangle
        Inherits Panel
     
        Public Shared PathDataProperty As DependencyProperty = _
            DependencyProperty.Register("PathData", GetType(GeometryGroup), _
                                        GetType(BoundsRectangle), _
                                        New PropertyMetadata(AddressOf PathDataPropertyChanged))
     
        Public Sub New()
            AddHandler Me.SizeChanged, AddressOf OnSizeChanged
        End Sub
     
        Public Property PathData() As GeometryGroup
            Get
                Return CType(GetValue(PathDataProperty), GeometryGroup)
            End Get
            Set(ByVal value As GeometryGroup)
                SetValue(PathDataProperty, value)
            End Set
        End Property
     
        Private Sub OnSizeChanged(ByVal sender As Object, ByVal args As SizeChangedEventArgs)
            Dim newWidth As Double = args.NewSize.Width
           
            Dim newData As New GeometryGroup
            Dim top As New LineGeometry
            top.StartPoint = New Point(0, 0)
            top.EndPoint = New Point(newWidth, 0)
     
            newData.Children.Add(top)
     
            PathData = newData
        End Sub
     
        Private Shared Sub PathDataPropertyChanged(ByVal sender As DependencyObject, _
                                                   ByVal args As DependencyPropertyChangedEventArgs)
        End Sub
     
    End Class
     
    Public Class DoublingConverter
        Implements IValueConverter
     
        Public Function Convert(ByVal value As Object, ByVal targetType As System.Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements System.Windows.Data.IValueConverter.Convert
            If value IsNot Nothing AndAlso TypeOf value Is Double Then
                Return value * 2.0
            End If
            Return Nothing
        End Function
     
        Public Function ConvertBack(ByVal value As Object, ByVal targetType As System.Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements System.Windows.Data.IValueConverter.ConvertBack
            Throw New NotImplementedException
        End Function
    End Class

    -Graham