最近使用C#开发图表,比较了DirectorChart,DontNetCharting,TeeChart,最终选用微软的mschart开发,对于X轴作为时间轴探索了好久,终于实现了想要的效果。

界面效果:

核心源码

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using ComponentFactory.Krypton.Toolkit;
using System.Windows.Forms.DataVisualization.Charting; namespace Krypton440Test
{
public partial class Form4 : ComponentFactory.Krypton.Toolkit.KryptonForm
{
public Form4()
{
InitializeComponent();
} private void Form4_Load(object sender, EventArgs e)
{
//清空原来数据缓存
chart1.Series[0].Points.Clear(); //定义图表大小尺寸
chart1.Width = Width - 100;
chart1.Height = Height - 100; //定义X轴、Y轴数据
double[] Ydata = { 20, 3, 23 ,6};
DateTime[] Xdate = new DateTime[] { DateTime.Parse("09:10:02"), DateTime.Parse("09:10:10"),DateTime.Parse("09:10:15"), DateTime.Parse("09:10:20") }; //以下按照先绘制chartArea、然后再绘制Series的步骤画图
//chartArea背景颜色
chart1.BackColor = Color.Azure; //X轴设置
chart1.ChartAreas[0].AxisX.Title = "时间";
chart1.ChartAreas[0].AxisX.TitleAlignment = StringAlignment.Near;
chart1.ChartAreas[0].AxisX.MajorGrid.Enabled = false;//不显示竖着的分割线 /************************************************************************/
/* 本文重点讲解时间格式的设置
* 如果想显示原点第一个时间坐标,需要设置最小时间,时间间隔类型,时间间隔值等三个参数*/
/************************************************************************/
chart1.ChartAreas[0].AxisX.LabelStyle.Format = "HH:mm:ss"; //X轴显示的时间格式,HH为大写时是24小时制,hh小写时是12小时制
chart1.ChartAreas[0].AxisX.Minimum = DateTime.Parse("09:10:02").ToOADate();
chart1.ChartAreas[0].AxisX.Maximum = DateTime.Parse("09:10:21").ToOADate();
chart1.ChartAreas[0].AxisX.IntervalType = DateTimeIntervalType.Seconds;//如果是时间类型的数据,间隔方式可以是秒、分、时
chart1.ChartAreas[0].AxisX.Interval = DateTime.Parse("00:00:02").Second;//间隔为2秒 //Y轴设置
chart1.ChartAreas[0].AxisY.Title = "数据点";
chart1.ChartAreas[0].AxisY.TitleAlignment = StringAlignment.Center;
chart1.ChartAreas[0].AxisY.MajorGrid.Enabled = true;//显示横着的分割线
chart1.ChartAreas[0].AxisY.Minimum = 0;
chart1.ChartAreas[0].AxisY.Maximum = 25;
chart1.ChartAreas[0].AxisY.Interval = 5; //Series绘制
chart1.Series[0].LegendText = "温度点";
chart1.Series[0].ChartType = SeriesChartType.Spline;
chart1.Series[0].XValueType = ChartValueType.DateTime;
chart1.Series[0].IsValueShownAsLabel = true;//显示数据点的值
chart1.Series[0].MarkerStyle = MarkerStyle.Circle; //把数据点添加到Series图表中
for (int i = 0; i < Xdate.Length; i++)
{
chart1.Series[0].Points.AddXY(Xdate[i], Ydata[i]);
}
}
}
}

  

Mschart绘制图表之X轴为时间的设置方式的更多相关文章

  1. 网页绘制图表 Google Charts with JavaScript #1....好强、好简单啊!

    此为文章备份,原文出处(我的网站) 网页绘制图表 Google Charts with JavaScript....好强.好简单啊!#1 http://www.dotblogs.com.tw/mis2 ...

  2. QCustomplot使用分享(九) 绘制图表-多功能游标

    目录 一.概述 二.效果图 三.源码讲解 1.源码结构 2.头文件 3.添加游标 4.监测移动 5.移动游标 6.其他函数 四.测试方式 1.测试工程 2.测试文件 3.测试代码 五.相关文章 六.总 ...

  3. Python 绘制图表之我见 ---一个java程序员的看法

    ---------------- 环境: win 10  . python3.5 https://github.com/Leechen2014/1400OS_01_Codes/blob/master/ ...

  4. 使用D3绘制图表(4)--面积图表

    面积图表的绘制就是在曲线图表的基础上做一点小小的改动.其他的代码跟绘制曲线图表没有什么区别,下面有黄色背景颜色的代码就是修改的,是不是很简单,第一句修改的地方就是把之前绘制线的函数(line)改成了绘 ...

  5. 在Android上用AChartEngine轻松绘制图表

    本文由 伯乐在线 - LeonHover 翻译.未经许可,禁止转载!英文出处:jaxenter.欢迎加入翻译组. Android发布不久的2008年底,开发者们已经开始寻找制表.制图.绘图的工具库.当 ...

  6. DevExpress使用之ChartControl控件绘制图表(多坐标折线图、柱状图、饼状图)

    最近因为公司项目需要用到WinForm的DecExpress控件,在这里把一些使用方法总结一下. DevExpress中有一个专门用来绘制图表的插件ChartControl,可以绘制折线图.饼状图.柱 ...

  7. ZedGrap控件绘制图表曲线

    问题描述: 使用C#中ZedGrap控件绘制图表曲线图 ZedGrap 介绍说明:     安装ZedGrap控件 ZedGraph控件dll文件: 添加ZedGraph控件,首先在新建立的C#图像工 ...

  8. BotVS开发基础—2.5 绘制图表

    代码 import time import math def main(): chart = { # 用于初始化 图表的对象 'title': {'text': "line数值触发 plot ...

  9. Highcharts使用CSV格式数据绘制图表

    Highcharts使用CSV格式数据绘制图表 CSV(Comma-Separated Values,逗号分隔值文本格式)是採用逗号切割的纯文本数据.通常情况下.每一个数据之间使用逗号切割,几个相关数 ...

随机推荐

  1. Asp.net异步IHttpAsyncHandler示例

    /// <summary> /// 异步IHttpHandler,实现了一个简单的统计流量的功能, /// 由于是示例代码,所以没有判断IP或者MAC /// </summary&g ...

  2. 【floyd存字典序路径】【HDU1385】【Minimum Transport Cost】

    题目大意 求多组i到j的最短路径 并输出字典序最小.... 现在只会floyd的方式 利用dis[i][j] 表示i到j的路径中i 后面的节点 更新是比较dis[i][j] dis[i][k]. 记住 ...

  3. odbc连接数据库

    using System; using System.Collections.Generic; using System.Text; using Console = System.Console; u ...

  4. 初始Knockout

    Kncokout是一个轻量级的ui类库,通过应用MVVN模式得JavaScript前端简单化. MVVN模式:http://www.cnblogs.com/xueduanyang/p/3601471. ...

  5. asp.net页面压缩

    http压缩方法(IIS 6.0 与IIS 7.0的详解)   在网上看了有关这方面的博客,再加上自己的实践,整理了一下,希望对大家有所帮助 本片文章采用两种压缩方法:一种是在IIS上开启GZIP压缩 ...

  6. jQuery基础---Ajax基础教程(二)

    jQuery基础---Ajax进阶 内容提纲: 1.加载请求 2.错误处理 3.请求全局事件 4.JSON 和 JSONP 5.jqXHR 对象 发文不易,转载请注明出处! 在 Ajax 基础一篇中, ...

  7. Oracle运维 专业的事情交给专业的人来做

    关于Oracle运维的重要性,随便写了几句,放在这儿和大家共勉. Oracle数据库在RDBMS中独占熬头,07年统计其市场份额占关系数据库市场的48.6%稳居首位,而且逐年增加,上升势头强劲.在使用 ...

  8. 如何让tableView展示数据

    设置数据源对象 self.tableView.dataSource = self; 数据源对象要遵守协议 @interface ViewController () <UITableViewDat ...

  9. n条直线的最多交点

    #include <iostream>using namespace std;int main(){int i,n;while(cin>>n){if(n==0||n==1) c ...

  10. php 注释

    @access 使用范围:class,function,var,define,module 该标记用于指明关键字的存取权限:private.public或proteced @author 指明作者 @ ...