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

发布于 2024-09-19 13:05:14 字数 12295 浏览 7 评论 0原文

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

这是我一直用作测试。

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

I can't quite see how to remove the markers in a WPFToolkit graph. I can see they are the ellipses in the XAML below, but I can't seem to successfully change any of the parameters to get the size of them to change, OR to remove them. Any ideas?

Here is the XAML (which stills need the WPFToolkit) I've been using as a test.

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浮生面具三千个 2024-09-26 13:05:14

您可以通过设置 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>

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

You can change any of the parameters by setting the DataPointStyle dependancy property of your LineSeries. For example, ...

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

I'm not sure about removing them. You could use the same method to set the style's visibility to collapsed but that doesn't seem like the best answer?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文