WPF DynamicDataDisplay 实现动态曲线图 双击获得数据点

这篇博客介绍了如何使用WPF的DynamicDataDisplay库创建动态曲线图,并详细说明了如何设置XAML、定义变量、在Window_Loaded事件中添加图形、使用DispatcherTimer更新数据以及实现双击图表获取数据点的功能。

近日由于项目需要,学习了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:Vertical

using Microsoft.Research.DynamicDataDisplay; using Microsoft.Research.DynamicDataDisplay.Charts; using Microsoft.Research.DynamicDataDisplay.Charts.Axes; using Microsoft.Research.DynamicDataDisplay.Charts.Navigation; using Microsoft.Research.DynamicDataDisplay.DataSources; using Microsoft.Research.DynamicDataDisplay.Navigation; using Microsoft.Win32; using NPOI.SS.Formula.Functions; using System; using System.Collections; using System.Collections.Generic; using System.Collections.ObjectModel; using System.ComponentModel; using System.Diagnostics; using System.IO; using System.IO.Ports; using System.Linq; using System.Runtime.InteropServices; using System.Text; using System.Text.RegularExpressions; using System.Threading; using System.Threading.Tasks; 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.Windows.Threading; using static NPOI.HSSF.Util.HSSFColor; namespace DigitalContorPower { /// <summary> /// MainWindow.xaml 的交互逻辑 /// </summary> public partial class MainWindow : Window { //创建一个保存串口设置的ini文件 [DllImport("kernel32")] private static extern long WritePrivateProfileString(string Section, string key, string val, string filePath); [DllImport("kernel32")] private static extern long GetPrivateProfileString(string Section, string key, string def, StringBuilder retval, int size, string filePath); string FileName = System.AppDomain.CurrentDomain.BaseDirectory + "data.ini"; //ini文件路径和名称 SerialPort Serial = new SerialPort(); //新建一个串口 StringBuilder comNume = new StringBuilder(20); //com口文件名 StringBuilder baudNume = new StringBuilder(20); //波特率 private bool OpneOrCloseSerial = false; //开or关串口标志位 string[] SoftSet = new string[10]; //存储串口设置的数据 Queue recQueue = new Queue(); //接收数据过程中,接收数据线程与数据处理线程直接传递的队列,先进先出 private bool WaitClose = true; //invoke里判断是否正在关闭串口是否正在关闭串口,执行Application.DoEvents,并阻止再次invoke ,解决关闭串口时,程序假死 DispatcherTimer Timer1 = new DispatcherTimer(); CursorCoordinateGraph cursorGraph = new CursorCoordinateGraph(); //曲线设置参数 private ObservableDataSource<Point> dataVol1 = new ObservableDataSource<Point>(); //申请电压曲线 private ObservableDataSource<Point> dataVol2 = new ObservableDataSource<Point>(); //申请电压曲线 private ObservableDataSource<Point> dataVol3 = new ObservableDataSource<Point>(); private ObservableDataSource<Point> dataVol4 = new ObservableDataSource<Point>(); private ObservableDataSource<Point> dataVol5 = new ObservableDataSource<Point>(); private ObservableDataSource<Point> dataVol6 = new ObservableDataSource<Point>(); private ObservableDataSource<Point> dataVol7 = new ObservableDataSource<Point>(); private ObservableDataSource<Point> dataVol8 = new ObservableDataSource<Point>(); private ObservableDataSource<Point> dataVol9 = new ObservableDataSource<Point>(); private ObservableDataSource<Point> dataVol10 = new ObservableDataSource<Point>(); private ObservableDataSource<Point> dataVol11 = new ObservableDataSource<Point>(); private ObservableDataSource<Point> dataVol12 = new ObservableDataSource<Point>(); private ObservableDataSource<Point> dataVol13 = new ObservableDataSource<Point>(); private ObservableDataSource<Point> dataVol14 = new ObservableDataSource<Point>(); private ObservableDataSource<Point> dataVol15 = new ObservableDataSource<Point>(); private ObservableDataSource<Point> dataVol16 = new ObservableDataSource<Point>(); private LineGraph graphVol1 = new LineGraph(); //电压曲线 private LineGraph graphVol2 = new LineGraph(); //电压曲线 private LineGraph graphVol3 = new LineGraph(); //电压曲线 private LineGraph graphVol4 = new LineGraph(); //电压曲线 private LineGraph graphVol5 = new LineGraph(); //电压曲线 private LineGraph graphVol6 = new LineGraph(); //电压曲线 private LineGraph graphVol7 = new LineGraph(); //电压曲线 private LineGraph graphVol8 = new LineGraph(); //电压曲线 private LineGraph graphVol9 = new LineGraph(); //电压曲线 private LineGraph graphVol10 = new LineGraph(); //电压曲线 private LineGraph graphVol11 = new LineGraph(); //电压曲线 private LineGraph graphVol12 = new LineGraph(); //电压曲线 private LineGraph graphVol13 = new LineGraph(); //电压曲线 private LineGraph graphVol14 = new LineGraph(); //电压曲线 private LineGraph graphVol15 = new LineGraph(); //电压曲线 private LineGraph graphVol16 = new LineGraph(); //电压曲线 Thread LoadedExcelThread; //加载Excel线程 Thread _ComRec; //接收线程 Thread _SaveRec; //保存线程 private bool isRun = true; //用于结束线程 private int uindex = 0; DateTime fristTime; //保存开始保存的年月日时分秒 private Boolean iSreal = false; /// <summary> /// 主窗口加载 /// </summary> public MainWindow() { InitializeComponent(); plotter.VerticalAxis = new VerticalIntegerAxis(); graphVol1 = plotter.AddLineGraph(dataVol1, Colors.Red, 2, "CH1"); graphVol2 = plotter.AddLineGraph(dataVol2, Colors.Orange, 2, "CH2"); graphVol3 = plotter.AddLineGraph(dataVol3, Colors.Yellow, 2, "CH3"); graphVol4 = plotter.AddLineGraph(dataVol4, Colors.Green, 2, "CH4"); graphVol5 = plotter.AddLineGraph(dataVol5, Colors.Cyan, 2, "CH5"); graphVol6 = plotter.AddLineGraph(dataVol6, Colors.Blue, 2, "CH6"); graphVol7 = plotter.AddLineGraph(dataVol7, Colors.Purple, 2, "CH7"); graphVol8 = plotter.AddLineGraph(dataVol8, Colors.Pink, 2, "CH8"); graphVol9 = plotter.AddLineGraph(dataVol9, Colors.Brown, 2, "CH9"); graphVol10 = plotter.AddLineGraph(dataVol10, Colors.Gray, 2, "CH10"); graphVol11 = plotter.AddLineGraph(dataVol11, Colors.Black, 2, "CH11"); graphVol12 = plotter.AddLineGraph(dataVol12, Colors.Beige, 2, "CH12"); graphVol13 = plotter.AddLineGraph(dataVol13, Colors.LightBlue, 2, "CH13"); graphVol14 = plotter.AddLineGraph(dataVol14, Colors.DarkBlue, 2, "CH14"); graphVol15 = plotter.AddLineGraph(dataVol15, Colors.LightGreen, 2, "CH15"); graphVol16 = plotter.AddLineGraph(dataVol16, Colors.DarkGreen, 2, "CH16"); plotter.Children.Add(new CursorCoordinateGraph()); //添加十字光标 // 设置Viewport的可见区域,固定Y轴范围 plotter.Viewport.FitToView(); //加载到视图上 SoftSetup_Loaded(); //软件设置参数读取 SearialSetup_Loaded(); //串口设置读取 Serial.Encoding = Encoding.GetEncoding("GB2312"); //设置串口的字体为GB2312 Serial.DataReceived += new SerialDataReceivedEventHandler(ComReceive);//串口接收中断 Serial.ReadTimeout = 200; Timer1.Tick += Timer_Handle; Timer1.Interval = new TimeSpan(0,0,1); Timer1.Stop(); _ComRec = new Thread(new ThreadStart(ComRec)); //查询串口接收数据线程声明 _ComRec.Start(); //启动线程 _SaveRec = new Thread(new ThreadStart(SvaeRecThread)); //数据保存线程声明 _SaveRec.Start();//启动线程 RefreshInfo(); //刷新显示信息 uindex = 0; } private void Timer_Handle(object sender, EventArgs e) { try { Query_data(); } catch { } } /// <summary> /// 软件设置读取 /// </summary> private void SoftSetup_Loaded() { StringBuilder ReadFileDtae = new StringBuilder(100); //创建读取的数据 GetPrivateProfileString("Buad", "Baud", "9600bps", ReadFileDtae, 15, FileName); //默认波特率为9600 SoftSet[0] = ReadFileDtae.ToString(); } /// <summary> /// 串口加载 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void SearialSetup_Loaded() { SerialPort Serial = new SerialPort();//新建一个串口 string[] Ports;//可用串口数组 Ports = new string[SerialPort.GetPortNames().Length];//重新定义可用串口数组长度 Ports = SerialPort.GetPortNames(); //获取可用串口 if (Ports.Length > 0)//有可用串口 { for (int s = 0; s < Ports.Length; s++) { ComCommbox.Items.Add(Ports[s]); } if (!((IList)Ports).Contains(SoftSet[2])) //判断打开串口是否有保存的串口,没有就打开第一个 { ComCommbox.Text = Ports[0]; //选择第一个COM口 } else { ComCommbox.Text = SoftSet[2]; //选中COM口的名称 } } else { ComCommbox.Text = "No COM"; ConnectButton.IsEnabled = false; } } /// <summary> /// 串口接收中断事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ComReceive(object sender, SerialDataReceivedEventArgs e)//接收数据 中断只标志有数据需要读取,读取操作在中断外进行 { if (true == WaitClose) return;//如果正在关闭串口,则直接返回 Thread.Sleep(10); //发送和接收均为文本时,接收中为加入判断是否为文字的算法,发送你(C4E3),接收可能识别为C4,E3,可用在这里加延时解决 if (true)//如果已经开启接收 { byte[] recBuffer;//接收缓冲区 try { recBuffer = new byte[Serial.BytesToRead]; //接收数据缓存大小 Serial.Read(recBuffer, 0, recBuffer.Length);//读取数据 recQueue.Enqueue(recBuffer); //读取数据入列Enqueue(全局) } catch { UIAction(() => { if (Serial.IsOpen == false)//如果ComPort.IsOpen == false,说明串口已丢失 { SetComLose();//串口丢失后相关设置 MessageBox.Show("串口未打开", "错误信息"); } else { MessageBox.Show("无法接收数据,原因未知!", "错误信息"); } }); } } else//暂停接收 { Serial.DiscardInBuffer();//清接收缓存 } } /// <summary> /// 8位和校验 /// </summary> /// <param name="buf"></param> /// <param name="len"></param> /// <returns></returns> byte Checkout8(byte[] buf, int len) { byte ret = 0; for(int i=0;i<len; i++) { ret += buf[i]; } return ret; } void Query_data() { if (OpneOrCloseSerial == false) return; byte[] sendBuffer = new byte[8]; sendBuffer[0] = 0x55; sendBuffer[1] = (byte)(0x01); sendBuffer[2] = (byte)(0x55); sendBuffer[3] = (byte)(0x11); sendBuffer[4] = (byte)(0x11); sendBuffer[5] = (byte)(0x11); sendBuffer[6] = (byte)(0x11); sendBuffer[7] = (byte)(0xaa); try { Serial.Write(sendBuffer, 0, sendBuffer.Length); } catch (Exception) { Timer1.Stop(); MessageBox.Show("请检查设备是否连接正常!", "错误信息"); } } void SendOpen_data() { int SetCur = 0; int SetVol = 0; try { } catch (Exception) { Timer1.Stop(); MessageBox.Show("请检查设备是否连接正常!", "错误信息"); } } void SendClose_data() { int SetCur = 0; int SetVol = 0; try { } catch (Exception) { Timer1.Stop(); MessageBox.Show("请检查设备是否连接正常!", "错误信息"); } } /// <summary> /// 接收线程 /// </summary> void ComRec()//接收线程,窗口初始化中就开始启动运行 { byte[] buf = new byte[1024]; while (isRun)//一直查询串口接收线程中是否有新数据 { if (recQueue.Count > 0)//当串口接收线程中有新的数据时候,队列中有新进的成员recQueue.Count > 0 { string recData = null;//接收数据转码后缓存 byte[] recBuffer = null; while (recQueue.Count > 0) { recBuffer = (byte[])recQueue.Dequeue();//出列Dequeue(全局) recData += System.Text.Encoding.Default.GetString(recBuffer);//转码 } UIAction(() => { buf = recBuffer; ; if(buf.Length != 0) { if ((buf[0] == 0x55)) //包头包尾是否准确 { if (buf.Length >= 34) { if (((buf[33] == 0xAA))) { try { int bfb = 0; int Vol1 = recBuffer[1] * 256+ recBuffer[2]; int Vol2 = recBuffer[3] * 256 + recBuffer[4]; int Vol3 = recBuffer[5] * 256 + recBuffer[6]; int Vol4 = recBuffer[7] * 256 + recBuffer[8]; int Vol5 = recBuffer[9] * 256 + recBuffer[10]; int Vol6 = recBuffer[11] * 256 + recBuffer[12]; int Vol7 = recBuffer[13] * 256 + recBuffer[14]; int Vol8 = recBuffer[15] * 256 + recBuffer[16]; int Vol9 = recBuffer[17] * 256 + recBuffer[18]; int Vol10 = recBuffer[19] * 256 + recBuffer[20]; int Vol11 = recBuffer[21] * 256 + recBuffer[22]; int Vol12 = recBuffer[23] * 256 + recBuffer[24]; int Vol13 = recBuffer[25] * 256 + recBuffer[26]; int Vol14 = recBuffer[27] * 256 + recBuffer[28]; int Vol15 = recBuffer[29] * 256 + recBuffer[30]; int Vol16 = recBuffer[31] * 256 + recBuffer[32]; List<Point> points1 = new List<Point>(); List<Point> points2 = new List<Point>(); List<Point> points3 = new List<Point>(); List<Point> points4 = new List<Point>(); List<Point> points5 = new List<Point>(); List<Point> points6 = new List<Point>(); List<Point> points7 = new List<Point>(); List<Point> points8 = new List<Point>(); List<Point> points9 = new List<Point>(); List<Point> points10 = new List<Point>(); List<Point> points11 = new List<Point>(); List<Point> points12 = new List<Point>(); List<Point> points13 = new List<Point>(); List<Point> points14 = new List<Point>(); List<Point> points15 = new List<Point>(); List<Point> points16 = new List<Point>(); points1.Add(new Point(uindex, Vol1)); points2.Add(new Point(uindex, Vol2)); points3.Add(new Point(uindex, Vol3)); points4.Add(new Point(uindex, Vol4)); points5.Add(new Point(uindex, Vol5)); points6.Add(new Point(uindex, Vol6)); points7.Add(new Point(uindex, Vol7)); points8.Add(new Point(uindex, Vol8)); points9.Add(new Point(uindex, Vol9)); points10.Add(new Point(uindex, Vol10)); points11.Add(new Point(uindex, Vol11)); points12.Add(new Point(uindex, Vol12)); points13.Add(new Point(uindex, Vol13)); points14.Add(new Point(uindex, Vol14)); points15.Add(new Point(uindex, Vol15)); points16.Add(new Point(uindex, Vol16)); uindex++; dataVol1.AppendMany(points1); dataVol2.AppendMany(points2); dataVol3.AppendMany(points3); dataVol4.AppendMany(points4); dataVol5.AppendMany(points5); dataVol6.AppendMany(points6); dataVol7.AppendMany(points7); dataVol8.AppendMany(points8); dataVol9.AppendMany(points9); dataVol10.AppendMany(points10); dataVol11.AppendMany(points11); dataVol12.AppendMany(points12); dataVol13.AppendMany(points13); dataVol14.AppendMany(points14); dataVol15.AppendMany(points15); dataVol16.AppendMany(points16); buf = new byte[1024]; } catch (System.Exception ex) { MessageBox.Show(ex.Message);//现实异常信息给客户。 Thread.Sleep(2);//如果不延时,一直查询,将占用CPU过高 } } else { buf = new byte[1024]; } } } else { buf = new byte[1024]; } } }); } else { try { Thread.Sleep(5);//如果不延时,一直查询,将占用CPU过高 } catch (Exception) { Thread.Sleep(400);//如果不延时,一直查询,将占用CPU过高 } } } } /// <summary> /// 接收线程 /// </summary> private void SvaeRecThread()//接收线程,窗口初始化中就开始启动运行 { while (isRun)//一直查询串口接收线程中是否有新数据 { try { if ((WaitClose == false)) { } Thread.Sleep(800);//如果不延时,一直查询,将占用CPU过高 } catch (System.Exception ex) { MessageBox.Show(ex.Message);//现实异常信息给客户。 Thread.Sleep(1000);//如果不延时,一直查询,将占用CPU过高 } } } /// <summary> /// 刷新可用的串口 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Com__PreviewMouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e) { string[] SerialPorts; //可用串口数组 string LastItem; int m = 0; LastItem = ComCommbox.Text; ComCommbox.Items.Clear(); //clear Item SerialPorts = new string[SerialPort.GetPortNames().Length];//重新定义可用串口数组长度 SerialPorts = SerialPort.GetPortNames();//获取可用串口 if (SerialPorts.Length > 0)//有可用串口 { if (!((IList)SerialPorts).Contains(comNume.ToString())) //判断打开串口是否有保存的串口,没有就打开第一个 { ComCommbox.Text = "No COM"; } for (int i = 0; i < SerialPorts.Length; i++) { ComCommbox.Items.Add(SerialPorts[i]); if (SerialPorts[i] == LastItem) m = 1; } } else { ComCommbox.Text = "No COM"; } if (m == 1) //if have last com select the last com { ComCommbox.Text = LastItem; } } /// <summary> /// 打开关闭串口的按钮Click /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void SwithButton_Click(object sender, RoutedEventArgs e) { if (iSreal == true) { iSreal = false; } else { iSreal = true; } } /// <summary> /// 打开关闭串口的按钮Click /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ConnectButton_Click(object sender, RoutedEventArgs e) { try { if (OpneOrCloseSerial == false) //开启串口 { ClearResseiveData(); OpneOrCloseSerial=true; Serial.Close(); if (ComCommbox.Text != "") { Serial.PortName = ComCommbox.Text; WritePrivateProfileString("COM", "COM", ComCommbox.Text, FileName); //选中后更新保存在文件的波特率名称 } Serial.BaudRate = Convert.ToInt32("115200"); Serial.DataBits = Convert.ToInt32("8"); Serial.StopBits = StopBits.One; Serial.Parity = (Parity)0; ConnectButton.Content = (" DisConnect ");//按键显示打开串口 ButtonImage.Source = new BitmapImage(new Uri(@"Picture/greenlight.png", UriKind.Relative)); ComCommbox.IsEnabled = false; Open_com(); Timer1.Start(); SendOpen_data(); WaitClose = false; uindex = 0; } else //关闭串口 { SendClose_data(); WaitClose = true;//等待关闭串口状态改为true OpneOrCloseSerial = false; Serial.Close(); ConnectButton.Content = (" Connect ");//按键显示打开串口 ButtonImage.Source = new BitmapImage(new Uri(@"Picture/redlight.png", UriKind.Relative)); ComCommbox.IsEnabled = true; Timer1.Stop(); } } catch (System.Exception ex) //异常情况 { SetComLose(); MessageBox.Show(ex.Message);//现实异常信息给客户。 } } /// <summary> /// 打开串口 /// </summary> private void Open_com() { try { Serial.Open(); uindex = 0; } catch (System.Exception ex) //异常情况 { SetComLose(); MessageBox.Show(ex.Message);//现实异常信息给客户。 } } /// <summary> /// 串口丢失后的设置 /// </summary> private void SetComLose()//成功关闭串口或串口丢失后的设置 { WaitClose = false;//关闭正在关闭状态字,用于在串口接收方法的invoke里判断是否正在关闭串口 OpneOrCloseSerial = false; Serial = new SerialPort(); //捕获到异常信息,创建一个新的comm对象,之前的不能用了。 Serial.Encoding = Encoding.GetEncoding("GB2312"); //设置串口的字体为GB2312 Serial.DataReceived += new SerialDataReceivedEventHandler(ComReceive);//串口接收中断 Serial.ReadTimeout = 200; Serial.Close(); ConnectButton.Content = (" Connest ");//按键显示打开串口 ButtonImage.Source = new BitmapImage(new Uri(@"Picture/redlight.png", UriKind.Relative)); ComCommbox.IsEnabled = true; } /// <summary> /// 在主线程外激活线程方法 /// </summary> /// <param name="action"></param> void UIAction(Action action) { System.Threading.SynchronizationContext.SetSynchronizationContext(new System.Windows.Threading.DispatcherSynchronizationContext(App.Current.Dispatcher)); System.Threading.SynchronizationContext.Current.Post(_ => action(), null); } /// <summary> /// 刷新显示信息 /// </summary> void RefreshInfo() { } /// <summary> /// 选择串口后,等下ini文件里面保存的数据 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void PortMouseDown_Click(object sender, MouseButtonEventArgs e) { if (ComCommbox.Text != "") { WritePrivateProfileString("COM", "COM", ComCommbox.Text, FileName); //选中后更新保存在文件的波特率名称 } } /// <summary> /// 窗口关闭事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void MainWindowsClosed(object sender, EventArgs e) { isRun = false;//关闭串口接收线程 //关闭数据保存线程 } /// <summary> /// 清理数据 /// </summary> void ClearResseiveData() { plotter.Children.Remove(graphVol1); plotter.Children.Remove(graphVol2); plotter.Children.Remove(graphVol3); plotter.Children.Remove(graphVol4); plotter.Children.Remove(graphVol5); plotter.Children.Remove(graphVol6); plotter.Children.Remove(graphVol7); plotter.Children.Remove(graphVol8); plotter.Children.Remove(graphVol9); plotter.Children.Remove(graphVol10); plotter.Children.Remove(graphVol11); plotter.Children.Remove(graphVol12); plotter.Children.Remove(graphVol13); plotter.Children.Remove(graphVol14); plotter.Children.Remove(graphVol15); plotter.Children.Remove(graphVol16); dataVol1 = new ObservableDataSource<Point>(); dataVol2 = new ObservableDataSource<Point>(); dataVol3 = new ObservableDataSource<Point>(); dataVol4 = new ObservableDataSource<Point>(); dataVol5 = new ObservableDataSource<Point>(); dataVol6 = new ObservableDataSource<Point>(); dataVol7 = new ObservableDataSource<Point>(); dataVol8 = new ObservableDataSource<Point>(); dataVol9 = new ObservableDataSource<Point>(); dataVol10 = new ObservableDataSource<Point>(); dataVol11 = new ObservableDataSource<Point>(); dataVol12 = new ObservableDataSource<Point>(); dataVol13 = new ObservableDataSource<Point>(); dataVol14 = new ObservableDataSource<Point>(); dataVol15 = new ObservableDataSource<Point>(); dataVol16 = new ObservableDataSource<Point>(); plotter.Viewport.FitToView(); graphVol1 = plotter.AddLineGraph(dataVol1, Colors.Red, 2, "CH1"); graphVol2 = plotter.AddLineGraph(dataVol2, Colors.Orange, 2, "CH2"); graphVol3 = plotter.AddLineGraph(dataVol3, Colors.Yellow, 2, "CH3"); graphVol4 = plotter.AddLineGraph(dataVol4, Colors.Green, 2, "CH4"); graphVol5 = plotter.AddLineGraph(dataVol5, Colors.Cyan, 2, "CH5"); graphVol6 = plotter.AddLineGraph(dataVol6, Colors.Blue, 2, "CH6"); graphVol7 = plotter.AddLineGraph(dataVol7, Colors.Purple, 2, "CH7"); graphVol8 = plotter.AddLineGraph(dataVol8, Colors.Pink, 2, "CH8"); graphVol9 = plotter.AddLineGraph(dataVol9, Colors.Brown, 2, "CH9"); graphVol10 = plotter.AddLineGraph(dataVol10, Colors.Gray, 2, "CH10"); graphVol11 = plotter.AddLineGraph(dataVol11, Colors.Black, 2, "CH11"); graphVol12 = plotter.AddLineGraph(dataVol12, Colors.Beige, 2, "CH12"); graphVol13 = plotter.AddLineGraph(dataVol13, Colors.LightBlue, 2, "CH13"); graphVol14 = plotter.AddLineGraph(dataVol14, Colors.DarkBlue, 2, "CH14"); graphVol15 = plotter.AddLineGraph(dataVol15, Colors.LightGreen, 2, "CH15"); graphVol16 = plotter.AddLineGraph(dataVol16, Colors.DarkGreen, 2, "CH16"); plotter.Viewport.FitToView(); RealVol1.Text = "0"; RealVol2.Text = "0"; RealVol3.Text = "0"; RealVol4.Text = "0"; RealVol5.Text = "0"; RealVol6.Text = "0"; RealVol7.Text = "0"; RealVol8.Text = "0"; RealVol9.Text = "0"; RealVol10.Text = "0"; RealVol11.Text = "0"; RealVol12.Text = "0"; RealVol13.Text = "0"; RealVol14.Text = "0"; RealVol15.Text = "0"; RealVol16.Text = "0"; uindex = 0; } } } <Window x:Class="DigitalContorPower.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:DigitalContorPower" xmlns:d3="http://research.microsoft.com/DynamicDataDisplay/1.0" xmlns:input="clr-namespace:System.Windows.Input;assembly=PresentationCore" mc:Ignorable="d" Title="压力传感器" Height="700" Width="1100" MinHeight="360" MinWidth="800" Closed="MainWindowsClosed"> <Window.Background> <ImageBrush ImageSource="Picture/backed.jpg"/> </Window.Background> <Grid> <Grid Margin="0,1,0,0"> <DockPanel> <Grid> <Grid.RowDefinitions> <RowDefinition Height="61*" /> <RowDefinition Height="3"/> <RowDefinition Height="100"/> </Grid.RowDefinitions> <Grid Grid.Column="0" Grid.Row="0"> <Grid> <Grid Grid.Column="0" Grid.Row="0"> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="1*"/> </Grid.ColumnDefinitions> <d3:ChartPlotter x:Name="plotter" Margin="3" > <d3:ChartPlotter.VerticalAxis> <d3:VerticalIntegerAxis /> </d3:ChartPlotter.VerticalAxis> <d3:ChartPlotter.HorizontalAxis> <d3:HorizontalIntegerAxis Name="dateAxis"/> </d3:ChartPlotter.HorizontalAxis> <d3:Header Content="压力波形图"/> <d3:VerticalAxisTitle /> </d3:ChartPlotter> </Grid> </Grid> </Grid> </Grid> <Grid Grid.Column="0" Background="Black" Margin="0,0,0,2" Grid.Row="1"> </Grid> <Grid Grid.Column="0" Grid.Row="2"> <Grid.ColumnDefinitions> <ColumnDefinition Width="200*"/> <ColumnDefinition Width="120"/> </Grid.ColumnDefinitions> <Grid Grid.Column="0" Grid.Row="0"> <Grid.RowDefinitions> <RowDefinition Height="5*"/> <RowDefinition Height="5*"/> <RowDefinition Height="5*"/> <RowDefinition Height="5*"/> </Grid.RowDefinitions> <Grid Grid.Column="0" Grid.Row="0"> <Grid.ColumnDefinitions> <ColumnDefinition Width="3*"/> <ColumnDefinition Width="3*"/> <ColumnDefinition Width="3*"/> <ColumnDefinition Width="3*"/> </Grid.ColumnDefinitions> <TextBox Name="RealVol1" Grid.Column="0" Grid.Row="0" Text="0" IsReadOnly="True" Background="Black" Foreground="Cyan" TextAlignment="Center" ></TextBox> <TextBox Name="RealVol2" Grid.Column="1" Grid.Row="0" Text="0" IsReadOnly="True" Background="Black" Foreground="Cyan" TextAlignment="Center" ></TextBox> <TextBox Name="RealVol3" Grid.Column="2" Grid.Row="0" Text="0" IsReadOnly="True" Background="Black" Foreground="Cyan" TextAlignment="Center" ></TextBox> <TextBox Name="RealVol4" Grid.Column="3" Grid.Row="0" Text="0" IsReadOnly="True" Background="Black" Foreground="Cyan" TextAlignment="Center" ></TextBox> </Grid> <Grid Grid.Column="0" Grid.Row="1"> <Grid.ColumnDefinitions> <ColumnDefinition Width="3*"/> <ColumnDefinition Width="3*"/> <ColumnDefinition Width="3*"/> <ColumnDefinition Width="3*"/> </Grid.ColumnDefinitions> <TextBox Name="RealVol5" Grid.Column="0" Grid.Row="0" Text="0" IsReadOnly="True" Background="Black" Foreground="Cyan" TextAlignment="Center" ></TextBox> <TextBox Name="RealVol6" Grid.Column="1" Grid.Row="0" Text="0" IsReadOnly="True" Background="Black" Foreground="Cyan" TextAlignment="Center" ></TextBox> <TextBox Name="RealVol7" Grid.Column="2" Grid.Row="0" Text="0" IsReadOnly="True" Background="Black" Foreground="Cyan" TextAlignment="Center" ></TextBox> <TextBox Name="RealVol8" Grid.Column="3" Grid.Row="0" Text="0" IsReadOnly="True" Background="Black" Foreground="Cyan" TextAlignment="Center" ></TextBox> </Grid> <Grid Grid.Column="0" Grid.Row="2"> <Grid.ColumnDefinitions> <ColumnDefinition Width="3*"/> <ColumnDefinition Width="3*"/> <ColumnDefinition Width="3*"/> <ColumnDefinition Width="3*"/> </Grid.ColumnDefinitions> <TextBox Name="RealVol9" Grid.Column="0" Grid.Row="0" Text="0" IsReadOnly="True" Background="Black" Foreground="Cyan" TextAlignment="Center" ></TextBox> <TextBox Name="RealVol10" Grid.Column="1" Grid.Row="0" Text="0" IsReadOnly="True" Background="Black" Foreground="Cyan" TextAlignment="Center" ></TextBox> <TextBox Name="RealVol11" Grid.Column="2" Grid.Row="0" Text="0" IsReadOnly="True" Background="Black" Foreground="Cyan" TextAlignment="Center" ></TextBox> <TextBox Name="RealVol12" Grid.Column="3" Grid.Row="0" Text="0" IsReadOnly="True" Background="Black" Foreground="Cyan" TextAlignment="Center" ></TextBox> </Grid> <Grid Grid.Column="0" Grid.Row="3"> <Grid.ColumnDefinitions> <ColumnDefinition Width="3*"/> <ColumnDefinition Width="3*"/> <ColumnDefinition Width="3*"/> <ColumnDefinition Width="3*"/> </Grid.ColumnDefinitions> <TextBox Name="RealVol13" Grid.Column="0" Grid.Row="0" Text="0" IsReadOnly="True" Background="Black" Foreground="Cyan" TextAlignment="Center" ></TextBox> <TextBox Name="RealVol14" Grid.Column="1" Grid.Row="0" Text="0" IsReadOnly="True" Background="Black" Foreground="Cyan" TextAlignment="Center" ></TextBox> <TextBox Name="RealVol15" Grid.Column="2" Grid.Row="0" Text="0" IsReadOnly="True" Background="Black" Foreground="Cyan" TextAlignment="Center" ></TextBox> <TextBox Name="RealVol16" Grid.Column="3" Grid.Row="0" Text="0" IsReadOnly="True" Background="Black" Foreground="Cyan" TextAlignment="Center" ></TextBox> </Grid> </Grid> <Grid Grid.Column="1" Grid.Row="0"/> <Grid Grid.Column="2" Grid.Row="0"> <Grid.RowDefinitions> <RowDefinition Height="5*"/> <RowDefinition Height="5*"/> </Grid.RowDefinitions> <Grid Grid.Column="0" Grid.Row="0"> <Grid.ColumnDefinitions> <ColumnDefinition Width="2*"/> <ColumnDefinition Width="3*"/> </Grid.ColumnDefinitions> </Grid> <Grid Grid.Column="0" Grid.Row="1"> <Grid.ColumnDefinitions> <ColumnDefinition Width="2*"/> <ColumnDefinition Width="3*"/> </Grid.ColumnDefinitions> </Grid> </Grid> <Grid Grid.Column="2" Grid.Row="0"> <Grid.RowDefinitions> <RowDefinition Height="4*"/> <RowDefinition Height="5*"/> </Grid.RowDefinitions> <Grid Grid.Column="0" Grid.Row="0"> <Grid.ColumnDefinitions> <ColumnDefinition Width="5*"/> <ColumnDefinition Width="2*"/> </Grid.ColumnDefinitions> <ComboBox Name="ComCommbox" PreviewMouseDown="Com__PreviewMouseDown" Margin="8,0,0,0" Grid.Column="0" Grid.Row="0" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" MouseDown="PortMouseDown_Click" > </ComboBox> <Image Name="ButtonImage" Margin="1,0,0,0" Grid.Column="1" Grid.Row="0" Source="Picture/redlight.png" Width="20" Height="20" ></Image> </Grid> <Grid Grid.Column="0" Grid.Row="1" Margin="0,1,1,1"> <Grid.ColumnDefinitions> <ColumnDefinition Width="5*"/> <ColumnDefinition Width="2*"/> </Grid.ColumnDefinitions> <Button Margin="8,0,0,0" Name="ConnectButton" Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="0" Content="Connect" Click="ConnectButton_Click" ></Button> </Grid> </Grid> </Grid> </Grid> </DockPanel> </Grid> </Grid> </Window> 改成scottplot
最新发布
05-17
评论 8
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值