WinForm学习笔记

一、图表类

1、ScottPlot

①初始化

普通的winform控件可以直接从窗口拖拽创建,但scottplot下载库后也能在工具箱控件列表看见,但拖拽后就会报错。试过方法有:卸载重装库;重新创建Dotnet解决方案(一开始是framework),没有效果后放弃。手动在后台代码中添加控件,示例代码如下:

formsPlot2 = new FormsPlot();
// 
// formsplot2
// 
formsPlot2.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
formsPlot2.DisplayScale = 1F;
formsPlot2.Location = new Point(733, 211);
formsPlot2.Name = "formsplot2";
formsPlot2.Size = new Size(695, 300);
formsPlot2.TabIndex = 6;
Controls.Add(formsPlot2);

②添加曲线

formsPlot1.Reset();
ScottPlot.Plot plot = formsPlot1.Plot;
var series1 = plot.Add.ScatterLine(xposList, yposList);
///设置轴上下限
//plot.Axes.SetLimits(xposList.Min(), xposList.Max(), yposList.Min(), yposList.Max());
///设置轴自适应
//plot.Axes.AutoScale();
///画面轴省略,相当于放大效果
//plot.Layout.Frameless();
///纯中文可以,混搭不行
series1.LegendText =Fonts.Detect( "光谱spectrum1520-1570nm");

formsPlot1.Refresh();

③保存图表

!若设置visible=false后,保存图像时是一片黑;正常情况下不会
解决方案:问了AI爹后,保存前设置为可见保存后再改回来

formsPlot1.Visible = true;
string fullFilePath = System.IO.Path.Combine(filePath, "newchart1-1.jpg");
formsPlot1.SaveToImage(fullFilePath,System.Drawing.Imaging.ImageFormat.Jpeg);
formsPlot1.Visible = false;

上述情况发生在直接使用formplot类的savetoimage方法时发生,改用plot.SaveJpeg等方法就可以正常保存,PS:png图片格式大小大于jpg

string fullFilePath = System.IO.Path.Combine(filePath, "newchart1-png.jpg");
formsPlot1.Plot.SavePng(fullFilePath, 800, 300);
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值