.NET chart 毫秒级坐标轴
来源:互联网 发布:婚礼沙画软件 编辑:程序博客网 时间:2024/05/29 09:15
微软的chart控件,功能强大,也非常方便好用。
这里说一下,如何用时间做X轴,坐标时间间隔可以精确到ms。
直接上代码(在VS2013 上通过):
在form1中拖入chart控件,name为chart1
拖入一个timer控件,name为timer1; 两个button;
界面如下图:
上图横坐标是取系统时间的 分:秒.毫秒
代码如下:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Forms.DataVisualization.Charting; //与chart相关的引用
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Forms.DataVisualization.Charting; //与chart相关的引用
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
private DateTime minValue, maxValue; //横坐标最小和最大值
private Random rand = new Random();
public Form1()
{
InitializeComponent();
}
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
minValue = DateTime.Now; //x轴最小刻度
maxValue = minValue.AddSeconds(1); //X轴最大刻度,比最小刻度大1秒
chart1.ChartAreas[0].AxisX.LabelStyle.Format = "mm:ss.fff"; //毫秒格式: hh:mm:ss.fff ,后面几个f则保留几位毫秒小数,此时要注意轴的最大值和最小值不要差太大
chart1.ChartAreas[0].AxisX.LabelStyle.IntervalType = DateTimeIntervalType.Milliseconds;
chart1.ChartAreas[0].AxisX.LabelStyle.Interval = 200; //坐标值间隔200 ms
chart1.ChartAreas[0].AxisX.LabelStyle.IsEndLabelVisible = false; //防止X轴坐标跳跃
chart1.ChartAreas[0].AxisX.MajorGrid.IntervalType = DateTimeIntervalType.Milliseconds;
chart1.ChartAreas[0].AxisX.MajorGrid.Interval = 200;
{
minValue = DateTime.Now; //x轴最小刻度
maxValue = minValue.AddSeconds(1); //X轴最大刻度,比最小刻度大1秒
chart1.ChartAreas[0].AxisX.LabelStyle.Format = "mm:ss.fff"; //毫秒格式: hh:mm:ss.fff ,后面几个f则保留几位毫秒小数,此时要注意轴的最大值和最小值不要差太大
chart1.ChartAreas[0].AxisX.LabelStyle.IntervalType = DateTimeIntervalType.Milliseconds;
chart1.ChartAreas[0].AxisX.LabelStyle.Interval = 200; //坐标值间隔200 ms
chart1.ChartAreas[0].AxisX.LabelStyle.IsEndLabelVisible = false; //防止X轴坐标跳跃
chart1.ChartAreas[0].AxisX.MajorGrid.IntervalType = DateTimeIntervalType.Milliseconds;
chart1.ChartAreas[0].AxisX.MajorGrid.Interval = 200;
chart1.ChartAreas[0].AxisX.Minimum = minValue.ToOADate();
chart1.ChartAreas[0].AxisX.Maximum = maxValue.ToOADate();
chart1.Series.Clear();
chart1.ChartAreas[0].AxisX.Maximum = maxValue.ToOADate();
chart1.Series.Clear();
Series newSeries = new Series("Series1");
newSeries.ChartType = SeriesChartType.Line;
newSeries.BorderWidth = 1;
newSeries.Color = Color.FromArgb(0, 0, 255);
newSeries.XValueType = ChartValueType.DateTime;
chart1.Series.Add(newSeries);
timer1.Interval = 200;
}
newSeries.ChartType = SeriesChartType.Line;
newSeries.BorderWidth = 1;
newSeries.Color = Color.FromArgb(0, 0, 255);
newSeries.XValueType = ChartValueType.DateTime;
chart1.Series.Add(newSeries);
timer1.Interval = 200;
}
public void AddNewPoint(DateTime timeStamp, System.Windows.Forms.DataVisualization.Charting.Series ptSeries)
{
// Add new data point to its series.
ptSeries.Points.AddXY(timeStamp.ToOADate(), rand.Next(5, 20));
{
// Add new data point to its series.
ptSeries.Points.AddXY(timeStamp.ToOADate(), rand.Next(5, 20));
// remove all points from the source series older than 1 seconds.
double removeBefore = timeStamp.AddSeconds((double)(1) * (-1)).ToOADate();
double removeBefore = timeStamp.AddSeconds((double)(1) * (-1)).ToOADate();
//remove oldest values to maintain a constant number of data points
while (ptSeries.Points[0].XValue < removeBefore)
{
ptSeries.Points.RemoveAt(0);
}
while (ptSeries.Points[0].XValue < removeBefore)
{
ptSeries.Points.RemoveAt(0);
}
chart1.ChartAreas[0].AxisX.Minimum = ptSeries.Points[0].XValue;
chart1.ChartAreas[0].AxisX.Maximum = DateTime.FromOADate(ptSeries.Points[0].XValue).AddSeconds(1).ToOADate();
chart1.ChartAreas[0].AxisX.Maximum = DateTime.FromOADate(ptSeries.Points[0].XValue).AddSeconds(1).ToOADate();
chart1.Invalidate();
}
}
//添加时间数据和对应列的值
public void AddData()
{
DateTime timeStamp = DateTime.Now;
AddNewPoint(timeStamp, chart1.Series[0]);
}
private void timer1_Tick(object sender, EventArgs e)
{
AddData();
}
{
AddData();
}
private void button1_Click(object sender, EventArgs e)
{
timer1.Enabled = true;
}
{
timer1.Enabled = true;
}
private void button2_Click(object sender, EventArgs e)
{
timer1.Enabled = false;
}
{
timer1.Enabled = false;
}
}
}
}
以上代码下载地址:http://download.csdn.net/detail/flyingqd/9623405
0 0
- .NET chart 毫秒级坐标轴
- VTK Chart坐标轴
- 改变chart坐标轴的起始值
- SWt chart 坐标轴绘制函数入口
- Extjs学习 图表Chart 坐标轴组件详解(axes)
- extjs4 chart 坐标轴都为Numberic时,坐标不正确问题
- C# 画图控件CHART 自定义坐标轴刻度标签
- 发布Chart .Net 组件
- Dundas Chart for .NET
- Dundas Chart for .NET
- .NET Chart ChartRenderType 属性
- .NET chart控件使用方法
- Ext.net chart应用
- VB.NET获取系统当前精确时间(毫秒级)
- VB.NET获取系统当前精确时间(毫秒级)
- 坐标轴
- 坐标轴
- asp.net 2.0 Chart画图
- 移动端适配之雪碧图(sprite)背景图片定位
- C++类与对象
- 【3】数据结构与算法-3 冒泡排序算法
- C# 判断图形文件(GIF,JPG,PNG)的图片格式的方法
- [51nod 1421]最大MOD值
- .NET chart 毫秒级坐标轴
- 初始化vector
- ubuntu下使用irtulbox虚拟winxp实现360wifi热点功能
- Redis常用命令
- iOS 视屏播放软件(AVPlayer)
- MapReduce实现QQ好友推荐
- 获取 点集合 的 rect
- jms中间件整合spring
- 数据库连接driverClass和jdbcUrl大全