Search code examples
xamlsilverlightchartstoolkit

Silverlight Toolkit Chart Removing Gridlines


I have inherited the work on a StackedColumnSeries Chart and which I turned into a StackedBarSeries, so the graph is on its side, I have two problems:

  1. The minimum value does not start at zero.
  2. I cannot hide the vertical gridlines.

Please can anybody help me.

The xaml code is below:

<Style x:Key="XAxisLabel" TargetType="charting:AxisLabel">
    <Setter Property="StringFormat" Value="{}{0:#,k}"></Setter>
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="charting:AxisLabel">
                <TextBlock Text="{TemplateBinding FormattedContent}" />
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

<Style x:Key="YAxisLabel" TargetType="charting:AxisLabel">
    <Setter Property="StringFormat" Value=""></Setter>
    <Setter Property="Visibility" Value="Collapsed"></Setter>
</Style>

<Style x:Key="SummaryGraphStyle" TargetType="charting:Chart">
    <Setter Property="PlotAreaStyle">
        <Setter.Value>
            <Style TargetType="Grid">
                <Setter Property="HorizontalAlignment" Value="Left"/>
                <Setter Property="Background" Value="Transparent"/>
            </Style>
        </Setter.Value>
    </Setter>

    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="charting:Chart">
                <Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="1" Background="{TemplateBinding Background}" Padding="{TemplateBinding Padding}">
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="*"/>
                        </Grid.RowDefinitions>
                        <!--<datavis:Title Content="{TemplateBinding Title}" Style="{TemplateBinding TitleStyle}"/>-->
                        <Grid Margin="0,0,0,15" Grid.Row="1">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*"/>
                            </Grid.ColumnDefinitions>

                            <Charting_Primitives:EdgePanel x:Name="ChartArea">
                                <Grid ShowGridLines="False" HorizontalAlignment="Left" Canvas.ZIndex="-1"/>

                                <Border BorderBrush="Black" BorderThickness="1,0,0,0" Canvas.ZIndex="10"/>

                            </Charting_Primitives:EdgePanel>
                        </Grid>

                    </Grid>
                </Border>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>


<Grid x:Name="LayoutRoot" Background="Transparent">
    <Grid ShowGridLines="False" HorizontalAlignment="Center" x:Name="SummaryGraphGrid">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto" />
        </Grid.ColumnDefinitions>
        <charting:Chart Loaded="Loaded" Width="{Binding ElementName=Graph, Path=GraphWidth}" Grid.Column="0" BorderBrush="Transparent"  x:Name="SummaryGraph"
                                        Style="{StaticResource SummaryGraphStyle}" BorderThickness="0" 
                                        VerticalAlignment="Stretch" HorizontalAlignment="Center">

            <charting:Chart.Axes>
                <charting:LinearAxis AxisLabelStyle="{StaticResource YAxisLabel}" Minimum="0" Location="Right" ShowGridLines="False" BorderThickness="0" Orientation="Y" Background="Transparent"/>
                <charting:CategoryAxis AxisLabelStyle="{StaticResource XAxisLabel}" Margin="5,0,0,0" Location="Left" ShowGridLines="False" BorderThickness="0" Background="Transparent" Orientation="X" />
            </charting:Chart.Axes>
        </charting:Chart>
    </Grid>
</Grid>

Image of barchart with lines etc


Solution

  • I managed to find a piece of code that will fix this, the code was added the code behind.

    ((StackedBarSeries)this.SummaryGraph.Series[0]).DependentAxis = new LinearAxis() { Minimum = 0, Orientation = AxisOrientation.X };
    

    enter image description here