如何从此图表中删除X轴标签?

时间:2012-10-18 14:21:36

标签: c# windows-phone-7 silverlight-toolkit

保持自己的简洁,我希望删除标签或至少从我的X轴修改它们:

enter image description here

我似乎正在使用这个库的修改版本,它允许我使用一些通常在wp7中不起作用的工具。

xmlns:charting="clr-namespace:System.Windows.Controls.DataVisualization.Charting;assembly=System.Windows.Controls.DataVisualization.Toolkit"

这是目前的LineSeries定义:

<charting:Chart x:Name="chart" Title="Humidity Readings" Grid.Column="0" Grid.Row="0" Grid.ColumnSpan="2" Foreground="#FF3C58C8">
    <chartingToolkit:LineSeries x:Name="HumidityGraph" Title="Humidity" BorderThickness="2"  ItemsSource="{Binding Data}" IndependentValuePath="Time" DependentValuePath="Measurement"/>
</charting:Chart>

为了回应 chridam ,我尝试实施他的建议 - 没有成功。

            <charting:Chart x:Name="chart" Title="Humidity Readings" Grid.Column="0" Grid.Row="0" Grid.ColumnSpan="2" Foreground="#FF3C58C8">
                <charting:Chart.LegendStyle>
                    <Style TargetType="visualizationToolkit:Legend">
                        <Setter Property="Width" Value="0"/>
                        <Setter Property="Height" Value="0"/>
                    </Style>

                </charting:Chart.LegendStyle>
                <!--there doesn't seem to be an AxisLabelStyle that I can create a style in.-->

                    <Style x:Key="EmptyStyle" TargetType="charting:NumericAxisLabel">
                        <Setter Property="StringFormat" Value="" />
                        <Setter Property="Template">
                            <Setter.Value>
                                <ControlTemplate TargetType="charting:NumericAxisLabel">
                                    <TextBlock />
                                </ControlTemplate>
                            </Setter.Value>
                        </Setter>
                    </Style>
                <chartingToolkit:LineSeries x:Name="HumidityGraph" Title="Humidity" BorderThickness="2"  ItemsSource="{Binding Data}" IndependentValuePath="Time" DependentValuePath="Measurement" TransitionDuration="0:1:1.5" FontSize="18.667">
                    <charting:LinearAxis AxisLabelStyle="{StaticResource EmptyStyle}" Orientation="X" ShowGridLines="True"/>
                </chartingToolkit:LineSeries>
            </charting:Chart>

1 个答案:

答案 0 :(得分:1)

尝试为Axis Label指定样式,将StringFormat属性值设置为空

<chartingToolkit:CategoryAxis> 
   <chartingToolkit:CategoryAxis.AxisLabelStyle> 
      <Style TargetType="AxisLabel"> 
         <Setter Property="StringFormat" Value=""></Setter> 
      </Style> 
   </chartingToolkit:CategoryAxis.AxisLabelStyle> 
</chartingToolkit:CategoryAxis>

<强>更新 另一种方法是应用样式模板

<Style x:Key="EmptyStyle" TargetType="charting:NumericAxisLabel"> 
    <Setter Property="StringFormat" Value="" /> 
    <Setter Property="Template"> 
        <Setter.Value> 
            <ControlTemplate TargetType="charting:NumericAxisLabel"> 
                <TextBlock /> 
            </ControlTemplate> 
        </Setter.Value> 
    </Setter> 
</Style>

到此:

<charting:LineSeries.DependentRangeAxis>    
        <charting:LinearAxis AxisLabelStyle="{StaticResource EmptyStyle}"    
            Orientation="X"    
            ShowGridLines="True"/>    
</charting:LineSeries.DependentRangeAxis>

有关图表样式的更多资源,Styling a Silverlight Chart