2010-02-05 42 views
5

我想从我的Silverlight图表中的LineSeries中删除数据点标记。我在网上找到的唯一方法是将VisibilityProperty设置为“折叠”。删除(折叠)LineSeries中的DataPoints?

//不在当前SL工具包版本中工作 var collapseDataPointSetter = new Setter(Control.VisibilityProperty,Visibility.Collapsed);

但是这不适用于SL工具包的当前版本。如何在当前版本中删除或隐藏DataPoint标记?

回答

10

pantarhei,

使用下面的图表样式(含参照的模板)隐藏的数据点。我已经包含LineSeries和AreaSeries的样式。

祝你好运,吉姆

<ControlTemplate x:Key="CommonAreaSeriesDataPointTemplate" TargetType="charting:AreaDataPoint"> 
    <!--Comment out data points from the default template; just an empty template--> 
    <Grid x:Name="Root" Opacity="1"> 
     <!--<ToolTipService.ToolTip> 
      <StackPanel Margin="2,2,2,2"> 
       <ContentControl Content="{TemplateBinding FormattedDependentValue}" /> 
       <ContentControl Content="{TemplateBinding FormattedIndependentValue}" /> 
      </StackPanel> 
     </ToolTipService.ToolTip> 
     <Ellipse StrokeThickness="{TemplateBinding BorderThickness}" Stroke="{TemplateBinding BorderBrush}" Fill="{TemplateBinding Background}" />--> 
    </Grid> 
</ControlTemplate> 
<Style x:Key="CommonAreaSeriesDataPoint" TargetType="charting:AreaDataPoint"> 
    <Setter Property="Background" Value="{StaticResource CommonAreaSeriesBackground}" /> 
    <Setter Property="Template" Value="{StaticResource CommonAreaSeriesDataPointTemplate}" /> 
</Style> 
<Style x:Key="CommonAreaSeriesPath" TargetType="Path"> 
    <Setter Property="StrokeThickness" Value="1" /> 
    <Setter Property="Stroke" Value="DarkGray" /> 
    <Setter Property="Effect" Value="{StaticResource DialogDropShadow}" /> 
</Style> 
<ControlTemplate x:Key="CommonLineSeriesDataPointTemplate" TargetType="charting:LineDataPoint"> 
    <!--Comment out data points from the default template; just an empty template--> 
    <Grid x:Name="Root" Opacity="1"> 
     <!--<ToolTipService.ToolTip> 
      <StackPanel Margin="2,2,2,2"> 
       <ContentControl Content="{TemplateBinding FormattedDependentValue}" /> 
       <ContentControl Content="{TemplateBinding FormattedIndependentValue}" />--> 
     <!--Example of how to access the bound business object--> 
     <!--<ContentControl Content="{Binding Amount}" DataContext="{TemplateBinding DataContext}" />--> 
     <!--</StackPanel> 
     </ToolTipService.ToolTip>--> 
     <!--<Ellipse StrokeThickness="{TemplateBinding BorderThickness}" Stroke="{TemplateBinding BorderBrush}" Fill="{TemplateBinding Background}" />--> 
    </Grid> 
</ControlTemplate> 
<Style x:Key="CommonLineSeriesDataPoint" TargetType="charting:LineDataPoint"> 
    <Setter Property="IndependentValueStringFormat" Value="{}{0:yyyy}" /> 
    <Setter Property="DependentValueStringFormat" Value="{}{0:c0}" /> 
    <Setter Property="Background" Value="#FF0077CC" /> 
    <Setter Property="BorderBrush" Value="White" /> 
    <Setter Property="BorderThickness" Value="2" /> 
    <Setter Property="IsTabStop" Value="False" /> 
    <Setter Property="Template" Value="{StaticResource CommonLineSeriesDataPointTemplate}" /> 
</Style> 
<Style x:Key="CommonLineSeriesPolyline" TargetType="Polyline"> 
    <Setter Property="StrokeThickness" Value="5" /> 
    <Setter Property="Effect" Value="{StaticResource DialogDropShadow}" /> 
</Style> 
<!-- Implicit non-Key'd Styles BasedOn Common Explicit Key'd Styles above --> 
<Style TargetType="charting:AreaSeries"> 
    <Setter Property="DataPointStyle" Value="{StaticResource CommonAreaSeriesDataPoint}" /> 
    <Setter Property="PathStyle" Value="{StaticResource CommonAreaSeriesPath}" /> 
</Style> 
<Style TargetType="charting:LineSeries"> 
    <Setter Property="DataPointStyle" Value="{StaticResource CommonLineSeriesDataPoint}" /> 
    <Setter Property="PolylineStyle" Value="{StaticResource CommonLineSeriesPolyline}" /> 
</Style> 
+0

谢谢。将尝试它。但似乎是我在找什么。 – pantarhei 2010-02-11 07:05:07

+0

像WPF中的魅力一样工作...非常感谢。 – sprite 2010-08-31 08:58:23

+0

非常感谢上面的代码@Jim。尽管如此,我仍然错过了这种方法,LineSeries中的线条颜色将固定到图表中所有系列的LineDataPoint样式中设置的背景值。移除背景设置器也无济于事,它只是一种不同的修复颜色。采用上述方法,线条颜色对于不同线条系列是否有自动变化的方法? – 2011-11-23 10:56:06

1
<charting:LineSeries.DataPointStyle> 
          <Style TargetType="charting:LineDataPoint"> 
           <Setter Property="Visibility" Value="Collapsed"/> 
           <Setter Property="Background" Value="violet"/> 
           <Setter Property="Opacity" Value="0" /> 
          </Style> 
         </charting:LineSeries.DataPointStyle> 

+0

它完美地工作。 – vijaykumar 2011-11-07 11:46:13

4

与风格做这在我看来是不是最好的方法,因为你仍然有视觉效果的一个巨大的量时,也有很多数据点像股票图表一样。

public class LineSeriesEx : LineSeries 
{ 
    protected override DataPoint CreateDataPoint() 
    { 
     return new EmptyDataPoint(); 
    } 
} 

public class EmptyDataPoint : DataPoint 
{ 
    // As the method name says, this DataPoint is empty. 
} 

以这种方式做,您的视觉效果几乎比设置某种风格少五倍。

+0

与触摸XAML相比,这是一个简单的解决方案。 – Sid 2016-03-30 12:16:30

3

我使用了Jim的解决方案(非常感谢你,很有帮助),并将其应用于默认图表模板。

在调色板区域中,您有系列中每行的资源字典。

这里是我是如何能够用吉姆的控制模板,以摆脱它,我可以把它放在每个ResourceDictonary所以我没有用线

<toolkit:ResourceDictionaryCollection> 
<ResourceDictionary> 
<!-- I wanted a solid color brush so I just went ahead and defined it in the palette--> 
<SolidColorBrush x:Key="Background" Color="Green"/> 
<Style x:Key="DataPointStyle" TargetType="Control"> 
<Setter Property="Background" Value="{StaticResource Background}"/> 
<!-- below is where I entered Jim's control template into the default palette defined--> 
<Setter Property="Template"> 
<ControlTemplate TargetType="charting:LineDataPoint"> 
<Grid x:Name="Root" Opacity="1"/> 
</ControlTemplate> 
</Setter.Value> 
</Setter> 
</Style> 
</ResourceDictionary> 
</toolkit:ResourceDictionaryCollection> 

这个工作对做线至少我是这样,它会为我节省很多时间(并且在我拔出之前已经为我节省了很多头发)