隐藏x轴UWP图表

时间:2017-11-27 12:32:34

标签: c# xaml uwp winrt-xaml-toolkit

有没有一种简单的方法来隐藏我的图表的x轴?我想使用XAML禁用它。

这是我当前显示X和Y轴的XAML代码。我在stackoverflow上尝试了一些解决方案,但它们都没有为我工作。

<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 个答案:

答案 0 :(得分:1)

  

隐藏x轴UWP图表

x-Axis实际上是图表中的CategoryAxis。您可以重新定义样式以删除CategoryAxis内容。例如:

<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>

您可以找到已完成的默认样式CategoryAxis here,并将其更改为您想要的内容。