【实例简介】

ZedGraph显示多条实时曲线并可控制显示哪一条

【实例截图】

【核心代码】

namespace 显示实时曲线

{

public partial class Form1 : Form

{

public Form1()

{

InitializeComponent();

}

int tickStart = 0;

private PointPairList list1 = new PointPairList();

private PointPairList list2 = new PointPairList();

double y = 0;

LineItem curve1;

LineItem curve2;

private void Form1_Load(object sender, EventArgs e)

{

//获取引用

GraphPane myPane = zedGraphControl1.GraphPane;

curve1 = myPane.AddCurve("曲线1", list1, Color.Blue, SymbolType.None);

curve2 = myPane.AddCurve("曲线2", list2, Color.Green, SymbolType.None);

//设置标题

myPane.Title.Text = "实时曲线";

//设置X轴说明文字

myPane.XAxis.Title.Text = "时间";

//设置Y轴说明文字

myPane.YAxis.Title.Text = "温度";

myPane.Chart.Fill = new Fill(Color.White, Color.LightGray, 45.0f);

//myPane.Chart.Fill = new Fill(Color.White, Color.LightGray, 45.0f);

//设置1200个点,假设每50毫秒更新一次,刚好检测1分钟,一旦构造后将不能更改这个值

//RollingPointPairList list1 = new RollingPointPairList(2400);

//RollingPointPairList list2 = new RollingPointPairList(2400);

//开始,增加的线是没有数据点的(也就是list为空)

//增加一条名称:Voltage,颜色Color.Bule,无符号,无数据的空线条

timer1.Interval = 1000;//设置timer控件的间隔为50毫秒

timer1.Enabled = true;//timer可用

timer1.Start();//开始

myPane.Y2Axis.IsVisible = true;

myPane.Y2Axis.Scale.Align = AlignP.Inside;

myPane.Y2Axis.MajorTic.IsOpposite = false;

myPane.Y2Axis.MinorTic.IsOpposite = false;

myPane.XAxis.Scale.Format = "dd  HH:mm:ss";   //DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")

myPane.XAxis.Type = ZedGraph.AxisType.DateAsOrdinal;

myPane.XAxis.Scale.Min = 0;//X轴最小值0

myPane.XAxis.Scale.Max = 5;//X轴最大30

//myPane.XAxis.Scale.MinorStep = 0.02;//X轴小步长1,也就是小间隔

//myPane.XAxis.Scale.MajorStep = 0.1;//X轴大步长为5,也就是显示文字的大间隔

myPane.XAxis.MajorGrid.IsVisible = true;//设置X虚线

myPane.YAxis.MajorGrid.IsVisible = true;//设置Y虚线

//改变轴的刻度

//zedGraphControl1.AxisChange();

// Show the x axis grid

//   myPane.XAxis.MajorGrid.IsVisible = true;

//    myPane.YAxis.MajorTic.IsOpposite = true;

//  myPane.YAxis.MinorTic.IsOpposite = true;

// Don't display the Y zero line

//保存开始时间

tickStart = Environment.TickCount;

zedGraphControl1.IsShowPointValues = true;

//zedGraphControl1.PointValueEvent = new ZedGraphControl.PointValueHandler(MyPointValueHandler);

// OPTIONAL: Add a custom context menu item

//   zedGraphControl1.ContextMenuBuilder = new ZedGraphControl.ContextMenuBuilderEventHandler(MyContextMenuBuilder);

// OPTIONAL: Handle the Zoom Event

//zedGraphControl1.ZoomEvent = new ZedGraphControl.ZoomEventHandler(MyZoomEvent);

//zedGraphControl1.AxisChange();

// Make sure the Graph gets redrawn

zedGraphControl1.Invalidate();

}

private int timerDrawI = 0;

private void timer1_Tick(object sender, EventArgs e)

{

//确保CurveList不为空

if (zedGraphControl1.GraphPane.CurveList.Count <= 0)

{

return;

}

//取Graph第一个曲线,也就是第一步:在GraphPane.CurveList集合中查找CurveItem

LineItem curve = zedGraphControl1.GraphPane.CurveList[0] as LineItem;

if (curve == null)

{

return;

}

//第二步:在CurveItem中访问PointPairList(或者其它的IPointList),根据自己的需要增加新数据或修改已存在的数据

IPointListEdit list = curve.Points as IPointListEdit;

// If this is null, it means the reference at curve.Points does not

// support IPointListEdit, so we won't be able to modify it

if (list == null)

{

return;

}

// Time is measured in seconds

/*for (int i = 0; i <= 100; i )

{

double x = (double)new XDate(DateTime.Now.AddSeconds(-(100 - i)));

list1.Add(x, (double)Math.Sin(timerDrawI / 10) * 12);

list2.Add(x, (double)Math.Sin(timerDrawI / 10f));

}*/

//double x = (double)new XDate(DateTime.Now.AddSeconds(100.00));

double x = (double)new XDate(DateTime.Now);

// 3 seconds per cycle

list1.Add(x, (double)Math.Sin(timerDrawI / 10) * 12);

list2.Add(x, (double)Math.Sin(timerDrawI / 10f));

y = (double)Math.Sin(timerDrawI / 10f);

//textBox1.Text = y.ToString();

textBox1.Text = list2.ToString();

// list.Add(time, Math.Sin(2.0 * Math.PI * time / 5.0));

timerDrawI ;

// Keep the X scale at a rolling 30 second interval, with one

// major step between the max X value and the end of the axis

Scale xScale = zedGraphControl1.GraphPane.XAxis.Scale;

/*if ( time > xScale.Max - xScale.MajorStep )

{

xScale.Max = time xScale.MajorStep;

xScale.Min = xScale.Max - 30.0;

}*/

//第三步:调用ZedGraphControl.AxisChange()方法更新X和Y轴的范围

zedGraphControl1.AxisChange();

//第四步:调用Form.Invalidate()方法更新图表

zedGraphControl1.Invalidate();

if (list.Count >= 100)

{

list1.RemoveAt(0);

list2.RemoveAt(0);

}

}

///

/// Display customized tooltips when the mouse hovers over a point

///

/*private string MyPointValueHandler(ZedGraphControl control, GraphPane pane,

CurveItem curve, int iPt)

{

// Get the PointPair that is under the mouse

PointPair pt = curve[iPt];

return curve.Label.Text " is " pt.Y.ToString("f2") " units at " pt.X.ToString("f1") " days";

}*/

///

/// Customize the context menu by adding a new item to the end of the menu

///

//private void MyContextMenuBuilder(ZedGraphControl control, ContextMenuStrip menuStrip,

//                Point mousePt)

//{

//    ToolStripMenuItem item = new ToolStripMenuItem();

//    item.Name = "add-beta";

//    item.Tag = "add-beta";

//    item.Text = "Add a new Beta Point";

//    item.Click = new System.EventHandler(AddBetaPoint);

//    menuStrip.Items.Add(item);

//}

///

/// Handle the "Add New Beta Point" context menu item.  This finds the curve with

/// the CurveItem.Label = "Beta", and adds a new point to it.

///

/* private void AddBetaPoint(object sender, EventArgs args)

{

// Get a reference to the "Beta" curve IPointListEdit

IPointListEdit ip = zedGraphControl1.GraphPane.CurveList["Beta"].Points as IPointListEdit;

if (ip != null)

{

double x = ip.Count * 5.0;

double y = Math.Sin(ip.Count * Math.PI / 15.0) * 16.0 * 13.5;

ip.Add(x, y);

zedGraphControl1.AxisChange();

zedGraphControl1.Refresh();

}

}*/

// Respond to a Zoom Event

/*private void MyZoomEvent(ZedGraphControl control, ZoomState oldState,

ZoomState newState)

{

// Here we get notification everytime the user zooms

}*/

private void Form1_Resize(object sender, EventArgs e)

{

//SetSize();

}

// Set the size and location of the ZedGraphControl

/*private void SetSize()

{

// Control is always 10 pixels inset from the client rectangle of the form

Rectangle formRect = this.ClientRectangle;

formRect.Inflate(-10, -10);

if (zedGraphControl1.Size != formRect.Size)

{

zedGraphControl1.Location = formRect.Location;

zedGraphControl1.Size = formRect.Size;

}

}*/

private void checkBox1_CheckedChanged(object sender, EventArgs e)

{

if (checkBox1.Checked == true)

{

curve2.IsVisible = true;

}

else

{

//否则文本框不可以用

curve2.IsVisible = false;

}

}

private void checkBox2_CheckedChanged(object sender, EventArgs e)

{

if (checkBox2.Checked == true)

{

curve1.IsVisible = true;

}

else

{

//否则文本框不可以用

curve1.IsVisible = false;

}

}

zedgraph显示最小刻度_ZedGraph显示多条实时曲线相关推荐

  1. zedgraph显示最小刻度_ZedGraph 控件各属性以及示例

    标签: Copy(Boolean) ->> 将图像复制到剪贴板. DoPageSetup()() ->> 打开打印设置对话框. DoPrint()() ->> 打印 ...

  2. Winform中设置ZedGraph的多条Y轴的标题和刻度不显示十次幂

    场景 Winform中设置ZedGraph的坐标轴的标题和刻度不显示十次幂: https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/106 ...

  3. Winform中设置ZedGraph的坐标轴的标题和刻度不显示十次幂

    场景 Winforn中设置ZedGraph曲线图的属性.坐标轴属性.刻度属性: https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/10 ...

  4. MATLAB完美画图:改变坐标轴刻度的显示数值,常数函数的作图

    直接上代码,自己看吧: 可直接复制,根据需求更改代码 clc,clear all x=[0,1];y=[1,1];plot(x,y,'blue')%常函数的分段是不一样的.横线 hold on;%表示 ...

  5. ajax加载进度百分比,在ajax中显示加载百分比的进度条,php

    您好我正在使用ajax加载数据库内容.我想显示加载或图像的总百分比.在ajax中显示加载百分比的进度条,php 这是我的脚本 function name1(str) { if (str.length= ...

  6. win7系统计算机无最小化,技术员解惑win7系统任务栏不显示最小化窗口的修复办法...

    许多win7系统用户在工作中经常会遇到win7系统任务栏不显示最小化窗口的情况,比如近日有用户到本站反映说win7系统任务栏不显示最小化窗口的问题,但是却不知道要怎么解决win7系统任务栏不显示最小化 ...

  7. ECharts图表坐标轴数据超出显示范围,以及坐标轴刻度标签显示不全解决方法

    1.在使用ECharts图表时,比较常见到坐标轴数据超出显示范围的情况,如下 解决办法:添加配置 2.坐标轴刻度标签显示不全 就简单描述一下,比如你的数据横坐标有15个,但是默认不会显示全部 解决方法 ...

  8. [前端] Chrome浏览器默认显示最小字号为12px

    Chrome浏览器默认显示最小字体为12px Chrome默认最小字号是12px(最新版英文也有此问题),这个是Chrome为了更好显示中文设计的. 但是这样一来就会出现,设置为8px字体的元素在Ch ...

  9. Python画图显示次刻度 set_minor_locator()

    显示次刻度 set_minor_locator() Python用plt画图时,有时不显示次刻度,解决办法: ax = plt.gca() yminorLocator = AutoMinorLocat ...

  10. 进度条实时显示request下载文件的解决方案

      大家好,我是herosunly.985院校硕士毕业,现担任算法研究员一职,热衷于机器学习算法研究与应用.曾获得阿里云天池比赛第一名,科大讯飞比赛第三名,CCF比赛第四名.拥有多项发明专利.对机器学 ...

最新文章

  1. 一星期没完成Ansible任务
  2. 马斯克SpaceX内部信曝光:戒骄戒躁,我们的首要任务是星际飞船
  3. PCL中有哪些可用的PointT类型(4)
  4. [spfa][差分约束] 洛谷 P3084 照片Photo
  5. 解析JavaScript中的字符串类型与字符编码支持
  6. 电子设计常用总线--QSPI
  7. 深度学习的实用层面 —— 1.3 机器学习基础
  8. 第12章 数据库完整性
  9. C++对象模型 笔记1
  10. day6--pandas
  11. RHCE课程-RH253Linux服务器架设笔记五-APACHE服务器配置(2)
  12. 在线html代码生成器,支持网页快速排版 CSS代码一键生成的在线设计工具
  13. R语言求和上三角矩阵
  14. html调用java函数_html通过JavaScript调用java代码
  15. 财会法规与职业道德【9】
  16. centos gedit 字体大小_【写作技巧】毕业论文格式要求及字体大小
  17. win10 android软件下载,windows10模拟器安卓版
  18. 教师计算机返岗实践方案,国培计划返岗实践方案
  19. 随机过程 更新过程(上)
  20. 如何设置Word文档公式序号在右边

热门文章

  1. Uiautomator 2.0之UiObject2类学习小记
  2. 测试版降级后软件还在么,2分钟告诉你如何将iOS测试版降级到正式版本
  3. 机器学习实战笔记1——机器学习导论
  4. 普元EOS之我要使用多数据源
  5. GIS - 百度地图 城市中心点坐标
  6. 百度热力图颜色说明_基于百度热力图的中国多中心城市分析|上海城市规划
  7. 微信小程序图片缓存问题
  8. 智慧城市大数据运营中心,发挥大数据价值
  9. grads插值_GrADS第6章变量和函数讲课.ppt
  10. steam密码文件在哪里_如何将您的Steam库无痛地移动到另一个文件夹或硬盘驱动器...