代码之家  ›  专栏  ›  技术社区  ›  devployment

删除(折叠)LineSeries中的数据点?

  •  5
  • devployment  · 技术社区  · 16 年前

    我想从Silverlight图表的LineSeries中删除数据点标记。我在网上找到的唯一方法是设置VisibilityProperty崩溃。

    //不在当前的SL工具包版本中工作 var collapsedatapointsetter=新的setter(control.visibilityproperty,visibility.collapsed);

    但这对当前版本的SL工具包不起作用。如何在当前版本中删除或隐藏数据点标记?

    4 回复  |  直到 14 年前
        1
  •  10
  •   Jim McCurdy    16 年前

    潘塔黑

    使用以下图表样式(带参考模板)隐藏数据点。我已经包括了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>
    
        2
  •  4
  •   DaveShaw Thishin    14 年前

    在我看来,使用样式并不是最好的方法,因为当您拥有大量数据点(如股票图表中的数据点)时,仍然有大量的视觉效果。

    public class LineSeriesEx : LineSeries
    {
        protected override DataPoint CreateDataPoint()
        {
            return new EmptyDataPoint();
        }
    }
    
    public class EmptyDataPoint : DataPoint
    {
        // As the method name says, this DataPoint is empty.
    }
    

    这样做的话,你的视觉效果几乎比你刚设定的风格少五倍。

        3
  •  3
  •   Sharon    14 年前

    我使用了Jim的解决方案(顺便说一下,非常感谢您的帮助),并将其应用于默认的图表模板。

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

    下面是我如何使用Jim的控件模板摆脱它的方法,我可以将它放在每个ResourceDictory中,这样我就不必一行一行地做它了。

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

    这至少对我有用,而且会节省我很多时间(而且在我拔出头发之前已经省了很多头发)

        4
  •  1
  •   vijaykumar    15 年前
    <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>
    

    推荐文章