2010-02-05 45 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> 

這個工作對做線至少我是這樣,它會爲我節省很多時間(並且在我拔出之前已經爲我節省了很多頭髮)