aardio调用c# ScottPlot 控件显示波形图
ScottPlot是用c# .net编写的波形图控件, 在winforms上性能优异, 上手简单, 只需要几行代码即可生成漂亮丝滑的波形图. 支持 折线图 / 直方图 / 饼图 / 散点图, 等等,
关键是开源免费MIT.
github地址: https://github.com/scottplot/scottplot
特别注意:
运行以下示例 , 请将aardio升级到 v34.39.0 以上 , 因为此版本jacenHe老大对dotnet库进行了大幅度的更新, 下面代码里用到了最新的功能.
↓↓↓↓↓ScottPlot4.1.35版本控件↓↓↓↓
第一版 简易封装调用库:
我将以下示例中常用的一些函数封装了库, 因为函数太多了,
没文档, 要读代码慢慢看函数, 先这样, 以后慢慢增加吧.
↓↓↓↓demo↓↓↓↓↓
第一个示例:
import win.ui; /*DSG{{*/ var winform = win.form(text="aardio form";right=759;bottom=469) winform.add( custom={cls="custom";text="自定义控件";left=0;top=0;right=760;bottom=470;bgcolor=12639424;db=1;dl=1;dr=1;dt=1;z=1} ) /*}}*/ import dotNet; var dll = dotNet.load("\ScottPlot.WinForms.dll"); var Chart = dll.new("ScottPlot.FormsPlot"); //绑定界面 dotNet.setParent(Chart,winform.custom); var Plotdll = dotNet.load("\ScottPlot.dll"); var DataGen = Plotdll.import("ScottPlot.DataGen"); var xs = DataGen.Consecutive(51); var sin = DataGen.Sin(51); var cos = DataGen.Cos(51); var plt = Chart.Plot; // 2条曲线 plt.AddScatter(xs, sin); plt.AddScatter(xs, cos); // plot参数设置 plt.Title("aardio调用c# ScottPlot 控件"); plt.XLabel("X轴"); plt.YLabel("Y轴"); plt.AddCrosshair(0.0, 0.0); Chart.Refresh(true); winform.show(); win.loopMessage();
双Y轴:
import dotNet; var dll = dotNet.load("\ScottPlot.WinForms.dll"); var Chart = dll.new("ScottPlot.FormsPlot"); //绑定界面 dotNet.setParent(Chart,winform.custom); var Plotdll = dotNet.load("\ScottPlot.dll"); var DataGen = Plotdll.import("ScottPlot.DataGen"); var plt = Chart.Plot; // plot one set of data using the primary Y axis var sigSmall = plt.AddSignal(DataGen.Sin(51, com.double(1))); sigSmall.YAxisIndex = 0; plt.YAxis.Label("Primary Axis"); plt.YAxis.Color(sigSmall.Color); // plot another set of data using an additional axis var sigBig = plt.AddSignal(DataGen.Cos(51,com.double(1),com.double(0),com.double(100))); var yAxis3 = plt.AddAxis(0/*Left*/, 2); sigBig.YAxisIndex = 2; yAxis3.Label("Additional Axis"); yAxis3.Color(sigBig.Color);; Chart.Refresh(true);
事件交互:
鼠标动态移动十字标尺进行交互
运行下面代码, 需要 aardio v34.36.0 版本以上. 因为dotnet库需要最新功能支持.
import win.ui; /*DSG{{*/ var winform = win.form(text="aardio form";right=759;bottom=469) winform.add( custom={cls="custom";text="自定义控件";left=0;top=0;right=760;bottom=470;bgcolor=12639424;db=1;dl=1;dr=1;dt=1;z=1} ) /*}}*/ import dotNet; var dll = dotNet.load("\ScottPlot.WinForms.dll"); var Chart = dll.new("ScottPlot.FormsPlot"); //绑定界面 dotNet.setParent(Chart,winform.custom); var Plotdll = dotNet.load("\ScottPlot.dll"); var DataGen = Plotdll.import("ScottPlot.DataGen"); var plt = Chart.Plot; var xs = DataGen.Consecutive(51); var sin = DataGen.Sin(51); var cos = DataGen.Cos(51); // 2条曲线 plt.AddScatter(xs, sin); plt.AddScatter(xs, cos); // plot参数设置 plt.Title("aardio调用c# ScottPlot 控件"); plt.XLabel("X轴"); plt.YLabel("Y轴"); var Crosshair = plt.AddCrosshair(15.0, 0.25); Crosshair.VerticalLine.IsVisible = false; Crosshair.HorizontalLine.IsVisible = false; Chart.Refresh(true); Chart.MouseEnter = function(e,r){ Crosshair.VerticalLine.IsVisible = true; Crosshair.HorizontalLine.IsVisible = true Chart.Refresh(false,false); } Chart.MouseLeave = function(e,r){ Crosshair.VerticalLine.IsVisible = false; Crosshair.HorizontalLine.IsVisible = false; Chart.Refresh(false,false); } Chart.MouseMove = function(){ var mouseCoordinates = Chart.GetMouseCoordinates(0,0); Crosshair.X = mouseCoordinates.Item1; Crosshair.Y = mouseCoordinates.Item2; Chart.Refresh(false,true); } winform.show(); win.loopMessage();
实时刷新方式:
import win.ui; /*DSG{{*/ var winform = win.form(text="aardio form";right=759;bottom=469;bgcolor=8421504) winform.add( custom={cls="custom";text="自定义控件";left=0;top=0;right=760;bottom=470;bgcolor=12639424;db=1;dl=1;dr=1;dt=1;z=1} ) /*}}*/ import dotNet; var dll = dotNet.load("\ScottPlot.WinForms.dll"); var Chart = dll.new("ScottPlot.FormsPlot"); //绑定界面 dotNet.setParent(Chart,winform.custom); var Plotdll = dotNet.load("\ScottPlot.dll"); var DataGen = Plotdll.import("ScottPlot.DataGen"); var plt = Chart.Plot; //初始化一个数组 var liveData = table.array(400,0); //设置初始曲线值,返回曲线 var liveplot = plt.AddSignal( liveData ); plt.AxisAutoX(0,0); plt.SetAxisLimits(null,null,-1,2.5,0,0); //显示一根垂直线,后面用来观察刷新移动 var vline = plt.AddVerticalLine(com.double(0), null,com.float(2)); // customize styling plt.Title("Electrocardiogram Strip Chart"); plt.YLabel("Potential (mV)"); plt.XLabel("Time (seconds)"); plt.Grid(false); //最后必须 Chart.Refresh(true,false); var index = 0; winform.setInterval( 50,function(){ if(index>399){ index=0 } //更新特定Y值 liveplot.Update(index,math.random()); //移动垂直线 vline.X = index; //必须 Chart.Refresh(true,false); index++; } ); winform.show(); win.loopMessage();
定时器里更新数据, 有两种方式:
1, 就是上面那个用,更新特定Y轴数据
//更新特定Y值 liveplot.Update(index,math.random());
2,一次性更新所有数据
liveData = { ... }; liveplot.Ys = liveData;
3,利用新增的数组定义dotnet.double({...}),和C#进行内存共享, 直接更新数组值.
import dotNet; var dll = dotNet.load("\ScottPlot.WinForms.dll"); var Chart = dll.new("ScottPlot.FormsPlot"); //绑定界面 dotNet.setParent(Chart,winform.custom); var Plotdll = dotNet.load("\ScottPlot.dll"); var DataGen = Plotdll.import("ScottPlot.DataGen"); var plt = Chart.Plot; /****------------初始化一个数组------****/ var data = table.array(400,0); var liveData = dotNet.double(data); /****-------------------------------****/ //设置初始曲线值,返回曲线 var liveplot = plt.AddSignal( liveData ); plt.AxisAutoX(0,0); plt.SetAxisLimits(null,null,-1,2.5,0,0); //显示一根垂直线,后面用来观察刷新移动 var vline = plt.AddVerticalLine(com.double(0), null,com.float(2)); // customize styling plt.Title("Electrocardiogram Strip Chart"); plt.YLabel("Potential (mV)"); plt.XLabel("Time (seconds)"); plt.Grid(false); //最后必须 Chart.Refresh(true,false); var index = 0; winform.setInterval( 50,function(){ if(index>399){ index=0 } /****-------------------------------****/ //利用dotnet库新增特性, 和c#共享内存, 直接更新数组即可 liveData[index+1]=math.random(); /****-------------------------------****/ //移动垂直线 vline.X = index; //必须 Chart.Refresh(true,false); index++; } );
import win.ui; /*DSG{{*/ var winform = win.form(text="aardio form";right=759;bottom=469;bgcolor=8421504) winform.add( custom={cls="custom";text="自定义控件";left=0;top=0;right=760;bottom=470;bgcolor=12639424;db=1;dl=1;dr=1;dt=1;z=1} ) /*}}*/ import dotNet; var dll = dotNet.load("\ScottPlot.WinForms.dll"); var Chart = dll.new("ScottPlot.FormsPlot"); //绑定界面 dotNet.setParent(Chart,winform.custom); var Plotdll = dotNet.load("\ScottPlot.dll"); var DataGen = Plotdll.import("ScottPlot.DataGen"); var plt = Chart.Plot; //初始化一个数组 var liveData = table.array(400,0); //设置初始曲线值,返回曲线 var liveplot = plt.AddSignal( liveData ); plt.AxisAutoX(0,0); plt.SetAxisLimits(null,null,-1,1,0,0); // customize styling plt.Title("Electrocardiogram Strip Chart"); plt.YLabel("Potential (mV)"); plt.XLabel("Time (seconds)"); plt.Grid(false); //最后必须 Chart.Refresh(true,false); winform.setInterval( 50,function(){ //整个更新 table.shift(liveData,1); table.push(liveData,math.random()); liveplot.Ys = liveData; //必须 Chart.Refresh(true,false); } ); winform.show(); win.loopMessage();
更多实时波形图示例: https://scottplot.net/faq/live-data/
多图表联动:
联动其实上就是当A移动的时候, 将剩下的BCD....其他窗口设置SetAxisLimits即可.
运行下面代码, 需要 aardio v34.34.0 版本以上. 因为dotnet库需要最新功能支持.
import win.ui; /*DSG{{*/ var winform = win.form(text="aardio form";right=759;bottom=461;bgcolor=8421504) winform.add( custom={cls="custom";text="自定义控件";left=0;top=0;right=760;bottom=227;bgcolor=12639424;db=1;dl=1;dr=1;dt=1;z=1}; custom2={cls="custom";text="自定义控件";left=0;top=235;right=760;bottom=462;bgcolor=12639424;db=1;dl=1;dr=1;dt=1;z=2}; splitter={cls="splitter";left=0;top=229;right=760;bottom=234;bgcolor=32896;dl=1;dr=1;dt=0.5;horz=1;z=3} ) /*}}*/ winform.splitter.split(winform.custom,winform.custom2) import dotNet; var dll = dotNet.load("\ScottPlot.WinForms.dll"); var Chart = dll.new("ScottPlot.FormsPlot"); //绑定界面 dotNet.setParent(Chart,winform.custom); var Chart2 = dll.new("ScottPlot.FormsPlot"); //绑定界面 dotNet.setParent(Chart2,winform.custom2); var Plotdll = dotNet.load("\ScottPlot.dll"); var DataGen = Plotdll.import("ScottPlot.DataGen"); var sin = DataGen.Sin(51); var cos = DataGen.Cos(51); Chart.Plot.AddSignal(sin); Chart2.Plot.AddSignal(cos); Chart.Refresh(true); Chart2.Refresh(true); Chart.AxesChanged = function(sender,e){ var newAxisLimits = Chart.Plot.GetAxisLimits(0, 0); //disable events briefly to avoid an infinite loop Chart2.Configuration.AxesChangedEventEnabled = false; Chart2.Plot.SetAxisLimits(newAxisLimits); Chart2.Refresh(true); Chart2.Configuration.AxesChangedEventEnabled = true; } Chart2.AxesChanged = function(sender,e){ var newAxisLimits = Chart2.Plot.GetAxisLimits(0, 0); //disable events briefly to avoid an infinite loop Chart.Configuration.AxesChangedEventEnabled = false; Chart.Plot.SetAxisLimits(newAxisLimits); Chart.Refresh(true); Chart.Configuration.AxesChangedEventEnabled = true; } winform.show(); win.loopMessage();
import dotNet; var dll = dotNet.load("\ScottPlot.WinForms.dll"); var Chart = dll.new("ScottPlot.FormsPlot"); var plt = Chart.Plot; //绑定界面 dotNet.setParent(Chart,winform.custom); var Plotdll = dotNet.load("\ScottPlot.dll"); var DataGen = Plotdll.import("ScottPlot.DataGen"); var Tools = Plotdll.import("ScottPlot.Tools"); rs = table.array(400,0); thetas = table.array(400,0); for (i = 1; 400; 1) { rs[i] = 1 + i * 0.01; thetas[i] = i * 2 * 3.1415 * 0.01; } // convert polar data to Cartesian data data = Tools.ConvertPolarCoordinates(rs, thetas); // plot the Cartesian data plt.AddScatter(data.Item1, data.Item2); // decorate the plot plt.Title("Scatter Plot of Polar Data"); plt.AxisScaleLock(true); Chart.Refresh(true);
import ScottPlot; var Chart = ScottPlot.FormsPlot(); //绑定界面 dotNet.setParent(Chart,mainForm.custom); var vArr = table.array(20,0); var YArr = table.array(20,0); for(i=1;20;1){ vArr[i]=math.random()*100; YArr[i]=i; } var bar = Chart.Plot.AddBar(vArr, YArr); bar.BarWidth = 1; //bar.ShowValuesAboveBars = true; //bar.HatchStyle = ScottPlot.Drawing.HatchStyle.StripedUpwardDiagonal; // customize the plot style Chart.Plot.YAxis.Label("Count (#)"); Chart.Plot.XAxis.Label("Height (cm)"); Chart.Plot.SetAxisLimits(null,null,0,null,0,0); Chart.Refresh(true,false);
线性回归:
import System.ValueTuple; import ScottPlot; var Chart = ScottPlot.FormsPlot(); //绑定界面 dotNet.setParent(Chart,mainForm.custom); var ys = ScottPlot.DataGen.NoisyLinear(null, 100,1,30, 20); var xs = ScottPlot.DataGen.Consecutive(#ys); var x1 = xs[1]; var x2 = xs[#xs]; var arr = System.ValueTuple.Create(dotNet.double(x1),dotNet.double(x2)); // use the linear regression fitter to fit these data var model = ScottPlot.Statistics.LinearRegressionLine(xs, ys); // plot the original data and add the regression line Chart.Plot.Title('Linear Regression\n' ++ "Y = "++model.slope++"x + "++model.offset++ " (R² = "++model.rSquared++")"); Chart.Plot.AddScatter(xs, ys, null, 0); Chart.Plot.AddLine(model.slope, model.offset, arr,null, 2); Chart.Refresh(true,false);
import System.Drawing; import ScottPlot; var Chart = ScottPlot.FormsPlot(); //绑定界面 dotNet.setParent(Chart,mainForm.custom); var vArr = ScottPlot.DataGen.RandomNormal(0, 1234, 178.4, 7.6); var Histogram = ScottPlot.Statistics.Common.Histogram(vArr, 140, 220, 1, true); var probabilities,binEdges = Histogram.Item1, Histogram.Item2; var YArr = {}; for(i=1;#probabilities;1){ YArr[i]=139+i; } var bar = Chart.Plot.AddBar(probabilities, YArr); bar.BarWidth = 1; bar.FillColor = System.Drawing.Color.LightGreen; bar.BorderColor = System.Drawing.Color.MediumBlue; var densities = ScottPlot.Statistics.Common.ProbabilityDensity(vArr, binEdges); Chart.Plot.AddScatterLines( binEdges, densities, System.Drawing.Color.Black, 2, ScottPlot.LineStyle.Dash); // customize the plot style Chart.Plot.Title("Adult Male Height"); Chart.Plot.YAxis.Label("Probability"); Chart.Plot.XAxis.Label("Height (cm)"); Chart.Plot.SetAxisLimits(null,null,0,null,0,0); Chart.Refresh(true,false);
import System.Drawing; import ScottPlot; var Chart = ScottPlot.FormsPlot(); //绑定界面 dotNet.setParent(Chart,mainForm.custom); var plt = Chart.Plot; var bar1 = plt.AddBar({ 10, 13, 15 }, { 1, 5, 9 }); bar1.HatchStyle = ScottPlot.Drawing.HatchStyle.StripedUpwardDiagonal; bar1.FillColor = System.Drawing.Color.Gray; bar1.FillColorHatch = System.Drawing.Color.Black; bar1.Label = "Series 1"; var bar2 = plt.AddBar({ 14, 15, 9 }, { 2, 6, 10 }); bar2.HatchStyle = ScottPlot.Drawing.HatchStyle.StripedWideDownwardDiagonal; bar2.FillColor = System.Drawing.Color.DodgerBlue; bar2.FillColorHatch = System.Drawing.Color.DeepSkyBlue; bar2.Label = "Series 2"; var bar3 = plt.AddBar({ 13, 6, 14 }, { 3, 7, 11 }); bar3.HatchStyle = ScottPlot.Drawing.HatchStyle.LargeCheckerBoard; bar3.FillColor = System.Drawing.Color.SeaGreen; bar3.FillColorHatch = System.Drawing.Color.DarkSeaGreen; bar3.Label = "Series 3"; // add a legend to display each labeled bar plot plt.Legend(true,1/* Alignment.UpperRight*/); // adjust axis limits so there is no padding below the bar graph Chart.Plot.SetAxisLimits(null,null,0,20,0,0); Chart.Refresh(true,false);
import ScottPlot; var Chart = ScottPlot.FormsPlot(); //绑定界面 dotNet.setParent(Chart,mainForm.custom); var plt = Chart.Plot; var bar = plt.AddBar({ 26, 20, 23, 7, 16 }/*values*/, { 3, 2, 5, 1, 3 }/*errors*/, { 1, 2, 3, 4, 5 }/*positions*/); bar.Orientation = ScottPlot.Orientation.Horizontal; // adjust axis limits so there is no padding below the bar graph Chart.Plot.SetAxisLimits(null,null,0,null,0,0); Chart.Refresh(true,false);
import System.Drawing import ScottPlot; var Chart = ScottPlot.FormsPlot(); //绑定界面 dotNet.setParent(Chart,mainForm.custom); var plt = Chart.Plot; var xs = ScottPlot.DataGen.Consecutive(31); var ys = ScottPlot.DataGen.Sin(31); var colormap = ScottPlot.Drawing.Colormap.Viridis; var myBubblePlot = plt.AddBubblePlot(); for (i = 1; #xs; 1) { var fraction = i / #xs; myBubblePlot.Add( xs[i], ys[i], 10 + i, colormap.GetColor(fraction, alpha: .8), 2, System.Drawing.Color.Black ); } plt.Title("Advanced Bubble Plot"); plt.AxisAuto(0.2, 0.25); // zoom out to accommodate large bubbles Chart.Refresh(true,false);
import ScottPlot; var Chart = ScottPlot.FormsPlot(); //绑定界面 dotNet.setParent(Chart,mainForm.custom); var plt = Chart.Plot; var values = { 11, 16, 7, 3, 14 }; var coxcomb = plt.AddCoxcomb(values); coxcomb.FillColors = plt.Palette.GetColors(5, 0, 0.5); coxcomb.SliceLabels = { "bikes", "blimps", "subs", "saucers", "rockets" }; plt.Legend(true); Chart.Refresh(true,false);
步进图:
import ScottPlot; var Chart = ScottPlot.FormsPlot(); //绑定界面 dotNet.setParent(Chart,mainForm.custom); var plt = Chart.Plot; var pointCount = 50; var dataXs = ScottPlot.DataGen.Consecutive(pointCount); var dataSin = ScottPlot.DataGen.Sin(pointCount); var dataCos = ScottPlot.DataGen.Cos(pointCount); plt.PlotStep(dataXs, dataSin); plt.PlotStep(dataXs, dataCos); //plt.XAxis.MajorGrid(true,System.Drawing.Color.Black,1,2); //plt.YAxis.MajorGrid(true,System.Drawing.Color.Green,0.1,2); Chart.Refresh(true,false);
import System.Drawing import ScottPlot; var Chart = ScottPlot.FormsPlot(); //绑定界面 dotNet.setParent(Chart,mainForm.custom); var plt = Chart.Plot; var xs = ScottPlot.DataGen.Range(0, 10, 0.1, true); var sin = ScottPlot.DataGen.Sin(xs); var cos = ScottPlot.DataGen.Cos(xs); plt.AddFill(xs, sin ); plt.AddFill(xs, cos); plt.AddHorizontalLine(0, System.Drawing.Color.Black); plt.AxisAuto(0); plt.Legend(true,0); Chart.Refresh(true,false);
import System.Drawing import ScottPlot; var Chart = ScottPlot.FormsPlot(); //绑定界面 dotNet.setParent(Chart,mainForm.custom); var plt = Chart.Plot; var values = { 778, 283, 184, 76, 43 }; var labels = {"a","b","c","d","e"}; var pie = plt.AddPie(values); pie.SliceLabels = labels; pie.DonutSize = 0.4;//内圆 pie.DonutLabel = "demo" pie.Explode = true;//分裂 pie.ShowValues = true; pie.ShowLabels = true; pie.ShowPercentages = true; plt.Grid(false); plt.XAxis.Ticks(false, false); plt.YAxis.Ticks(false, false); //plt.Legend(true); Chart.Refresh(false,false);
import System.Drawing import ScottPlot; var Chart = ScottPlot.FormsPlot(); //绑定界面 dotNet.setParent(Chart,mainForm.custom); var plt = Chart.Plot; var xs = { 1, 2, 3, 4 }; var ys1 = { 1, 3, 1, 2 }; var ys2 = { 3, 7, 3, 1 }; var ys3 = { 5, 2, 5, 6 }; // plot line data as polygon corners var paddedXs = ScottPlot.Tools.Pad(xs, 1,0,0,true); plt.AddPolygon(paddedXs, ScottPlot.Tools.Pad(ys3), null, 2, System.Drawing.Color.Black); plt.AddPolygon(paddedXs, ScottPlot.Tools.Pad(ys2), null, 2, System.Drawing.Color.Black); plt.AddPolygon(paddedXs, ScottPlot.Tools.Pad(ys1), null/*System.Drawing.Color.Green*/, 2, System.Drawing.Color.Black); plt.AxisAuto(0, 0); plt.Title("Filled Line Plots"); Chart.Refresh(false,false);
热力图
import ScottPlot; var Chart = ScottPlot.FormsPlot(); //绑定界面 dotNet.setParent(Chart,mainForm.custom); var plt = Chart.Plot; var intensities = table.array(100,100,{}); for ( i = 1; 100; 1) { for ( j = 1; 100; 1) { intensities[i][j] = (math.sin(i * 0.2) + math.cos(j * 0.2)) * 100; } } plt.AddHeatmap(intensities); Chart.Refresh(true);
用热力图画个图片:
import ScottPlot; var Chart = ScottPlot.FormsPlot(); //绑定界面 dotNet.setParent(Chart,mainForm.custom); var plt = Chart.Plot; import gdip.bitmap var bitdata = gdip.bitmap("\1.png").lockData().bits; var col = #bitdata.rows; var row = #bitdata.rows[1].bytes/4; var intensities = table.array(col,row,{}); for ( i = 1; col; 1) { for ( j = 1; row; 1) { intensities[i][j] = bitdata.rows[i].bytes[1+(j-1)*3]; } } plt.AddHeatmap(intensities); Chart.Refresh(true);
更新个任意图例子:
import win.ui; /*DSG{{*/ var mainForm = win.form(text="ScottPlot_Demo";right=796;bottom=627) mainForm.add( custom={cls="custom";text="自定义控件";left=0;top=0;right=797;bottom=628;bgcolor=12639424;db=1;dl=1;dr=1;dt=1;z=1} ) /*}}*/ import dotNet; var dll = dotNet.load("\res\ScottPlot.WinForms.dll"); var Chart = dll.new("ScottPlot.FormsPlot"); var plt = Chart.Plot; //绑定界面 dotNet.setParent(Chart,mainForm.custom); import gdip.bitmap var bitdata = gdip.bitmap("res\1.png").lockData().bits; var row = #bitdata.rows; var col = #bitdata.rows[1].bytes/4; var xs={}; var ys={}; var color={}; for ( i = 1; col; 1) { for ( j = 1; row; 1) { if(bitdata.rows[i].bytes[1+(j-1)*3]<120){ table.push(xs,j); table.push(ys,-1*i); } } } plt.AddScatter(xs, ys, null, 0); Chart.Refresh(true); mainForm.show(); return win.loopMessage();
实时显示波形数据 方式3:
import ScottPlot; var Chart = ScottPlot.FormsPlot(); //绑定界面 dotNet.setParent(Chart,mainForm.custom); //初始化一个超大数组 var data = table.array(1000,0); var liveData = dotNet.double(data); var livePlot = Chart.Plot.AddSignal(liveData); Chart.Plot.SetAxisLimits(0,100,-2,2,0,0); // customize styling Chart.Plot.Title("Electrocardiogram Strip Chart"); Chart.Plot.YLabel("Potential (mV)"); Chart.Plot.XLabel("Time (seconds)"); //最后必须 //Chart.Refresh(true,false); var index = 0; mainForm.setInterval( 10,function(){ //更新数据点 liveData[index+1] = math.sin((index)*0.05); livePlot.MaxRenderIndex = index;//控制显示点 if(index%100==0){//放慢频率(1s), 扩大显示范围 var currentRightEdge = Chart.Plot.GetAxisLimits(0,0).XMax; if(index>=currentRightEdge){//超过边界 //边界扩大100 Chart.Plot.SetAxisLimitsX(0,index+100); } } index ++; if(index>1000){//超过最大数据量重新开始,防止溢出 index = 0; livePlot.MaxRenderIndex = index; Chart.Plot.SetAxisLimitsX(0,index+100); } //必须 Chart.Refresh(true,false); } );
回复#30 @ttfox :
import time.ole; var tm = time.ole(); tm.year = 2022; tm.month = 8; tm.day = 1; import System.ValueTuple; import ScottPlot; var Chart = ScottPlot.FormsPlot(); //绑定界面 dotNet.setParent(Chart,mainForm.custom); var vArr = table.array(10,0); var YArr = table.array(10,0); for(i=1;10;1){ vArr[i]=math.random()*100; //时间转数字 YArr[i]=tonumber( tm.addday(7*i) ); } var bar = Chart.Plot.AddBar(vArr, YArr); bar.BarWidth = 1; // customize the plot style Chart.Plot.YAxis.Label("Count (#)"); Chart.Plot.XAxis.Label("Height (cm)"); Chart.Plot.SetAxisLimits(null,null,0,null,0,0); //手动指定 //var xLabels = { "VII", "XXI", "XXXVII", "XLVI","VII", "XXI", "XXXVII", "XLVI","VII", "XXI" }; //Chart.Plot.XAxis.ManualTickPositions(YArr, xLabels); //手动格式化, //Chart.Plot.XAxis.TickLabelFormat('H/mm\n\ss',true); //自动按照时间格式 Chart.Plot.XAxis.DateTimeFormat(true); Chart.Refresh(true,false);
日期就是个时间戳,aardio范例>语言>时间日期 里有相关日期和时间的示例, scottplot里看官方的cookbook , 里面都有写 , 而且还可以自定义格式化, 具体这些功能你需要自己研究实验了 ,
格式化附录:
登录后方可回帖