WPFToolkit Charting - How to remove markers or change marker size?

老子叫甜甜 提交于 2019-12-08 02:29:16

问题


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

回答1:


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?



来源:https://stackoverflow.com/questions/3715426/wpftoolkit-charting-how-to-remove-markers-or-change-marker-size

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!