我已经使用James McCaffrey提供的教程生成了图:http://msdn.microsoft.com/en-us/magazine/magazine/ff714591.aspx
iam能够成功地做到这一点。另外,我添加了一个工具提示:
plotter.AddLineGraph(compositeDataSource1,
new Pen(Brushes.Blue, 2),
new CircleElementPointMarker{ Size = 10.0, Fill = Brushes.Red ,Tooltip="Coordinates"},
new PenDescription("Number bugs open"));
我的问题是:如何显示工具提示点的 co-ordinates 。?
这就是我解决问题的方式。
EnumerableDataSource<TPoint> edc;
edc= new EnumerableDataSource<TPoint>(List_Of_TPoint);
edc.SetXMapping(x => dateAxis.ConvertToDouble(x.X));
edc.SetYMapping(y => Convert.ToDouble(y.Y));
edc.AddMapping(CircleElementPointMarker.ToolTipTextProperty, s => String.Format("Y-Data : {0}nX-Data : {1}", s.Y, s.X));
我在创建我的Enumerabledatasource时刚刚添加了映射。然后将EDC添加到绘图仪中。
plotter.AddLineGraph(
edc,
new Pen(Brushes.Transparent, 3),
new CircleElementPointMarker
{
Size = 15,
Brush = border,
Fill = c2
},
null
);
使用ElementMarkerPointSgraph和CircleElementPointMarker可能非常昂贵。对于每个点,都会创建一个椭圆。此外,即使没有人愿意查看工具提示,也将执行映射(构建工具提示的字符串)。
所以我的方式是使用MarkerPointSgraph并动态设置其工具提示。
xaml:
<d3:MarkerPointsGraph Name="MyMarkerPointsGraph" DataSource="{Binding Values}" ToolTip="Dummy" ToolTipOpening="CircleMarker_OnToolTipOpening">
<d3:MarkerPointsGraph.Marker>
<d3:CirclePointMarker />
</d3:MarkerPointsGraph.Marker>
</d3:MarkerPointsGraph>
以及背后的代码:
private void CircleMarker_OnToolTipOpening(object sender, ToolTipEventArgs e)
{
var pos = Mouse.GetPosition(MyMarkerPointsGraph);
var transform = GetTransform(MyMarkerPointsGraph);
transform.ScreenToData(pos);
var dataPoint = transform.ScreenToData(pos);
MyMarkerPointsGraph.ToolTip = $"Y-Data : {dataPoint.Y}nX-Data : {dataPoint.X}";
}
public static CoordinateTransform GetTransform(PointsGraphBase graph)
{
if (!(graph.Plotter is Plotter2D))
return null;
var transform = ((Plotter2D)graph.Plotter).Viewport.Transform;
if (graph.DataTransform != null)
transform = transform.WithDataTransform(graph.DataTransform);
return transform;
}