Lv.的博客

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

posted @   Avatarx  阅读(1404)  评论(0编辑  收藏  举报
(评论功能已被禁用)
编辑推荐:
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
阅读排行:
· winform 绘制太阳,地球,月球 运作规律
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
历史上的今天:
2014-05-23 Qt:使用Model-View,动态的加载显示数据
2014-05-23 怎样在VMware虚拟机中使用安装并设置Ubuntu系统
2014-05-23 在Ubuntu上安装Qt5.2.0
2014-05-23 DBCA创建数据库
2014-05-23 Oracle常用命令大全
2014-05-23 Qt数据库编程_基本
2014-05-23 Oracle 11g win32位 window7下安装教程
点击右上角即可分享
微信分享提示