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进行阅读] 本文站在数据的维度谈一下在架构设计中的一些方案对数据的权衡以及数据流转过程中的折腾这两个事情.最后进行系列文 ...
随机推荐
- #实现详细记录登陆过系统的用户,IP地址,shell命令及详细操作的时间
//实现详细记录登陆过系统的用户,IP地址,shell命令及详细操作的时间 将下面代码加入/etc/profile //history USER_IP = who -u am i 2> /dev ...
- [BZOJ]|[Ural] Formula 1-----插头DP入门
1519. Formula 1 Time limit: 1.0 secondMemory limit: 64 MB Background Regardless of the fact, that Vo ...
- set/multiset_01
按序排列 不能指定插入位置 红黑树变体 不可以直接存取元素(即 无[?]/at(?)操作) 不可以直接修改元素值(用 先删除后添加的方式,达到相同效果) A.头尾 添加/移除 B.随机存取 C.数据存 ...
- js 文件上传
<head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8&quo ...
- Codeforces 140D - New Year Contest
140D - New Year Contest 思路:贪心+排序.罚时与时间成正比,因为在0点前做完的题都可以在0点提交.从时间短的开始做最优. 代码: #include<bits/stdc++ ...
- iframe 通信问题
iframe作用: 1:页面部分刷新(iframe也是一个window,html是完整的不是部分html片段) 2:跨域 3:父子window通信 iframe1.window.xx=xx;paren ...
- MyBatis3-基于注解的示例
在基于注解的示例中,可以简化编写XML的过程,全部采用注解方式进行编写,并在注解上写SQL语句,语句和XML的语句保持一致,并且可以省略掉XML文件不用引入的好处.但还有一点,基于注解的方式还没有百分 ...
- dns未设置 PHP Warning: file_get_contents():php_network_getaddresses: getaddrinfo failed:
php通过去访问外部网站时,出现以下提示: PHP Warning: file_get_contents(): php_network_getaddresses: getaddrinfo failed ...
- Confluence 6 教程:在 Confluence 中导航
当你对 Confluence 有所了解后,你会发现 Confluence 使用起来非常简单.这个教程主要是针对你使用的 Confluence 界面进行一些说明,同时向你展示在那里可以进行一些通用的任务 ...
- 一篇文章,读懂Netty的高性能架构之道
一篇文章,读懂Netty的高性能架构之道 Netty是由JBOSS提供的一个java开源框架,是一个高性能.异步事件驱动的NIO框架,它提供了对TCP.UDP和文件传输的支持,作为一个异步NIO框架, ...