我是.net 的初学者,本人才鸟一个,数据格式(部分)如下,我想问怎么可以调入这个文本数据,然后形成一个以时间(第2列)为横坐标,压力(第4列)为纵坐标的曲线图?C#语言开发。急等,那位帮帮忙!多谢,说得越详细越好 ^_^
jdyd 测井数据记录
==========================
日 期: 2006-09-22-09-26
井 号: B020010000031
套 压: 0.52
油 压: 0.65
下入深度: 825.18
电池电压: 6.00
操作人员: 刘振山
压力计号: 019
文 件 名: D:\yhfwin\dat\2-1-31.dat
测压方式: 2
测 点 数: 742 序号 累计时间(s) 温度(℃) 压力(MPa) 1 0 26.39 0.002
2 30 26.42 -0.002
3 60 26.45 0.516
4 90 27.30 0.576
5 120 29.43 0.929
6 150 32.45 1.251
7 180 35.01 1.539
8 210 36.98 1.973
9 240 38.47 2.450
10 270 39.70 2.799
11 300 40.74 2.795
12 330 41.58 2.785
13 360 42.27 2.777
14 390 42.80 2.770
15 420 43.27 2.967
16 450 43.71 3.464
17 480 44.19 4.194
jdyd 测井数据记录
==========================
日 期: 2006-09-22-09-26
井 号: B020010000031
套 压: 0.52
油 压: 0.65
下入深度: 825.18
电池电压: 6.00
操作人员: 刘振山
压力计号: 019
文 件 名: D:\yhfwin\dat\2-1-31.dat
测压方式: 2
测 点 数: 742 序号 累计时间(s) 温度(℃) 压力(MPa) 1 0 26.39 0.002
2 30 26.42 -0.002
3 60 26.45 0.516
4 90 27.30 0.576
5 120 29.43 0.929
6 150 32.45 1.251
7 180 35.01 1.539
8 210 36.98 1.973
9 240 38.47 2.450
10 270 39.70 2.799
11 300 40.74 2.795
12 330 41.58 2.785
13 360 42.27 2.777
14 390 42.80 2.770
15 420 43.27 2.967
16 450 43.71 3.464
17 480 44.19 4.194
解决方案 »
- c#调用JS文件中的函数
- 如何控制按tab在datagridview跳动
- 按下回车键后Combox控件焦点转移到下一控件?
- C#里如何指定参数不可写?类似C++里的const
- 请高手指教,关于TableControl和ImageList的问题
- C# excel 如何关闭进程
- 求教关于ListView控件的问题(送份30!)
- 2008年的奥运会,我们程序员可以做些什么,除了看比赛?
- 请问关于如何比较一个文件夹
- 请问:调试的时候出现“异常详细信息: System.Data.SqlClient.SqlException: 用户 'NT AUTHORITY\NETWORK SERVICE' 登录失败。”的错误,
- DataAdapter的Fill问题,请指教....
- c#2.0中tablelayoutpanel的问题
这个回复有点不负责任:-)最近刚开始接触Crystal Reports~~~
编写一个存储过程,结果基本如下:
创建一个TEMP表
将时间写进去
用游标来比较记录中的数据,再UPDATE
最后得到结果。
哈哈,不过比较慢。
你需要使用的类是:AxMSChart20Lib.AxMSChart 稍后给你贴出代码
http://www.woziji.com/user1/infofox/archives/2006/1440.html
经过很多次的测试没有一点问题!
下面第一个问题如何加:AxMSChart20Lib到自己的C#系统上(很多人都问了,所以告诉大家很简单的)
在[工具]->[添加/移出工具箱]->鼠标单击->选择[COM组件]
找到Mcrosoft Chart Control 6.0(SP4)(oledb) 选中,然后[确定],你会发现你的工具箱里面有了一个这样的控件了!然后接着开始写代码!
____________________________________慢慢看把,道路很长的哦(记得给我分哦)_____________
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;namespace WindowsApplication1
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
//这里申明了DataSet,OleDbCommand,OleDbDataAdapter和OleDbConnection
private System.Data.DataSet ds;
private System.Data.OleDb.OleDbCommand oleDbSelectCommand1;
private System.Data.OleDb.OleDbCommand oleDbInsertCommand1;
private System.Data.OleDb.OleDbCommand oleDbUpdateCommand1;
private System.Data.OleDb.OleDbCommand oleDbDeleteCommand1;
private System.Data.OleDb.OleDbDataAdapter da;
private System.Data.OleDb.OleDbCommand comm;
private System.Data.OleDb.OleDbConnection cn; //这里声明了一个AxMSChart类的实例;
private AxMSChart20Lib.AxMSChart axMSChart1;
private System.Windows.Forms.TextBox t1;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null; public void myphoto()
{
//装载数据库的数据
cn.ConnectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+Application.StartupPath+"\\data\\hzj.mdb"+";Persist Security Info=False";
cn.Open();
comm.Connection=cn;
//我的表命名为myid,ST字段代表累计时间(s),yl代表压力(MPa)
string sql="select st,yl from myid";
comm.CommandText=sql;
da.SelectCommand=comm;
da.Fill(ds,"newtb"); //设计原理,由于axMSChart1的数据是直接可以接受一个二为数组的,
//所以我把事先读好的数据放到一个数组里
//注意数据库对应二为数组,是这样的行是一位,列是二位;
//所以我们看看就这样做
//由于楼主提出以时间(第2列)为横坐标,压力(第4列)为纵坐标的曲线图
//所以我们要把时间放在数组里的第一位,而压力放在第2位
//因为在axMSChart里数组第一位代表横坐标
//最后我们申明一个2纬数组,由于2纬数组一位代表行
//所以我们可以用ds.Tables["newtb"].Rows.Count取得行的总数
//而我们只要2列就可以了,所以我们是直接知道2纬数组的第2位的值,也就是2
//最后也是最关键的,也就是axMSChart需要数组里的第一个值来描述坐标点的说明
//所以我们就要空出一个位的数组来做描述
//因此数组真正的长度为ds.Tables["newtb"].Rows.Count+1
Object[,] myay=new Object[ds.Tables["newtb"].Rows.Count+1,2]; myay[0,0]=(Object)"时间描述";//这里可以不用写什么
myay[0,1]=(Object)"压力描述";//这里是描述坐标点的压力
for(int i=1;i<=ds.Tables["newtb"].Rows.Count;i++)
{
//这里是个重点,为什么要加上"["+"]"
//其实这个axMSChart1玩意很有意识的,如果你的字符串是数字类型的描述
//就算是字符串类型也不会当成横坐标哦!!
//嘿嘿有意识把,本人曾经为了这个问题搞了几天的!
myay[i,0]=(Object)"["+ds.Tables["newtb"].Rows[i-1]["st"].ToString()+"]";
myay[i,1]=(Object)ds.Tables["newtb"].Rows[i-1]["yl"].ToString();
} //设计axMSChart1的数据 axMSChart1.ChartData = myay;
//设计图表的表头名称和对齐方式
axMSChart1.Title.Text = "这里是一个图表"; axMSChart1.Legend.Location.LocationType = MSChart20Lib.VtChLocationType.VtChLocationTypeRight; axMSChart1.Legend.Location.Visible = true;
//设计X轴名称
axMSChart1.Plot.get_Axis(MSChart20Lib.VtChAxisId.VtChAxisIdX, null).AxisTitle.Text = "这里是时间描述";
//设计Y轴名称
axMSChart1.Plot.get_Axis(MSChart20Lib.VtChAxisId.VtChAxisIdY, null).AxisTitle.Text = "这里是压力描述";
//设计图表形状的描述方式,是并图还是线图等等
//axMSChart1.chartType = MSChart20Lib.VtChChartType.VtChChartType2dLine;
ds.Tables.Clear();
cn.Close();
} public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent(); //
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
} /// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
} #region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
this.ds = new System.Data.DataSet();
this.oleDbSelectCommand1 = new System.Data.OleDb.OleDbCommand();
this.oleDbInsertCommand1 = new System.Data.OleDb.OleDbCommand();
this.oleDbUpdateCommand1 = new System.Data.OleDb.OleDbCommand();
this.oleDbDeleteCommand1 = new System.Data.OleDb.OleDbCommand();
this.da = new System.Data.OleDb.OleDbDataAdapter();
this.comm = new System.Data.OleDb.OleDbCommand();
this.cn = new System.Data.OleDb.OleDbConnection();
this.axMSChart1 = new AxMSChart20Lib.AxMSChart();
this.t1 = new System.Windows.Forms.TextBox();
((System.ComponentModel.ISupportInitialize)(this.ds)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.axMSChart1)).BeginInit();
this.SuspendLayout();
//
// ds
//
this.ds.DataSetName = "NewDataSet";
this.ds.Locale = new System.Globalization.CultureInfo("zh-CN");
//
// da
//
this.da.DeleteCommand = this.oleDbDeleteCommand1;
this.da.InsertCommand = this.oleDbInsertCommand1;
this.da.SelectCommand = this.oleDbSelectCommand1;
this.da.UpdateCommand = this.oleDbUpdateCommand1;
//
// axMSChart1
//
this.axMSChart1.DataSource = null;
this.axMSChart1.Location = new System.Drawing.Point(0, 8);
this.axMSChart1.Name = "axMSChart1";
this.axMSChart1.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("axMSChart1.OcxState")));
this.axMSChart1.Size = new System.Drawing.Size(688, 328);
this.axMSChart1.TabIndex = 0;
//
// t1
//
this.t1.Location = new System.Drawing.Point(80, 384);
this.t1.Name = "t1";
this.t1.Size = new System.Drawing.Size(544, 21);
this.t1.TabIndex = 1;
this.t1.Text = "textBox1";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(704, 445);
this.Controls.Add(this.t1);
this.Controls.Add(this.axMSChart1);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
((System.ComponentModel.ISupportInitialize)(this.ds)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.axMSChart1)).EndInit();
this.ResumeLayout(false); }
#endregion /// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Form1 myf=new Form1();
myf.myphoto();
Application.Run(myf);
} private void Form1_Load(object sender, System.EventArgs e)
{
}
}
}
其实MSChart20Lib这个东东是很厉害的