赞
踩
- using System;
- using System.Diagnostics;
- using System.Threading;
- using System.Windows;
-
- namespace ScottplotTest
- {
- /// <summary>
- /// MainWindow.xaml 的交互逻辑
- /// </summary>
- public partial class MainWindow : Window
- {
-
- double[] myData1 = new double[200];
- double[] myData2 = new double[200];
- ScottPlot.Plottable.SignalPlot signalPlot1;
- ScottPlot.Plottable.SignalPlot signalPlot2;
- bool initflag = false;
-
- public MainWindow()
- {
- InitializeComponent();
-
- this.Closing += CloseWindow;
-
- signalPlot1 = this.WpfPlot1.Plot.AddSignal(myData1, 0.1, System.Drawing.Color.Black, label: "曲线1");
- signalPlot2 = this.WpfPlot1.Plot.AddSignal(myData2, 0.1, System.Drawing.Color.Magenta, label: "曲线2");
-
-
- //WpfPlot1.Plot.XAxis.Label("Time (milliseconds)");
- WpfPlot1.Plot.YAxis.Label("Celsius temperature (°C)");
- WpfPlot1.Plot.XAxis2.Label("Title");
-
- // One Axis Only
- WpfPlot1.Plot.XAxis.Ticks(false);
- WpfPlot1.Plot.XAxis.Line(false);
- WpfPlot1.Plot.YAxis2.Line(false);
- WpfPlot1.Plot.XAxis2.Line(false);
-
-
- Thread SPdataProcessing = new Thread(RefreshOPMUI);
-
- //signalPlot1.Label = "a";
- // signalPlot2.Label = "b";
-
- WpfPlot1.Plot.Legend();
-
- WpfPlot1.Refresh();
-
- signalPlot1.IsVisible = true;
- signalPlot2.IsVisible = true;
-
- initflag = true;
-
- signalPlot1.OffsetX = 0;
- signalPlot2.OffsetX = 0;
-
-
- SPdataProcessing.Start();
-
- Array.Copy(myData1, 1, myData1, 0, myData1.Length - 1);
- Array.Copy(myData2, 1, myData2, 0, myData2.Length - 1);
-
- myData1[myData1.Length - 1] = 50;
- myData2[myData2.Length - 1] = 20;
- WpfPlot1.Refresh();
-
-
-
- }
-
- public void RefreshOPMUI()
- {
- while (true)
- {
- Random rd = new Random();
-
- int v1 = rd.Next(0, 200);
- int v2 = rd.Next(0, 1000);
-
- // double[] values = ScottPlot.DataGen.RandomWalk(rand, 2);
- Array.Copy(myData1, 1, myData1, 0, myData1.Length - 1);
- Array.Copy(myData2, 1, myData2, 0, myData2.Length - 1);
-
- myData1[myData1.Length - 1] = v1;
- myData2[myData2.Length - 1] = v2;
- Dispatcher.Invoke(new Action(delegate
- {
- WpfPlot1.Refresh();
- WpfPlot1.Plot.AxisAutoY();
- // WpfPlot1.Plot.AxisAutoX();
- }));
-
-
- Thread.Sleep(50);
- }
- }
-
- // 关闭窗口
- private void CloseWindow(object sender, System.ComponentModel.CancelEventArgs e)
- {
- Process.GetCurrentProcess().Kill();
- this.Close();
- }
-
-
- private void CheckBox_Checked(object sender, RoutedEventArgs e)
- {
- if (initflag == false) {
- return;
- }
- if (checkBox.IsChecked == true) {
- signalPlot1.IsVisible = true;
- }
- else{
- signalPlot1.IsVisible = false;
- }
- }
-
- private void CheckBox1_Checked(object sender, RoutedEventArgs e)
- {
- if (initflag == false)
- {
- return;
- }
- if (checkBox1.IsChecked == true)
- {
- signalPlot2.IsVisible = true;
- }
- else
- {
- signalPlot2.IsVisible = false;
- }
- }
- }
- }
- <Window x:Class="ScottplotTest.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:ScottplotTest"
- mc:Ignorable="d"
- Title="MainWindow" Height="450" Width="800">
- <Grid>
- <WpfPlot Name="WpfPlot1" Margin="0,0,107,59" />
- <CheckBox x:Name="checkBox" Content="曲线1" IsChecked="True" HorizontalAlignment="Left" Margin="695,275,0,0" VerticalAlignment="Top" Checked="CheckBox_Checked" Unchecked="CheckBox_Checked"/>
- <CheckBox x:Name="checkBox1" Content="曲线2" IsChecked="True" HorizontalAlignment="Left" Margin="695,300,0,0" VerticalAlignment="Top" Checked="CheckBox1_Checked" Unchecked="CheckBox1_Checked"/>
- </Grid>
- </Window>
ScottPlotTestVideo2
所以离线移植到新的项目的时候,需要拷贝 packages文件夹 以及 packages.config文件
对比安装前与安装后
1、ScottPlot引用路径:
packages\ScottPlot.4.1.59\lib\netstandard2.0\ScottPlot.dll
2、ScottPlot.WPF引用路径:
packages\ScottPlot.WPF.4.1.59\lib\net461\ScottPlot.WPF.dll
3、System.Drawing引用路径:
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\System.Drawing.dll
4、System.Drawing.Common引用路径:
packages\System.Drawing.Common.4.6.1\lib\net461\System.Drawing.Common.dll
5、System.Numerics引用路径:
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\System.Numerics.dll
6、System.Numerics.Vectors引用路径:
packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll
4个引用的操作步骤一样,就不一一截图了。
新建项目
注意:新建程序时 框架是:.NET Framework 4.6.1,所以安装的ScottPlot很多引用路径都是n461.
离线移植的程序,最好也选这:.NET Framework 4.6.1
感谢您的阅读,欢迎留言讨论、收藏、点赞、分享。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。