一、图表类
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);