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画图心得的更多相关文章

  1. ZEDGRAPH画图心得,SQL语句构造!!!

    /// <summary> /// 画折线 /// </summary> public void Drawline() { OleDbConnection odcConnect ...

  2. C#:ZedGraph画图控件(待补充)

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  3. zedgraph中禁用鼠标滚轮变焦(禁止画图区域随鼠标滚动改变XY轴,定位)(转)

    禁用鼠标滚轮变焦的zedgraph功能 如果zgc是你ZedGraphControl实例,请使用: zgc.ZoomButtons = MouseButtons.None; zgc.ZoomButto ...

  4. windows类书的学习心得(转载)

    原文网址:http://www.blogjava.net/sound/archive/2008/08/21/40499.html 现在的计算机图书发展的可真快,很久没去书店,昨日去了一下,真是感叹万千 ...

  5. zedGraph

    “zedGraph”控件画图的时候遇到了一点小问题,就是在同一个控件实例上第一次绘制饼图的时候一切正常,但是再次绘制的时候不是重新绘制新的饼图,而是在原有基础之上又添加进新的对象(PieItem),又 ...

  6. GridView+ZedGraph【转】

    edgraph图表控件的强大功能令人出乎意料,与OWC相比我想应该毫不逊色,近来需求要求作出相关数据统计,不想使用BI这类的强大东西,所以搜索到 了免费的开源的Zedgraph控件.使用起来也非常方便 ...

  7. 百度api使用心得体会

    最近项目中在使用百度地图api,对于其中的一些有用的点做一些归纳整理,如有不对的地方,欢迎各位大神纠正指出. 一定要学会查找百度地图api提供的类参考网站:http://lbsyun.baidu.co ...

  8. Surface pro 4 使用心得

    今天谈谈这几个月Surface pro 4的使用心得.这篇后面有点跑题,行文也比较随意,就当闲笔了. 设备简述 使用体验 优点 不足 优雅使用 系统界面 应用 系统应用 工具应用 生产工具 其他应用 ...

  9. 朱晔的互联网架构实践心得S1E10:数据的权衡和折腾【系列完】

    朱晔的互联网架构实践心得S1E10:数据的权衡和折腾[系列完] [下载本文PDF进行阅读] 本文站在数据的维度谈一下在架构设计中的一些方案对数据的权衡以及数据流转过程中的折腾这两个事情.最后进行系列文 ...

随机推荐

  1. 【Coursera】SecondWeek(2)

    The First Two Packets on the Internet Leonard Kleinrock Kleinrock 是一名工程师和计算机科学家,他在APRANET网络中起到了至关重要的 ...

  2. python从字符串解析方法名

    方法如下 import requests func_name = 'get' fn_obj = getattr(requests,func_name) fn_obj('http://www.baidu ...

  3. Java中Arrays 与 Collections 的简单操作

    import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.C ...

  4. hdu 5493 Queue 树状数组第K大或者二分

    Queue Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submi ...

  5. jquery作业 教授答案

    http://www.cnblogs.com/qianjinyan/p/8961086.html 题目要求: 1. 通过jquery动态的创建一个表格,随机生成(id自增,name随机2-3个中文汉字 ...

  6. unable to find resource 'xxx\xx\overview.vm' in any resource loader.

    ResourceManager : unable to find resource 'C:\Test\TestConfig\overview.vm' in any resource loader.or ...

  7. Java 集合-List接口和三个子类实现

    List List:有序的 collection(也称为序列).此接口的用户可以对列表中每个元素的插入位置进行精确地控制.用户可以根据元素的整数索引(在列表中的位置)访问元素,并搜索列表中的元素.与 ...

  8. Android 使用SQLite

    SQLite简介 Google为Andriod的较大的数据处理提供了SQLite,他在数据存储.管理.维护等各方面都相当出色,功能也非常的强大.SQLite具备下列特点: 1.轻量级 使用 SQLit ...

  9. 【python】模块整理

    ---文件.系统--- import glob  # 给定路径下查找符合规则文件.三个匹配符:”*”, “?”, “[]”.”*”匹配0个或多个字符:”?”匹配单个字符:”[]”匹配指定范围内的字符, ...

  10. 你的centos/linux下有多个php.ini,不确定是哪个时

    你的centos/linux下有多个php.ini,不确定是哪个时,但是你自己知道,你的php安装目录. 比如我的php安装目录是 /usr/local/php 那么可以通过命令来查找php.ini的 ...