我正在绘制一个 WPFToolkit LineSeries 图,除了 ToolTip 之外,它都可以正常工作。我想要一个工具提示来显示鼠标线上任何点的 x 和 y 值。我发现这适用于 DataPoints(在我的情况下相当稀疏):http: //istacee.wordpress.com/2013/03/19/wpf-toolkit-chart-custom-tooltip-on-lineseries- chart/和图表区域上的任何点:使用工具提示 c# 在图表上的任何点上显示系列值。
到目前为止,这是我的代码:
<Grid.Resources>
<ResourceDictionary>
<ControlTemplate x:Key="CommonLineSeriesDataPointTemplate" TargetType="chartingToolkit:LineDataPoint">
<Grid x:Name="Root" Opacity="1" />
</ControlTemplate>
<Style x:Key="CommonLineSeriesDataPoint" TargetType="chartingToolkit:LineDataPoint">
<Setter Property="Template" Value="{StaticResource CommonLineSeriesDataPointTemplate}" />
</Style>
<Style x:Key="lineSeriesStyle" TargetType="{x:Type chartingToolkit:LineSeries}">
<Setter Property="IsTabStop" Value="False" />
<Setter Property="DataPointStyle" Value="{StaticResource CommonLineSeriesDataPoint}" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="chartingToolkit:LineSeries">
<Canvas x:Name="PlotArea">
<Polyline Points="{TemplateBinding Points}" >
<Polyline.Stroke>
<SolidColorBrush Color="Red"/>
</Polyline.Stroke>
</Polyline>
</Canvas>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<DataTemplate x:Key="chartTemplate" DataType="{x:Type Views:GraphCurve}">
<chartingToolkit:LineSeries ItemsSource="{Binding}"
IndependentValuePath="X"
DependentValuePath="Y"
Style="{StaticResource lineSeriesStyle}" />
</DataTemplate>
</ResourceDictionary>
</Grid.Resources>
<chartingToolkit:Chart BorderBrush="DarkGray"
SeriesSource="{Binding GraphItems}"
SeriesTemplate="{StaticResource chartTemplate}">
<chartingToolkit:Chart.Axes>
<chartingToolkit:LinearAxis Orientation="X" />
<chartingToolkit:LinearAxis Orientation="Y" />
</chartingToolkit:Chart.Axes>
</chartingToolkit:Chart>
有任何想法吗?