110,538
社区成员
发帖
与我相关
我的任务
分享
private void dispplot(NPlot.Windows.PlotSurface2D myplot, List<float> mlist,double dmax,double dmin)
{
int[] myxx = new int[2048];
float[] myyy = new float[2048];
myplot.Clear();
Grid mygrid = new Grid();
mygrid.HorizontalGridType = Grid.GridType.None;
mygrid.VerticalGridType = Grid.GridType.Fine;
myplot.Add(mygrid);
for (int i = 0; i < 2048; i++)
{
myxx[i] = i;
}
myyy = mlist.ToArray();
LinePlot lp = new LinePlot();
lp.Pen = new Pen(Color.Red, 1);
lp.AbscissaData = myxx;
lp.OrdinateData = myyy;
myplot.Add(lp);
LinearAxis liny = (LinearAxis)myplot.YAxis1;
liny.WorldMax = dmax;
liny.WorldMin = dmin;
myplot.YAxis1 = liny;
myplot.Refresh();
}
参考下
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication5
{
public partial class Form1 : Form
{
List<int> values = new List<int>();
Bitmap bitmap = null;
PictureBox pictureBox = null;
int totalShowPointNumber = 30;
public Form1()
{
InitializeComponent();
pictureBox = new PictureBox
{
Parent = this,
Dock = DockStyle.Fill
};
ThreadPool.QueueUserWorkItem(obj =>
{
Random random = new Random();
values.Add(0);
while (true)
{
try
{
bitmap = new Bitmap(pictureBox.Width, pictureBox.Height);
int newValue = random.Next(pictureBox.Height);
values.Add(newValue);
int start = values.Count - totalShowPointNumber;
if (start < 0)
start = 0;
List<Point> pointList = new List<Point>();
for (int i = start; i < values.Count; i++)
{
pointList.Add(new Point((i- start )* pictureBox.Width/totalShowPointNumber, values[i]));
}
using (Graphics graphics = Graphics.FromImage(bitmap))
{
graphics.DrawLines(Pens.Red, pointList.ToArray());
}
pictureBox.Invoke((Action)(() =>
{
pictureBox.Image = bitmap;
}));
Thread.Sleep(100);
}
catch
{
}
}
});
}
}
}