官网链接1:点击打开链接(www.oxyplot.org)
官网链接2:http://docs.oxyplot.org/en/latest/
引用资源共享:
链接:https://pan.baidu.com/s/1r9ctsyEYW7_E7x-L99Op8w
密码:dfjm
ps:项目添加引用后可直接使用
1.主要结构
//显示控件PlotView;继承: Control, IPlotView, IView
OxyPlot.WindowsForms.PlotView plotView1;
//PlotModel:Model
SimPlotModel = new OxyPlot.PlotModel();
//Series常用的是曲线:LineSeries
var lineSerial1 = new OxyPlot.Series.LineSeries();
//Axes:坐标轴
var linearAxis1 = new OxyPlot.Axes.LinearAxis();
ps:AreaSeries、BarSeries、BoxPlotSeries、CandleStickSeries、ColumnSeries、PieSeries、RectangleBarSeries、ScatterSeries不做说明。
2.实例详解
步骤:1.新建项目
2.引用资源
3.编写源码
//定义model
public OxyPlot.PlotModel PlotViewModel()
{
lineSerial.Points.Add(new OxyPlot.DataPoint(0, 0));
lineSerial.Points.Add(new OxyPlot.DataPoint(50, 100));
return SimplePlotModel;
}
//main
public Form1()
{
InitializeComponent();
OxyPlot.WindowsForms.PlotView plotView1;
//初始化plotview
plotView1 = new OxyPlot.WindowsForms.PlotView();
plotView1.BackColor = System.Drawing.Color.White;
//plotView1.Dock = System.Windows.Forms.DockStyle.Bottom;
plotView1.Location = new System.Drawing.Point(0, 0);
plotView1.Name = "plotView1";
plotView1.PanCursor = System.Windows.Forms.Cursors.Hand;
plotView1.Size = new System.Drawing.Size(500, 500);
plotView1.TabIndex = 1;
plotView1.Text = "Title";
plotView1.ZoomHorizontalCursor = System.Windows.Forms.Cursors.SizeWE;
plotView1.ZoomRectangleCursor = System.Windows.Forms.Cursors.SizeNWSE;
plotView1.ZoomVerticalCursor = System.Windows.Forms.Cursors.SizeNS;
DateTime dt = DateTime.Now;
plotView1.Tag = "id";
plotView1.MouseClick += plotView1_MouseClick;
PlotViewModle(plotView1, "ttt");
Controls.Add(plotView1);
}
4.花式PlotView
//定义model
public OxyPlot.PlotModel PlotViewModel2()
{
SimplePlotModel = new OxyPlot.PlotModel();
//————————Axes-begin———————— //
var linearAxis01 = new OxyPlot.Axes.LinearAxis();
linearAxis01.Angle = 1; //刻度标示旋转角度
linearAxis01.Title = "Y轴"; //坐标轴标志
linearAxis01.TitleColor = OxyColor.Parse("#d3d3d3"); //标志颜色
linearAxis01.TitleFontSize = 15; //标志字体大小
linearAxis01.AxisDistance = 5; //轴边距,0最佳
linearAxis01.AxislineStyle = OxyPlot.LineStyle.Solid; //轴线类型
linearAxis01.AxislineThickness = 2; //轴线厚度
linearAxis01.AxisTickToLabelDistance = 5; //轴线与标注距离
linearAxis01.AxisTitleDistance = 5; //轴线与轴标志距离
linearAxis01.IsZoomEnabled = false; //是否开启缩放功能
linearAxis01.IsPanEnabled = false; //看名字,不一一说明了
linearAxis01.Minimum = 0;
linearAxis01.Maximum = 60;
linearAxis01.IsAxisVisible = true;
linearAxis01.MajorGridlineStyle = OxyPlot.LineStyle.Solid;
linearAxis01.MinorGridlineStyle = OxyPlot.LineStyle.Dot;
linearAxis01.Position = OxyPlot.Axes.AxisPosition.Left;
linearAxis01.Key = "Key";
linearAxis01.MaximumPadding = 10;
linearAxis01.MinimumPadding = 1;
linearAxis01.MajorGridlineStyle = LineStyle.Solid; //主刻度格网
linearAxis01.MajorGridlineColor = OxyColor.Parse("#777777");
linearAxis01.MinorGridlineStyle = LineStyle.Dot; //子刻度网格
linearAxis01.MinorGridlineColor = OxyColor.Parse("#666666");
var linearAxis02 = new OxyPlot.Axes.LinearAxis();
linearAxis02.Angle = 1;
linearAxis02.Title = "X轴";
linearAxis02.TitleColor = OxyColor.FromRgb(20, 120, 220);
linearAxis02.TitleFontSize = 15;
linearAxis02.AxisDistance = 5;
linearAxis02.AxislineStyle = OxyPlot.LineStyle.Solid;
linearAxis02.AxislineThickness = 2;
linearAxis02.AxisTickToLabelDistance = 5;
linearAxis02.AxisTitleDistance = 5;
linearAxis02.IsZoomEnabled = false;
linearAxis02.IsPanEnabled = false;
linearAxis02.Minimum = 0;
linearAxis02.Maximum = 200;
linearAxis02.IsAxisVisible = true;
linearAxis02.MajorGridlineStyle = OxyPlot.LineStyle.Solid;
linearAxis02.MinorGridlineStyle = OxyPlot.LineStyle.Dot;
linearAxis02.Position = OxyPlot.Axes.AxisPosition.Bottom;
linearAxis02.Key = "Key";
linearAxis02.MaximumPadding = 10;
linearAxis02.MinimumPadding = 1;
SimplePlotModel.Axes.Add(linearAxis01);//坐标x轴
SimplePlotModel.Axes.Add(linearAxis02);//坐标y轴
//————————Axes-end———————— //
//ps:后面的就不要copy,没有按常理出牌的
//————————Series-begin————————//
//————————Series-end————————//
//————————Annotation-begin————————//
*ArrowAnnotation
*EllipseAnnotation
*FunctionAnnotation
*ImageAnnotation
*LineAnnotation
*PointAnnotation
*PolygonAnnotation
*PolyLineAnnotation
*RectangleAnnotation
*TextAnnotation
//标注线,上限和下限两根红色标线如下
var 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 = 88;
lineAnnotation_Max.Y = 40;
lineAnnotation_Max.Text = "上限:40";
SimplePlotModel.Annotations.Add(lineAnnotation_Max);
var lineAnnotation_Min = new OxyPlot.Annotations.LineAnnotation();
lineAnnotation_Min.Type = OxyPlot.Annotations.LineAnnotationType.Horizontal;
lineAnnotation_Min.MaximumX = 88;
lineAnnotation_Min.Y = 10;
lineAnnotation_Min.Text = "下限:10";
lineAnnotation_Min.Color = OxyPlot.OxyColors.Red;
lineAnnotation_Min.LineStyle = OxyPlot.LineStyle.Solid;
SimplePlotModel.Annotations.Add(lineAnnotation_Min);
//————————Annotation-end————————//
SimplePlotModel.Series.Add(lineSerial);
return SimplePlotModel;
}
********************本文属本人原创,喜欢转载记得标明出处**************************