2010-02-05 37 views
5

Tôi muốn xóa các điểm đánh dấu dữ liệu khỏi một LineSeries trong biểu đồ Silverlight của tôi. Cách duy nhất tôi tìm thấy trên web là thiết lập VisibilityProperty thành Collapse.Xóa (thu gọn) DataPoints trong một LineSeries?

// không hoạt động trong bản phát hành bộ công cụ SL hiện tại var collapseDataPointSetter = new Setter (Control.VisibilityProperty, Visibility.Collapsed);

Nhưng điều này không hoạt động đối với bản phát hành hiện tại của bộ công cụ SL. Làm cách nào để xóa hoặc ẩn Điểm đánh dấu dữ liệu trong bản phát hành hiện tại?

Trả lời

10

pantarhei,

Sử dụng các kiểu biểu đồ sau (với mẫu được tham chiếu) để ẩn các điểm dữ liệu. Tôi đã bao gồm các kiểu cho cả LineSeries và AreaSeries.

Chúc may mắn, Jim

<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

Cảm ơn bạn. Sẽ thử nó. Nhưng có vẻ là những gì tôi đang tìm kiếm. – pantarhei

+0

Hoạt động như một nét duyên dáng trong WPF ... Cảm ơn rất nhiều. – sprite

+0

Rất cám ơn @Jim cho mã ở trên. Tuy nhiên, một điều tôi đang thiếu với phương pháp này là màu đường kẻ trong LineSeries sẽ được sửa thành giá trị Nền được thiết lập theo kiểu LineDataPoint cho tất cả các chuỗi trong biểu đồ. Loại bỏ bộ nền cũng không giúp được gì, nó chỉ là màu sửa chữa khác. Có cách nào để các màu của đường thẳng tự động khác nhau đối với các chuỗi dòng khác nhau với cách tiếp cận trên không? –

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

Nó làm việc hoàn hảo cho tôi. – vijaykumar

4

Làm nó với phong cách theo ý kiến ​​của tôi không phải là phương pháp tốt nhất vì bạn vẫn còn có một số lượng lớn hình ảnh khi bạn cũng có rất nhiều datapoints như trong một biểu đồ chứng khoán.

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

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

Làm theo cách này bạn có ít hơn năm lần Hình ảnh so với khi bạn chỉ đặt một số kiểu.

+0

Đây là giải pháp dễ dàng so với việc chạm XAML. – Sid

3

Tôi đã sử dụng giải pháp của Jim (cảm ơn bạn rất nhiều bằng cách này, HUGE trợ giúp ở đó) và áp dụng nó cho mẫu biểu đồ mặc định.

Trong vùng bảng màu bạn có từ điển tài nguyên cho mỗi dòng trong chuỗi.

Sau đây là cách tôi đã có thể thoát khỏi nó sử dụng mẫu kiểm soát của Jim, và tôi có thể đặt nó trong mỗi ResourceDictonary vì vậy tôi không cần phải làm điều đó từng dòng

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

này làm việc cho tôi ít nhất, và nó sẽ tiết kiệm cho tôi rất nhiều thời gian (và đã tiết kiệm rất nhiều tóc của tôi trước khi tôi kéo nó ra)

Các vấn đề liên quan