WPFToolkit图表 - 如何删除标记或更改标记大小?

时间:2010-09-15 07:11:42

标签: wpf xaml wpftoolkit

我无法完全看到如何删除WPFToolkit图中的标记。我可以看到它们是下面XAML中的省略号,但我似乎无法成功更改任何参数以获得更改它们的大小,或者删除它们。有什么想法吗?

以下是我一直在使用的XAML(仍然需要WPFToolkit)。

<Window x:Class="MyInternetUsage.EnginePerformance"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:chartingToolkit="clr-namespace:System.Windows.Controls.DataVisualization.Charting;assembly=System.Windows.Controls.DataVisualization.Toolkit" xmlns:local="clr-namespace:DataVisualizationDemos" xmlns:datavis="clr-namespace:System.Windows.Controls.DataVisualization;assembly=System.Windows.Controls.DataVisualization.Toolkit" Title="EnginePerformance" Height="277" Width="371">
    <Grid>
        <Grid.Resources>
            <local:EngineMeasurementCollection x:Key="EngineMeasurementCollection"/>

            <!--  charting:LineSeries  -->
            <Style TargetType="chartingToolkit:LineSeries">
                <Setter Property="IsTabStop" Value="False" />
                <Setter Property="PolylineStyle">
                    <Setter.Value>
                        <Style TargetType="Polyline">
                            <Setter Property="StrokeThickness" Value="1" />
                        </Style>
                    </Setter.Value>
                </Setter>
            </Style>

            <!--  charting:LineDataPoint  -->
            <Style TargetType="chartingToolkit:LineDataPoint">
                <Setter Property="Background" Value="Orange" />
                <Setter Property="BorderBrush" Value="Red" />
                <Setter Property="BorderThickness" Value="5" />
                <Setter Property="IsTabStop" Value="False" />
                <Setter Property="Width" Value="1000" />
                <Setter Property="Height" Value="1000" />
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="chartingToolkit:LineDataPoint">
                            <Grid x:Name="Root" Opacity="0">
                                <VisualStateManager.VisualStateGroups>
                                    <VisualStateGroup x:Name="CommonStates">
                                        <VisualStateGroup.Transitions>
                                            <VisualTransition GeneratedDuration="0:0:0.1" />
                                        </VisualStateGroup.Transitions>
                                        <VisualState x:Name="Normal" />
                                        <VisualState x:Name="MouseOver">
                                            <Storyboard>
                                                <ColorAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="MouseOverHighlight" Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)">
                                                    <SplineColorKeyFrame KeyTime="00:00:00" Value="#FFFFDF00" />
                                                </ColorAnimationUsingKeyFrames>
                                                <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="MouseOverHighlight" Storyboard.TargetProperty="(UIElement.Opacity)">
                                                    <SplineDoubleKeyFrame KeyTime="00:00:00" Value="0.24" />
                                                </DoubleAnimationUsingKeyFrames>
                                            </Storyboard>
                                        </VisualState>
                                    </VisualStateGroup>
                                    <VisualStateGroup x:Name="SelectionStates">
                                        <VisualStateGroup.Transitions>
                                            <VisualTransition GeneratedDuration="0:0:0.1" />
                                        </VisualStateGroup.Transitions>
                                        <VisualState x:Name="Unselected" />
                                        <VisualState x:Name="Selected">
                                            <Storyboard>
                                                <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="SelectionHighlight" Storyboard.TargetProperty="(UIElement.Opacity)">
                                                    <SplineDoubleKeyFrame KeyTime="00:00:00" Value="0.18" />
                                                </DoubleAnimationUsingKeyFrames>
                                            </Storyboard>
                                        </VisualState>
                                    </VisualStateGroup>
                                    <VisualStateGroup x:Name="RevealStates">
                                        <VisualStateGroup.Transitions>
                                            <VisualTransition GeneratedDuration="0:0:0.5" />
                                        </VisualStateGroup.Transitions>
                                        <VisualState x:Name="Shown">
                                            <Storyboard>
                                                <DoubleAnimation Duration="0" Storyboard.TargetName="Root" Storyboard.TargetProperty="Opacity" To="1" />
                                            </Storyboard>
                                        </VisualState>
                                        <VisualState x:Name="Hidden">
                                            <Storyboard>
                                                <DoubleAnimation Duration="0" Storyboard.TargetName="Root" Storyboard.TargetProperty="Opacity" To="0" />
                                            </Storyboard>
                                        </VisualState>
                                    </VisualStateGroup>
                                </VisualStateManager.VisualStateGroups>
                                <ToolTipService.ToolTip>
                                    <ContentControl Content="{TemplateBinding FormattedDependentValue}" />
                                </ToolTipService.ToolTip>
                                <Ellipse Stroke="{TemplateBinding BorderBrush}" Fill="{TemplateBinding Background}" Height="30"/>
                                <Ellipse RenderTransformOrigin="0.661,0.321">
                                    <Ellipse.Fill>
                                        <RadialGradientBrush GradientOrigin="0.681,0.308">
                                            <GradientStop Color="Green" />
                                            <GradientStop Color="#FFFFFFFF" Offset="1" />
                                        </RadialGradientBrush>
                                    </Ellipse.Fill>
                                </Ellipse>
                                <Ellipse x:Name="SelectionHighlight" Opacity="0" Fill="Red" />
                                <Ellipse x:Name="MouseOverHighlight" Opacity="0" Fill="White" />
                            </Grid>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>



            <Style TargetType="chartingToolkit:LegendItem">
                <Setter Property="IsTabStop" Value="False" />
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="chartingToolkit:LegendItem">
                            <Border Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}">
                                <StackPanel Orientation="Horizontal">
                                    <Rectangle Width="8" Height="8" Fill="{Binding Background}" Stroke="{Binding BorderBrush}" StrokeThickness="1" Margin="0,0,3,0" />
                                    <datavis:Title Content="{TemplateBinding Content}" />
                                </StackPanel>
                            </Border>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>


        </Grid.Resources>

        <chartingToolkit:Chart Title="Engine Performance">
            <!-- Power curve -->
            <chartingToolkit:LineSeries
                            Title="Power"
                            ItemsSource="{StaticResource EngineMeasurementCollection}"
                            IndependentValueBinding="{Binding Speed}"
                            DependentValueBinding="{Binding Power}">
                <!-- Vertical axis for power curve -->
                <chartingToolkit:LineSeries.DependentRangeAxis>
                    <chartingToolkit:LinearAxis
                                    Orientation="Y"
                                    Title="Power (hp)"
                                    Minimum="0"
                                    Maximum="250"
                                    Interval="50"
                                    ShowGridLines="True"/>
                </chartingToolkit:LineSeries.DependentRangeAxis>
            </chartingToolkit:LineSeries>
            <!-- Torque curve -->
            <chartingToolkit:LineSeries
                            Title="Torque"
                            ItemsSource="{StaticResource EngineMeasurementCollection}"
                            IndependentValueBinding="{Binding Speed}"
                            DependentValueBinding="{Binding Torque}">
                <!-- Vertical axis for torque curve -->
                <chartingToolkit:LineSeries.DependentRangeAxis>
                    <chartingToolkit:LinearAxis
                                    Orientation="Y"
                                    Title="Torque (lb-ft)"
                                    Minimum="50"
                                    Maximum="300"
                                    Interval="50"/>
                </chartingToolkit:LineSeries.DependentRangeAxis>
            </chartingToolkit:LineSeries>
            <chartingToolkit:Chart.Axes>
                <!-- Shared horizontal axis -->
                <chartingToolkit:LinearAxis
                                Orientation="X"
                                Title="Speed (rpm)"
                                Interval="1000"
                                ShowGridLines="True"/>
            </chartingToolkit:Chart.Axes>
        </chartingToolkit:Chart>
    </Grid>
</Window>

...

namespace DataVisualizationDemos
{
    public class EngineMeasurementCollection : Collection<EngineMeasurement>
    {
        public EngineMeasurementCollection()
        {
            Add(new EngineMeasurement { Speed = 1000, Torque = 100, Power = 20 });
            Add(new EngineMeasurement { Speed = 2000, Torque = 160, Power = 60 });
            Add(new EngineMeasurement { Speed = 3000, Torque = 210, Power = 125 });
            Add(new EngineMeasurement { Speed = 4000, Torque = 220, Power = 160 });
            Add(new EngineMeasurement { Speed = 5000, Torque = 215, Power = 205 });
            Add(new EngineMeasurement { Speed = 6000, Torque = 200, Power = 225 });
            Add(new EngineMeasurement { Speed = 7000, Torque = 170, Power = 200 });
        }
    }

    public class EngineMeasurement
    {
        public int Speed { get; set; }
        public int Torque { get; set; }
        public int Power { get; set; }
    }
}

1 个答案:

答案 0 :(得分:2)

您可以通过设置LineSeries的DataPointStyle依赖属性来更改任何参数。例如,......

<!-- Power curve -->
<chartingToolkit:LineSeries
                Title="Power"
                ItemsSource="{StaticResource EngineMeasurementCollection}"
                IndependentValueBinding="{Binding Speed}"
                DependentValueBinding="{Binding Power}">

    <!-- Changing the data point style -->
    <chartingToolkit:LineSeries.DataPointStyle>
        <Style TargetType="chartingToolkit:LineDataPoint">
            <Setter Property="Width" Value="20"/>
            <Setter Property="Height" Value="20"/>
        </Style>
    </chartingToolkit:LineSeries.DataPointStyle>

    <!-- Vertical axis for power curve -->
    etc...
</chartingToolkit:LineSeries>

我不确定要删除它们。您可以使用相同的方法将样式的可见性设置为折叠,但这似乎不是最佳答案?