c 读取mysql返回winform,C# winform中怎么从数据库取数据绘制实时曲线图

C# codeGraphPane myPan = new GraphPane();

PointPairList list = new PointPairList();

Random ran = new Random();

LineItem myCurve;

DataSet ds = new DataSet();

SqlConnection myConnection = null;

SqlCommand myCommand = null;

SqlDataAdapter adapt = null;

SqlDataReader reader = null;

public Form1()

{

InitializeComponent();

}

public string GetConnectString(string server, string database, string username, string password)

{

return "Server=" + server + ";Database=" + database + ";UID=" + username + ";PWD=" + password;

}

public void Exc()

{

double x, y;

myConnection = new SqlConnection();

myConnection.ConnectionString = GetConnectString("192.168.0.101", "AMR", "sa", "123");

myCommand = new SqlCommand("select MSID,UpdateTime from Tab_BS_Dailyfile", myConnection);

myCommand.CommandType = CommandType.Text;

myConnection.Open();

adapt = new SqlDataAdapter();

try

{

//myCommand.ExecuteNonQuery();

reader = myCommand.ExecuteReader();

while (reader.Read())

{

for (int i = 0; i < reader.FieldCount; )

{

y = double.Parse(reader[i++].ToString());

x = (double)new XDate(DateTime.Parse(reader[i++].ToString()));

list.Add(x, y);

}

}

}

catch (SqlException ex)

{

MessageBox.Show("插入错误!" + ex.Message.ToString());

}

myCommand.Clone();

myConnection.Close();

}

private void Form1_Load(object sender, EventArgs e)

{

this.zedGraphControl1.GraphPane.Title.Text = "动态折线图";

this.zedGraphControl1.GraphPane.XAxis.Title.Text = "时间";

this.zedGraphControl1.GraphPane.X2Axis.Scale.FontSpec.Size = 28;

this.zedGraphControl1.GraphPane.YAxis.Title.Text = "数量";

this.zedGraphControl1.GraphPane.YAxis.Scale.FontSpec.Size = 8;

myPan.XAxis.Scale.IsVisible = true;

this.zedGraphControl1.GraphPane.XAxis.Type = ZedGraph.AxisType.DateAsOrdinal;

Exc();

DateTime dt = DateTime.Now;

myCurve = zedGraphControl1.GraphPane.AddCurve("My Curve",

list, Color.DarkGreen, SymbolType.None);

this.zedGraphControl1.AxisChange();

this.zedGraphControl1.Refresh();

}

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值