WPF中利用DynamicDataDisplay快速实现示波器功能
DynamicDataDisplay控件是一个功能很强的绘图工具,除了能生成曲线外,还有很多其他功能,具体见http://dynamicdatadisplay.codeplex.com/。这里你也能下载到其DLL文件。在项目中利用定时器产生数据,下面是我的示波器界面,暂时实现了开始,停止和清除功能:

示波器添加了一个边框,途中模拟了两个通道,注意要添加相关引用,另外我还弄了一个渐变画刷,看起来是不是很漂亮,界面xaml代码:
//添加引用
xmlns:d="http://research.microsoft.com/DynamicDataDisplay/1.0"
//添加资源
<RadialGradientBrush x:Key="ChartPlotterBrush" GradientOrigin="0.6,0.5">
<GradientStop Color="/>
<GradientStop Color="/>
</RadialGradientBrush>
//添加控件
<Border Margin=" Background="#FF5F5A5A">
<d:ChartPlotter Name=" Background="{StaticResource ChartPlotterBrush }"></d:ChartPlotter>
</Border>
<StackPanel Grid.Column=" Background="{StaticResource ToolBarBackgroundBrush}" Orientation="Horizontal">
<Button Width=" Margin="30,2,5,0" Click="OscilloscopeStart_Click">开 启</Button>
<Button Width=" Margin="5,2,5,0" Click="OscilloscopeStop_Click">停 止</Button>
<Button Width=" Margin="5,2,5,0" Click="OscilloscopeClear_Click">清 除</Button>
<Button Width=" Margin="5,2,5,0" Click="OscilloscopeSet_Click">设 置</Button>
<Button Width=" Margin="5,2,5,0" Click="OscilloscopeDataLoad_Click">载入数据</Button>
<Button Width=" Margin="5,2,5,0" Click="OscilloscopeDataSave_Click">存储数据</Button>
<Ellipse Width=" Margin="5,2,5,0" Fill="Red"></Ellipse>
</StackPanel>
后台程序代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Data.OleDb;
using System.Data;
using System.Collections.ObjectModel;
using System.Globalization;
using System.IO;
using System.Windows.Threading;
using Microsoft.Research.DynamicDataDisplay;
using Microsoft.Research.DynamicDataDisplay.DataSources;
using System.Windows.Forms;
namespace MotorDriver1
{
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : Window
{
private ObservableDataSource<Point> dataSource1 = new ObservableDataSource<Point>();
private ObservableDataSource<Point> dataSource2 = new ObservableDataSource<Point>();
private DispatcherTimer timer = new DispatcherTimer();
private LineGraph graphSin1 = new LineGraph();
private LineGraph graphSin2 = new LineGraph();
;
public MainWindow()
{
InitializeComponent();
}
private void OscilloscopeStart_Click(object sender, RoutedEventArgs e)
{
//plotter.AddLineGraph(dataSource, Colors.Green, 2);
timer.Interval = TimeSpan.FromSeconds(0.1);
timer.Tick += new EventHandler(AnimatedPlot);
timer.IsEnabled = true;
)
{
graphSin1 = plotter.AddLineGraph(dataSource1, Colors.Red, , "Sin1");
graphSin2 = plotter.AddLineGraph(dataSource2, Colors.Black, , "Sin2");
}
plotter.Viewport.FitToView();
}
private void AnimatedPlot(object sender, EventArgs e)
{
double x = i;
double y1 = Math.Sin(i*0.2);
* Math.Sin(i * 0.6);
Point point1 = new Point(x, y1);
Point point2 = new Point(x, y2);
dataSource1.AppendAsync(base.Dispatcher, point1);
dataSource2.AppendAsync(base.Dispatcher, point2);
i++;
}
private void OscilloscopeStop_Click(object sender, RoutedEventArgs e)
{
timer.IsEnabled = false;
}
private void OscilloscopeClear_Click(object sender, RoutedEventArgs e)
{
i = ;
timer.IsEnabled = false;
plotter.Children.Remove(graphSin1);
plotter.Children.Remove(graphSin2);
dataSource1 = new ObservableDataSource<Point>();
dataSource2 = new ObservableDataSource<Point>();
}
需要注意的就是清除示波器数据时,除了要用plotter.Children.Remove()指令,将此通道曲线移除,还要将数据源里的数据清干净,这里我们直接重新分配内存了。如果不清除干净,新的图线将在原来图线基础上继续画。
WPF中利用DynamicDataDisplay快速实现示波器功能的更多相关文章
- WPF中利用RadialGradient模拟放大镜效果
原文:WPF中利用RadialGradient模拟放大镜效果 --------------------------------------------------------------------- ...
- WPF中利用后台代码实现窗口分栏动态改变
在WPF中实现窗口分栏并能够通过鼠标改变大小已经非常容易,例如将一个GRID分成竖排三栏显示,就可以将GRID先分成5列,其中两个固定列放GridSplitter. <Grid Backgrou ...
- 在sql server中利用with as实现递归功能
在sqlserver2005之前,要实现递归功能比较麻烦,比如可能会要用到临时表与while语句来循环.自sqlserver2005之后,新增了with as功能语法,即 公用表达式(CTE),让递归 ...
- 【原创】js中利用cookie实现记住密码功能
在登录界面添加记住密码功能,我首先想到的是在java后台中调用cookie存放账号密码,大致如下: HttpServletRequest request HttpServletResponse res ...
- WPF中利用控件的DataContext属性为多个TextBox绑定数据
工作上需要从给定的接口获取数据,然后显示在界面的编辑框中,以往肯定会一个一个的去赋值,但这样太麻烦而且效率很低,不利于维护,于是想到了数据绑定这一方法,数据绑定主要利用INotifyPropertyC ...
- js中利用cookie实现记住密码功能
在登录界面添加记住密码功能,代码如下: //设置cookie var passKey = '4c05c54d952b11e691d76c0b843ea7f9'; function setCookie( ...
- WPF在3D Cad模型中利用TextureCoordinates实现颜色渐变显示偏差值的变化
原文:WPF在3D Cad模型中利用TextureCoordinates实现颜色渐变显示偏差值的变化 注:最近在做3D机械模型重建方面的软件,需要根据光栅传感器采集的数据绘制3D图形,并显示出色差以及 ...
- 后续来啦:Winform/WPF中快速搭建日志面板
后续来啦:Winform/WPF中快速搭建日志面板 继昨天发文ASP.NET Core 可视化日志组件使用(阅读文章,查看视频)后,视频下有朋友留言 "Winform客户端的程序能用它不?& ...
- Python中利用函数装饰器实现备忘功能
Python中利用函数装饰器实现备忘功能 这篇文章主要介绍了Python中利用函数装饰器实现备忘功能,同时还降到了利用装饰器来检查函数的递归.确保参数传递的正确,需要的朋友可以参考下 " ...
随机推荐
- Virtualbox - 共享文件夹
在虚拟机中添加共享文件夹——比如主机中的/home/user/download,我想把download文件夹共享给虚拟机用. 步骤:1.在虚拟机中找个挂载的目录,比如 /mnt/d,没有就新建一个目录 ...
- Python学习笔记 第一课 列表
Python的列表就像是一个数组: 一.创建列表 movies=["The Holy Grail","Then Life of Brian","The ...
- linux-阿里云ECS部署PPTP(centos)
请参考以下步骤:(centos6.5中测试通过) 1.服务器端安装软件 1.1 首先安装ppp,命令: [root@test ~]#yum install -y ppp 提示Complete! ,表示 ...
- CF Amr and Pins (数学)
Amr and Pins time limit per test 1 second memory limit per test 256 megabytes input standard input o ...
- LInux下socket编程学习笔记
1.socket套接字: socket起源于Unix,而Unix/Linux基本哲学之一就是“一切皆文件”,都可以用“打开open –> 读写write/read –> 关闭close”模 ...
- Next Power of 2
Next Power of 2 Write a function that, for a given no n, finds a number p which is greater than or e ...
- Linux 命令 - top: 动态显示进程信息
命令格式 top -hv | -abcHimMsS -d delay -n iterations -p pid [, pid ...] 命令参数 -a 根据内存的使用排序. -b 以批处理模式操作. ...
- 【转载】Kafka实现篇之消息和日志
http://blog.csdn.net/honglei915/article/details/37760631 消息格式 日志 一个叫做“my_topic”且有两个分区的的topic,它的日志有两个 ...
- CSS之perspective
<!DOCTYPE html> <html> <head> <style> #div1 { position: relative; height: 15 ...
- 使用EntityFramework连接 Mysql
原文:使用EntityFramework连接 Mysql 1,安装VS.net 插件 http://forums.mysql.com/read.php?174,601041,601041 2,安装连接 ...