WPF——OXY绘图
private PlotModel _plotModel;
public PlotModel plotModel
{
get { return _plotModel; }
set
{
_plotModel = value;
RaisePropertyChanged("plotModel");
}
} public void LoadChart()
{
BeginDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fff"); Stopwatch sw = new Stopwatch();
sw.Start(); var resData = JsonConvert.DeserializeObject<List<ResultModel>>(WcfConnector.GetInstance().QuerySroodRawData(QueryEqpId, RouteSelected.RunId, SvidSelected.ParaName)); var orderList = resData.OrderByDescending(m => m.val);
var maxPoint = orderList.FirstOrDefault();
var minPoint = orderList.LastOrDefault();
var mean = 107.5; plotModel = new PlotModel()
{
Title = "数据统计",
LegendTitle = "Max:红色,Min:黄色",
LegendOrientation = LegendOrientation.Horizontal,
LegendPlacement = LegendPlacement.Inside,
LegendPosition = LegendPosition.TopRight,
LegendBackground = OxyColor.FromAColor(, OxyColors.Beige),
LegendBorder = OxyColors.Black,
DefaultFont = "微软雅黑",
}; #region X,Y轴 //X轴
var _dateAxis = new DateTimeAxis()
{
MajorGridlineStyle = LineStyle.Solid,
MinorGridlineStyle = LineStyle.Dot,
IntervalLength = ,
IsZoomEnabled = false,
IsPanEnabled = false,
StringFormat = "M/d HH:mm:ss",
Title = "时间"
};
plotModel.Axes.Add(_dateAxis); //var startDate = DateTime.Now.AddDays(-10);
//var endDate = DateTime.Now;
//var minValue = DateTimeAxis.ToDouble(startDate);
//var maxValue = DateTimeAxis.ToDouble(endDate); //Y轴
var _valueAxis = new LinearAxis()
{
Title = "数值",
Maximum = maxPoint.val + maxPoint.val / ,
Minimum = minPoint.val - minPoint.val / ,
MajorGridlineStyle = LineStyle.Solid,//主刻度设置格网
MinorGridlineStyle = LineStyle.Dot,//子刻度设置格网样式
IntervalLength = ,
Angle = ,
IsZoomEnabled = true,//坐标轴缩放
IsPanEnabled = true,//图表缩放功能
Position = AxisPosition.Left,
};
plotModel.Axes.Add(_valueAxis); #endregion #region 线条 //动态线条
var lineSerial = new LineSeries()
{
Title = SvidSelected.ParaName,//eqpParam name
Color = OxyColors.Black,
Smooth = true,
MarkerType = MarkerType.Circle,
StrokeThickness = ,
MarkerSize = ,
MarkerStroke = OxyColors.BlueViolet,
};
plotModel.Series.Add(lineSerial); Task.Factory.StartNew(() =>
{
for (int i = ; i < resData.Count; i++)
{
lineSerial.Points.Add(DateTimeAxis.CreateDataPoint(resData[i].occurenceTime, resData[i].val));
plotModel.InvalidatePlot(true); //每秒刷新一次视图
Thread.Sleep();
}
}); //plotModel.InvalidatePlot(false); #endregion #region 上下限 //添加标注线
var lineMaxAnnotation = new LineAnnotation()
{//上限
Type = LineAnnotationType.Horizontal,
Y = maxPoint.val,
Text = "上限:" + maxPoint.val,
Color = OxyColors.Red,
LineStyle = LineStyle.DashDashDot,
StrokeThickness =
};
plotModel.Annotations.Add(lineMaxAnnotation); var lineMinAnnotation = new LineAnnotation()
{//下限
Type = LineAnnotationType.Horizontal,
Color = OxyColors.Blue,
LineStyle = LineStyle.Dash,
StrokeThickness = ,
Y = minPoint.val,
Text = "下限:" + minPoint.val
};
plotModel.Annotations.Add(lineMinAnnotation); var lineMean = new LineAnnotation()
{//平均
Type = LineAnnotationType.Horizontal,
Color = OxyColors.Green,
LineStyle = LineStyle.LongDash,
StrokeThickness = ,
Y = mean,
Text = "平均:" + mean
};
plotModel.Annotations.Add(lineMean); #endregion #region 最大值,最小值 var min = new ScatterSeries();
var MaxDataPoint = DateTimeAxis.CreateDataPoint(maxPoint.occurenceTime, maxPoint.val);
min.Points.Add(new ScatterPoint(MaxDataPoint.X, MaxDataPoint.Y, ));
min.MarkerFill = OxyColor.FromAColor(, OxyColors.Red);
min.MarkerType = MarkerType.Circle;
plotModel.Series.Add(min); var max = new ScatterSeries();
var minDataPoint = DateTimeAxis.CreateDataPoint(minPoint.occurenceTime, minPoint.val);
max.Points.Add(new ScatterPoint(minDataPoint.X, minDataPoint.Y, ));
max.MarkerFill = OxyColor.FromAColor(, OxyColors.Yellow);
max.MarkerType = MarkerType.Circle;
plotModel.Series.Add(max); #endregion #region 线条2 ////动态线条
//var lineSerial3 = new LineSeries()
//{
// Title = "CF3",
// Color = OxyColors.Blue,
// Smooth = true,
// MarkerType = MarkerType.Circle,
// StrokeThickness = 2,
// MarkerSize = 3,
// MarkerStroke = OxyColors.BlueViolet
//};
//plotModel.Series.Add(lineSerial3); //var count = 50; //var rd3 = new Random();
//Task.Factory.StartNew(() =>
//{
// var list = new List<DataPoint>(); // while (count > 0)
// {
// var point = DateTimeAxis.CreateDataPoint(DateTime.Now, rd3.Next(15, 60));
// list.Add(point);
// lineSerial3.Points.Add(point);
// //if (lineSerial3.Points.Count > 1000)
// //{
// // lineSerial3.Points.RemoveAt(0);
// //}
// plotModel.InvalidatePlot(true); //每秒刷新一次视图
// Thread.Sleep(500);
// count--;
// } // if (list.Count > 0)
// {
// var list1 = list.OrderByDescending(m => m.Y);
// var maxPoint = list1.FirstOrDefault();
// var minPoint = list1.LastOrDefault(); // var min = new ScatterSeries();
// min.Points.Add(new ScatterPoint(maxPoint.X, maxPoint.Y, 15));
// min.MarkerFill = OxyColor.FromAColor(120, OxyColors.Red);
// min.MarkerType = MarkerType.Circle;
// plotModel.Series.Add(min); // var max = new ScatterSeries();
// max.Points.Add(new ScatterPoint(minPoint.X, minPoint.Y, 15));
// max.MarkerFill = OxyColor.FromAColor(120, OxyColors.Yellow);
// max.MarkerType = MarkerType.Circle;
// plotModel.Series.Add(max); // }
//}); #endregion EndDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fff");
sw.Stop();
TotalDate = sw.ElapsedTicks / (decimal)Stopwatch.Frequency;
}
WPF——OXY绘图的更多相关文章
- WPF——OXY绘图_old
plotModel = new PlotModel() { Title = "数据统计", LegendTitle = "Max:红色,Min:黄色", Leg ...
- WPF 在绘图控件(Shape)中添加文字 [2018.7.15]
原文:WPF 在绘图控件(Shape)中添加文字 [2018.7.15] Q:使用Shape的子类Ellipse画一个圆,如何在圆中添加文字? A:Shape类中不包含Text属性.可使用Shape类 ...
- WPF特效-绘图
原文:WPF特效-绘图 WPF玩起来还是挺炫酷的.我实现的效果:不同色块交叉,交叉部分颜色叠加显示.(叠加部分暂时用随机颜色代替).单独色块点击弹出以色块颜色为主的附 ...
- WPF 实时绘图的逻辑
实时绘图实际上是两个线程.外部线程直接用thread,只有到绘图那个逻辑才用绘图控件的mycanvas2.Dispatcher.Invoke. 或者说,INVOKE并不是开线程,只是一个绘图的委托而已 ...
- WPF中绘图(含调用GDI+)
private void DrawStuff() { // //if (buffer == null) //{ // buffer = new RenderTargetBitmap((int)Back ...
- WPF学习(11)2D绘图
本篇我们来学习WPF的绘图,在2D绘图中主要有这么几个重要的类:Drawing.Visual和Shape,顺便讲下Brush和BitmapEffect. 1 2D绘图 1.1Drawing类 Draw ...
- 《Programming WPF》翻译 第7章 1.图形基础
原文:<Programming WPF>翻译 第7章 1.图形基础 WPF使得在你的应用程序中使用图形很容易,以及更容易开发你的显卡的能力.这有很多图形构架的方面来达到这个目标.其中最重要 ...
- WPF绘制深度不同颜色的3D模型填充图和线框图
原文:WPF绘制深度不同颜色的3D模型填充图和线框图 在机械测量过程中,测量的数据需要进行软件处理.通常测量一个零件之后,需要重建零件的3D模型,便于观察测量结果是否与所测工件一致. 重建的3D模型需 ...
- WPF特效-绘制实时2D激光雷达图
原文:WPF特效-绘制实时2D激光雷达图 接前两篇: https://blog.csdn.net/u013224722/article/details/80738619 https://blog.cs ...
随机推荐
- Java 之 Collection 接口
一.Collection 集合 Collection:单列集合类的根接口,用于存储一系列符合某种规则的元素,它有两个重要的子接口,分别是 java.util.List 和 java.util.Set. ...
- consul:健康检查
官方文档:https://www.consul.io/docs/agent/checks.html consul提供的健康检查有以下几种: 1.script+interval 2.http+inter ...
- 使用SAP CRM中间件XIF(External Interface)一步步创建服务订单
tcode WE19, choose an existing IDOC in the system: Just change the existing IDOC Service Order ID to ...
- linux如何执行定时任务
前言:最近在做一个前端监控系统,用到分表分库的功能,由于代码上无法做到实时新建表,所以只能够曲线救国,使用linux系统的定时任务来完成. ============================== ...
- Oracle11g 干净卸载
原文链接:https://www.cnblogs.com/su-root/p/9689787.html 作 者:小柏 出 处:https://www.cnblogs.com/su-root Ora ...
- 浅析ORACLE ERP系统维护方法
笔者曾从事ORACLE ERP系统客户服务工作多年,在ERP系统维护工作中,深深体会到:ERP的系统维护工作看似平常,实则大有学问. ORACLE ERP系统是一个大型集成的软件系统,是一个企业全面共 ...
- LP线性规划初识
认识LP 线性规划(Linear Programming) 特指目标函数和约束条件皆为线性的最优化问题. 目标函数: 多个变量形成的函数 约束条件: 由多个等式/不等式形成的约束条件 线性规划: 在线 ...
- java实现快速排序,归并排序
//1.快速排序 import java.util.*; public class Main { public static void main(String[] args) { Scanner sc ...
- rds - mysql修改存储过程/函数的方式
rds 不支持账户A 给账户B 创建授权存储过程,只能是当前登录账户给自己创建,要登陆对应账户删除原有存储过程重新创建即为修改. 例子如下: 先登陆新账号然后执行如下sql语句即可: DROP PRO ...
- docker配置镜像加速器
docker配置镜像加速器 针对Docker客户端版本大于 1.10.0 的用户 您可以通过修改daemon配置文件/etc/docker/daemon.json来使用加速器 sudo mkdir - ...