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快速实现示波器功能的更多相关文章

  1. WPF中利用RadialGradient模拟放大镜效果

    原文:WPF中利用RadialGradient模拟放大镜效果 --------------------------------------------------------------------- ...

  2. WPF中利用后台代码实现窗口分栏动态改变

    在WPF中实现窗口分栏并能够通过鼠标改变大小已经非常容易,例如将一个GRID分成竖排三栏显示,就可以将GRID先分成5列,其中两个固定列放GridSplitter. <Grid Backgrou ...

  3. 在sql server中利用with as实现递归功能

    在sqlserver2005之前,要实现递归功能比较麻烦,比如可能会要用到临时表与while语句来循环.自sqlserver2005之后,新增了with as功能语法,即 公用表达式(CTE),让递归 ...

  4. 【原创】js中利用cookie实现记住密码功能

    在登录界面添加记住密码功能,我首先想到的是在java后台中调用cookie存放账号密码,大致如下: HttpServletRequest request HttpServletResponse res ...

  5. WPF中利用控件的DataContext属性为多个TextBox绑定数据

    工作上需要从给定的接口获取数据,然后显示在界面的编辑框中,以往肯定会一个一个的去赋值,但这样太麻烦而且效率很低,不利于维护,于是想到了数据绑定这一方法,数据绑定主要利用INotifyPropertyC ...

  6. js中利用cookie实现记住密码功能

    在登录界面添加记住密码功能,代码如下: //设置cookie var passKey = '4c05c54d952b11e691d76c0b843ea7f9'; function setCookie( ...

  7. WPF在3D Cad模型中利用TextureCoordinates实现颜色渐变显示偏差值的变化

    原文:WPF在3D Cad模型中利用TextureCoordinates实现颜色渐变显示偏差值的变化 注:最近在做3D机械模型重建方面的软件,需要根据光栅传感器采集的数据绘制3D图形,并显示出色差以及 ...

  8. 后续来啦:Winform/WPF中快速搭建日志面板

    后续来啦:Winform/WPF中快速搭建日志面板 继昨天发文ASP.NET Core 可视化日志组件使用(阅读文章,查看视频)后,视频下有朋友留言 "Winform客户端的程序能用它不?& ...

  9. Python中利用函数装饰器实现备忘功能

    Python中利用函数装饰器实现备忘功能 这篇文章主要介绍了Python中利用函数装饰器实现备忘功能,同时还降到了利用装饰器来检查函数的递归.确保参数传递的正确,需要的朋友可以参考下   " ...

随机推荐

  1. Honda HDS IMMO PCM Code calculator Free Download

    HDS IMMO PCM Code calculator software for Honda vehicle models is free download available in Eobd2.f ...

  2. Objective-C ,ios,iphone开发基础:3分钟教你做一个iphone手机浏览器

    第一步:新建一个Single View工程: 第二步:新建好工程,关闭arc. 第三步:拖放一个Text Field 一个UIButton 和一个 UIWebView . Text Field 的ti ...

  3. 类、对象以及jvm运行内存解析

    一.JVM内存的分析: 第一步:存放在硬盘上的程序首先要被加载到内存空间中. 第二步:内存中的jvm找到程序中main函数作为入口,然后开始执行. 第三步:执行过程中的内存管理:内存分为四个部分: 栈 ...

  4. C# 文件的读取、写入和删除

    class Program { static void Main(string[] args) { EmployeeDAL DAL = new EmployeeDAL(); List<Sys_E ...

  5. 通过Bresenham算法实现完成矢量线性多边形向栅格数据的转化

    1.实验目的与要求 目的:通过本次实验,完成矢量线性多边形向栅格数据的转化过程: 要求:采用VC++6.0实现. 2.实验方法 采用Bresenham算法实现 3.实验材料 直线的定义:y = x/3 ...

  6. ubuntu共享文件夹给virtualbox

    在ubuntu或者linuxmint等linux系统下安装了virtualbox,可以通过共享文件夹的方式,把文件夹共享给virtualbox下的虚拟机系统,我这里的虚拟机系统是win7,共享过程如下 ...

  7. WebStorm 8.0安装LESS编译环境的教程

    WebStorm是一个非常棒的Web前端开发编辑器,被程序猿们成为“最智能的JavaScript IDE”.对HTML5.Bootstrap框架.Node.js等都有完美支持.目前最新版本为WebSt ...

  8. 判断checkbox选中

    源码如下,仅限参考,直接复制即可: <meta http-equiv="Content-Type" content="text/html; charset=utf- ...

  9. HTML5와 CSS3 적용기

    HTML5의 DTD 선언 <!DOCTYPE html>  HTML5의 인코딩 선언 <meta charset="utf-8">  그리고나서는 새로 ...

  10. iMAC——查看开机关机时间

    每次下班都记不好早上几点打的卡,你是不是也经常有这样的情况:  那就用以下的代码考到Mac电脑的终端中,回车: mac终端输入上面命令行 查看开机时间: last | grep reboot 查看关机 ...