DynamicDataDisplay 双击获取坐标
近日由于项目需要,学习了DynamicDataDisplay实现动态曲线图,网上的资料基本上够用了,就是双击获得数据点没能找到资料,只好下载了DynamicDataDisplay的源码来学习。总结共享如下:
1、xaml定义
<d3:ChartPlotter Name="chart0" MouseDoubleClick="chart1_MouseDoubleClick">
<d3:ChartPlotter.HorizontalAxis>
<d3:HorizontalIntegerAxis></d3:HorizontalIntegerAxis>
</d3:ChartPlotter.HorizontalAxis>
<d3:ChartPlotter.VerticalAxis>
<d3:VerticalIntegerAxis></d3:VerticalIntegerAxis>
</d3:ChartPlotter.VerticalAxis>
<d3:HorizontalAxisTitle Content="rotate(℃)" Name="chart2Title"></d3:HorizontalAxisTitle>
</d3:ChartPlotter>
2、变量定义
private ObservableDataSource<Point> dataSources = new ObservableDataSource<Point>();
private int t=0;
3、Window_Loaded中
chart0.AddLineGraph(dataSources, Color.Red, 3, 'A');
chart0.FitToView();
4、利用timer加入数据
DispatcherTimer timerSine = new DispatcherTimer();
timerSine.Tick += new EventHandler(timerSine_Tick);
timerSine.Interval = TimeSpan.FromMilliseconds(10);
timerSine.Start();
private void timerSine_Tick(object sender, EventArgs e)
{
dataSources.AppendAsync(Dispatcher, new Point(t, 2*t));
t+= timerSine.Interval.Milliseconds;
}
5、双击获得数据点Point
private void chart0_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
ChartPlotter chart = sender as ChartPlotter;
Point p = e.GetPosition(this).ScreenToData(chart.Transform);
}