Hide x-Axis UWP Chart

445 Views Asked by At

Is there a simple way to hide the x-Axis of my chart? I would like to disable it using XAML.

This is my current XAML code which displays the X and Y axes. I tried some solutions on stackoverflow but none of them worked for me.

<Charting:Chart x:Name="LineChart" Margin="0,100,0,0" HorizontalAlignment="Center" VerticalAlignment="Center" Width="800" Height="400">
    <Charting:LineSeries  Name="line_data" Margin="0" IndependentValuePath="Key" DependentValuePath="Value" IsSelectionEnabled="True"/>
</Charting:Chart>
1

There are 1 best solutions below

0
On

Hide x-Axis UWP Chart

The x-Axis actually is the CategoryAxis in chart. You could redefined the style to delete the CategoryAxis content. For example:

<Page.Resources>
   <Style TargetType="Charting:CategoryAxis">      
       <Setter Property="Template">
           <Setter.Value>
               <ControlTemplate TargetType="Charting:CategoryAxis">
                   <!--<Grid x:Name="AxisGrid" Background="{TemplateBinding Background}">
                       <dataVis:Title x:Name="AxisTitle" Style="{TemplateBinding TitleStyle}"  Visibility="Collapsed"/>
                   </Grid>-->
               </ControlTemplate>
           </Setter.Value>
       </Setter>
   </Style>
</Page.Resources>

<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" DataContext="{Binding}">
   <Charting:Chart
       Title="{Binding Title}"
       Width="600"
       Height="400"
       HorizontalAlignment="Center"
       VerticalAlignment="Center"
       DataContext="{Binding}" >    
       <Charting:LineSeries
           Title="Title"
           Margin="0"
           DependentValuePath="Amount"
           IndependentValuePath="Name"
           IsSelectionEnabled="True"
           ItemsSource="{Binding Data}" />  
   </Charting:Chart>
</Grid>

You could find the completed default style of CategoryAxis here and change it as what you want.