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绘图的更多相关文章

  1. WPF——OXY绘图_old

    plotModel = new PlotModel() { Title = "数据统计", LegendTitle = "Max:红色,Min:黄色", Leg ...

  2. WPF 在绘图控件(Shape)中添加文字 [2018.7.15]

    原文:WPF 在绘图控件(Shape)中添加文字 [2018.7.15] Q:使用Shape的子类Ellipse画一个圆,如何在圆中添加文字? A:Shape类中不包含Text属性.可使用Shape类 ...

  3. WPF特效-绘图

    原文:WPF特效-绘图                  WPF玩起来还是挺炫酷的.我实现的效果:不同色块交叉,交叉部分颜色叠加显示.(叠加部分暂时用随机颜色代替).单独色块点击弹出以色块颜色为主的附 ...

  4. WPF 实时绘图的逻辑

    实时绘图实际上是两个线程.外部线程直接用thread,只有到绘图那个逻辑才用绘图控件的mycanvas2.Dispatcher.Invoke. 或者说,INVOKE并不是开线程,只是一个绘图的委托而已 ...

  5. WPF中绘图(含调用GDI+)

    private void DrawStuff() { // //if (buffer == null) //{ // buffer = new RenderTargetBitmap((int)Back ...

  6. WPF学习(11)2D绘图

    本篇我们来学习WPF的绘图,在2D绘图中主要有这么几个重要的类:Drawing.Visual和Shape,顺便讲下Brush和BitmapEffect. 1 2D绘图 1.1Drawing类 Draw ...

  7. 《Programming WPF》翻译 第7章 1.图形基础

    原文:<Programming WPF>翻译 第7章 1.图形基础 WPF使得在你的应用程序中使用图形很容易,以及更容易开发你的显卡的能力.这有很多图形构架的方面来达到这个目标.其中最重要 ...

  8. WPF绘制深度不同颜色的3D模型填充图和线框图

    原文:WPF绘制深度不同颜色的3D模型填充图和线框图 在机械测量过程中,测量的数据需要进行软件处理.通常测量一个零件之后,需要重建零件的3D模型,便于观察测量结果是否与所测工件一致. 重建的3D模型需 ...

  9. WPF特效-绘制实时2D激光雷达图

    原文:WPF特效-绘制实时2D激光雷达图 接前两篇: https://blog.csdn.net/u013224722/article/details/80738619 https://blog.cs ...

随机推荐

  1. dubbo循序渐进 - nacos安装

    1.安装docker ce yum install -y yum-utils device-mapper-persistent-data lvm2 yum-config-manager --add-r ...

  2. 【转载】C#的DataTable使用NewRow方法创建新表格行

    在C#的DataTable数据表格操作过程中,DataRow类表示DataTable中的数据行信息,但DataRow没有可以直接实例化的构造方法,在创建DataTable的新行的时候,不可直接使用Da ...

  3. APS系统的现状以及与MES系统的关联

    MES是智能工厂的核心,将前端产品设计.工艺定义阶段的产品数据管理与后端制造阶段的生产数据管理融合,实现产品设计.生产过程.维修服务闭环协同全生命周期管理. APS就是高级计划排程 应该说APS本来是 ...

  4. MySQL登录时出现 Access denied for user 'root'@'xxx.xxx.xxx.xxx' (using password: YES) 的原因及解决办法

    场景一:调试web程序访问数据库的时候出现 场景二:MySQL登陆的时候,区分本地localhost登陆,以及远程登陆.即使本地能够登陆,如果不授权也无法远程登陆 分析原因:(区分)当本地出现这样的情 ...

  5. win2003下安装python3.4 + pyspider

    昨天尝试了在win2003下安装python2.7.这个是文章地址:https://www.cnblogs.com/alpiny/p/11706606.html 但是程序跑了一晚上,发现有一点问题,是 ...

  6. go中如何更好的迭代

    三种迭代方式 3 ways to iterate in Go 有如下三种迭代的写法: 回调函数方式迭代 通过Next()方法迭代.参照python 迭代器的概念,自定义Next()方法来迭代 通过ch ...

  7. Linux下关于Qt无法调用fcitx的中文输入

    1 本机环境: deepin 15.11 Qt 5.11.3 fcitx 输入法 2 问题描述 Qt Creator 和使用 QT 编译的程序运行时均不能使用deepin系统自带的fcitx输入法,且 ...

  8. 【PyTorch v1.1.0文档研习】60分钟快速上手

    阅读文档:使用 PyTorch 进行深度学习:60分钟快速入门. 本教程的目标是: 总体上理解 PyTorch 的张量库和神经网络 训练一个小的神经网络来进行图像分类 PyTorch 是个啥? 这是基 ...

  9. Chrome出现“浏览器由所属组织管理”如何解决

    之前碰到了这个问题,删除注册表解决了.当时没记下来,今天又碰到了.那就写下来以备之后再碰到吧 删除了注册表\HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Google\Ch ...

  10. com.mysql.jdbc.MysqlDataTruncation: Data truncation异常

    Exception in thread "main" com.mysql.jdbc.MysqlDataTruncation: Data truncation: Data too l ...