ZEDGRAPH画图心得
OleDbConnection odcConnection = new OleDbConnection(MyConnectionString); //打开连接 C#操作Access之按列读取mdb
odcConnection.Open();
OleDbCommand odCommandValue = odcConnection.CreateCommand();//value
OleDbCommand odCommandYear = odcConnection.CreateCommand();//year odCommandValue.CommandText = "select 全年平均 from 洱海各月出流流量"; //读取全年平均项,建立读取 C#操作Access之按列读取mdb
odCommandYear.CommandText = "select 年 from 洱海各月出流流量"; //读取year OleDbDataReader odrReaderValue = odCommandValue.ExecuteReader();//建立SQL查询value
OleDbDataReader odrReaderYear = odCommandYear.ExecuteReader();//建立SQL查询year //ArrayList ArrValue = new ArrayList();//定义动态数组ArrValue
//ArrayList ArrYear = new ArrayList();//定义动态数组ArrYear //double []Yearavrg;//数组定义
//Yearavrg = new double[100];//初始化大小,分配内存
//double []Year;//数组定义
//Year = new double[100]; double[] ArrValue;//数组定义
ArrValue = new double[];//初始化大小,分配内存
double[] ArrYear;//数组定义
ArrYear = new double[];
int im = , jm = ;
while (odrReaderValue.Read())
{
//ArrValue.Add(odrReaderValue["全年平均"].ToString());//读取列的每一个
ArrValue[im] = Convert.ToDouble(odrReaderValue["全年平均"]);
im++;
}
while (odrReaderYear.Read())
{
//ArrYear.Add(odrReaderYear["年"].ToString());//读取列的每一个
ArrYear[jm] = Convert.ToDouble(odrReaderYear["年"]);
jm++;
} odrReaderValue.Close();
odrReaderYear.Close();
odcConnection.Close();
//test
//int leng = ArrValue.Count;//计算数组长度
int leng = ArrValue.Length; // MessageBox.Show(leng.ToString());//test
GraphPane MyPane=zedGraphControl1.GraphPane;
MyPane.Title.Text = "洱海年平均出流流量";
MyPane.XAxis.Title.Text = "年份";
MyPane.YAxis.Title.Text = "流量(立方米每秒)"; //
PointPairList pplist = new PointPairList();//显示点数组
//test-OK
foreach (double a in ArrValue)
{ textBox1.Text += a;
//pplist.Add(0,b); } //test-OK
//foreach (string a in ArrYear)
//foreach (string a in ArrValue)
//{
// //MessageBox.Show(a);
// double b = double.Parse(a);//类型转换
// textBox1.Text += b;//test
//} //foreach (string a in ArrValue)
//{
// //MessageBox.Show(a);
// int i = 0;
// Yearavrg[i] = double.Parse(a);//类型转换
// i++; //} //foreach (string b in ArrYear)
//{
// //MessageBox.Show(a);
// int i = 0;
// Year[i] = double.Parse(b);//类型转换
// i++;
// textBox1.Text+=Year[i].ToString(); //} for (int i = ; i < leng; i++)
{ pplist.Add(ArrYear[i], ArrValue[i]);//xaile是年,yaile是年平均流量值
} LineItem myCurve = MyPane.AddCurve("流量",pplist,Color.Red,SymbolType.Diamond);//标注样式 myCurve.Symbol.Fill = new Fill(Color.White);//背景填充白色
MyPane.XAxis.MajorGrid.IsVisible = true;//显示X网格
MyPane.YAxis.MajorGrid.IsZeroLine = true;//Y坐标不显示0坐标线 // Align the Y axis labels so they are flush to the axis
MyPane.YAxis.Scale.Align = AlignP.Inside; //坐标范围划定
MyPane.YAxis.Scale.Min = -;
MyPane.YAxis.Scale.Max = ; MyPane.XAxis.Scale.Min = ;
MyPane.XAxis.Scale.Max = ; MyPane.Chart.Fill = new Fill(Color.White, Color.LightGray, 45.0f); // Add a text box with instructions
TextObj text = new TextObj(
"左键拖拽放大\n鼠标中键滚放缩\n右键菜单",
0.05f, 0.95f, CoordType.ChartFraction, AlignH.Left, AlignV.Bottom);
text.FontSpec.StringAlignment = StringAlignment.Near;
MyPane.GraphObjList.Add(text); zedGraphControl1.IsShowHScrollBar = true;
zedGraphControl1.IsShowVScrollBar = true;
zedGraphControl1.IsAutoScrollRange = true; 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); // Tell ZedGraph to calculate the axis ranges
// Note that you MUST call this after enabling IsAutoScrollRange, since AxisChange() sets
// up the proper scrolling parameters
zedGraphControl1.AxisChange();
// Make sure the Graph gets redrawn
zedGraphControl1.Invalidate();
}
/// <summary>
/// Display customized tooltips when the mouse hovers over a point
/// </summary>
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") + " m3/s at " + pt.X.ToString("f1") + " 年";
//return pt.X.ToString("f1") + "年"+curve.Label.Text + "是" + pt.Y.ToString("f2") + " wm3/s";
return pt.X.ToString() + "年" + curve.Label.Text + "是" + pt.Y.ToString("f2") + " wm3/s";//OKZWJ
} /// <summary>
/// Customize the context menu by adding a new item to the end of the menu
/// </summary>
private void MyContextMenuBuilder(ZedGraphControl control, ContextMenuStrip menuStrip,
Point mousePt, ZedGraphControl.ContextMenuObjectState objState)
{
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);
} /// <summary>
/// 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.
/// </summary>
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
} }
调试蛮辛苦的,尝试了很多次,各种改变,最后终于可以了!!!
ZEDGRAPH画图心得的更多相关文章
- ZEDGRAPH画图心得,SQL语句构造!!!
/// <summary> /// 画折线 /// </summary> public void Drawline() { OleDbConnection odcConnect ...
- C#:ZedGraph画图控件(待补充)
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- zedgraph中禁用鼠标滚轮变焦(禁止画图区域随鼠标滚动改变XY轴,定位)(转)
禁用鼠标滚轮变焦的zedgraph功能 如果zgc是你ZedGraphControl实例,请使用: zgc.ZoomButtons = MouseButtons.None; zgc.ZoomButto ...
- windows类书的学习心得(转载)
原文网址:http://www.blogjava.net/sound/archive/2008/08/21/40499.html 现在的计算机图书发展的可真快,很久没去书店,昨日去了一下,真是感叹万千 ...
- zedGraph
“zedGraph”控件画图的时候遇到了一点小问题,就是在同一个控件实例上第一次绘制饼图的时候一切正常,但是再次绘制的时候不是重新绘制新的饼图,而是在原有基础之上又添加进新的对象(PieItem),又 ...
- GridView+ZedGraph【转】
edgraph图表控件的强大功能令人出乎意料,与OWC相比我想应该毫不逊色,近来需求要求作出相关数据统计,不想使用BI这类的强大东西,所以搜索到 了免费的开源的Zedgraph控件.使用起来也非常方便 ...
- 百度api使用心得体会
最近项目中在使用百度地图api,对于其中的一些有用的点做一些归纳整理,如有不对的地方,欢迎各位大神纠正指出. 一定要学会查找百度地图api提供的类参考网站:http://lbsyun.baidu.co ...
- Surface pro 4 使用心得
今天谈谈这几个月Surface pro 4的使用心得.这篇后面有点跑题,行文也比较随意,就当闲笔了. 设备简述 使用体验 优点 不足 优雅使用 系统界面 应用 系统应用 工具应用 生产工具 其他应用 ...
- 朱晔的互联网架构实践心得S1E10:数据的权衡和折腾【系列完】
朱晔的互联网架构实践心得S1E10:数据的权衡和折腾[系列完] [下载本文PDF进行阅读] 本文站在数据的维度谈一下在架构设计中的一些方案对数据的权衡以及数据流转过程中的折腾这两个事情.最后进行系列文 ...
随机推荐
- Apache+Php+Mariadb+NFS+discuz
安装LAMP服务器,并利用discuz做测试 nfs + discuz 192.168.108.158 php + DNS 192.168.108.160 apache ...
- spring Boot启动报错Initialization of bean failed; nested exception is java.lang.NoSuchMethodError: org.springframework.core.annotation.AnnotatedElementUtils.getAnnotationAttributes
spring boot 启动报错如下 org.springframework.context.ApplicationContextException: Unable to start web serv ...
- Linux——用户管理简单学习笔记(二)
其实如果我们了解了Linux中用户管理的配置文件之后,完全可以手工管理用户: 添加用户: useradd 设置选项 用户名 -D 查看缺省参数 u:UID g:缺省所属用户组GID G:指定用户所属多 ...
- python 时间戳转元组
#!/usr/bin/python # -*- coding: UTF- -*- import time localtime = time.localtime(time.time()) print(& ...
- [JSBSim]基于winsocket2的TCP\UDP使用例子
TCP部分: 参考:http://blog.csdn.net/sbfksmq/article/details/50808863 另附:linux下的tcp/udp参考:https://www.cnbl ...
- [原][JSBSim]基于qt代码实现:TCP|UDP与飞行模拟软件JSBSim的通信,现实模型飞行!
废话没有,上关键代码 头文件 #include <QUdpSocket> #include <qtcpsocket.h> #ifndef vrUDP #define vrUDP ...
- 技术分享:SSH实战项目
1.需求分析 系统概述: 企业人事管理系统. 要求对员工信息进行维护. 后台系统先登录,才能操作员工;添加.修改.删除. 没有登录,只能查看列表,不能操作. 功能分类: 1)[管理员模块] 注册/登录 ...
- 爱阅app --- 答复功能改进建议
共有四组评论,接下来一一答复. 第一组: 希望增加的功能: 1.希望能够继续完善书签功能,增加逐条删除书签功能. 2.能够在爱阅内部打开APP中提供的网址,用户选择一款阅读APP,当然不想每看一本新的 ...
- Ubuntu 16.04下docker ce的安装
卸载版本的docker sudo apt-get remove docker docker-engine docker.io 安装可选内核模块 从 Ubuntu 14.04 开始,一部分内核模块移到了 ...
- JDK1.5 新特性
1:自动装箱与拆箱 自动装箱:每当需要一种类型的对象时,这种基本类型就自动地封装到与它相同类型的包装中. 自动拆箱:每当需要一个值时,被装箱对象中的值就被自动地提取出来,没必要再去调用intValue ...