当前位置: 首页 > 工具软件 > OxyPlot > 使用案例 >

[c#][WPF]Message Box,DataTable,Oxyplot画图 常用规则总结

娄建义
2023-12-01

MessageBox 弹框函数

string message = "Do You Want To Use Seleted Data ?";
string title = "Slected Files:" + item.Content.ToString();
MessageBoxResult result = MessageBox.Show(message, title, MessageBoxButton.YesNo);
 if (result == MessageBoxResult.Yes)
    {
   SetItemsListWithSelectedFile(selected_file_path, rat);
    }

使用DataTable 处理Excel表格数据

DataTable库

using System.Data;

DataTable处理函数

//new 新的datatable
DataTabledt = new DataTable();
// 插入列
DataColumndd = new DataColumn("Item", typeof(string));
dt.Columns.Add(dd);
DataColumndd1 = new DataColumn("File", typeof(string));
dt.Columns.Add(dd1);
//插入新行
DataRowdr = dt.NewRow();
dr["Item"] = "File0";
dr["File"] = 0;
dt.Rows.Add(dr);
DataRowdr1 = dt.NewRow();
dr1["Item"] = "File1";
dr1["File"] = 1;
dt.Rows.Add(dr1);
//插入新行到特定行
DataRowdr2 = dt.NewRow();
dr2["Item"] = "File2";
dr2["File"] = 2;
dt.Rows.InsertAt(dr2,1);
//修改已有行内容
DataRowdrr = dt.Rows[1];
drr.BeginEdit();
drr["File"] = 3;
drr.EndEdit();

OxyPlot 画图工具

画直线,可用作limit spec --》 LineAnnotation

使用功能: LineAnnotation

解释: Acomment on a line in a verbatim listing

代码设置:

lineAnnotation_Max = new OxyPlot.Annotations.LineAnnotation();
lineAnnotation_Max.Type = OxyPlot.Annotations.LineAnnotationType.Horizontal;
lineAnnotation_Max.Color = OxyPlot.OxyColors.Red;
lineAnnotation_Max.LineStyle = OxyPlot.LineStyle.Solid;
lineAnnotation_Max.MaximumX = 40;
lineAnnotation_Max.MinimumX = 0;
Model.Annotations.Add(lineAnnotation_Max);

lineAnnotation_Min = new OxyPlot.Annotations.LineAnnotation();
lineAnnotation_Min.Type = OxyPlot.Annotations.LineAnnotationType.Horizontal;
lineAnnotation_Min.MaximumX = 40;
lineAnnotation_Min.MinimumX = 0;
lineAnnotation_Min.Color = OxyPlot.OxyColors.Red;
lineAnnotation_Min.LineStyle = OxyPlot.LineStyle.Solid;
Model.Annotations.Add(lineAnnotation_Min);

定义X Y轴

使用功能: LinearAxis

代码设置:

 LineAxisY = new OxyPlot.Axes.LinearAxis();
  LineAxisY.Angle = 1;
  LineAxisY.Title = "Y axis";
  LineAxisY.TitleColor = OxyColor.FromRgb(20, 120, 220); ;
  LineAxisY.TitleFontSize = 15;
  LineAxisY.AxisDistance = 0;
  LineAxisY.AxislineStyle = OxyPlot.LineStyle.None;
  LineAxisY.AxislineThickness = 1;
  LineAxisY.AxisTickToLabelDistance = 5;
  LineAxisY.AxisTitleDistance = 5;

LineAxisX = new OxyPlot.Axes.LinearAxis();
LineAxisX.Angle = 1;
LineAxisX.Title = "X axis";
  LineAxisX.TitleColor = OxyColor.FromRgb(20, 120, 220);
  LineAxisX.TitleFontSize = 15;
  LineAxisX.AxisDistance = 0;
  LineAxisX.AxislineStyle = OxyPlot.LineStyle.None;
  LineAxisX.AxislineThickness = 1;
  LineAxisX.AxisTickToLabelDistance = 5;

生成散点图

使用工具:ScatterSeries

代码设置:

ScatterSeries series1 = new ScatterSeries { MarkerType = MarkerType.Circle };
List<double> datas = GetDatas(node, dt);
x_point = 1;
foreach (double data in datas)
{
    series1.Points.Add(new ScatterPoint(x_point, data));
    x_point++;
 }
 Model.Series.Add(series1);

图形刷新

//修改完数据后更新UI    
 Model.InvalidatePlot(true);

 类似资料: