Graphics g = this.groupBox1.CreateGraphics();
g.Clear(Color.SeaShell);
Brush b = new SolidBrush(Color.Blue);
Font f = new Font("Arial", 9, FontStyle.Regular);
Pen p = new Pen(b); using (da = new SqlDataAdapter("select * from hjb where 温度='" + str + "' order by 温度", con))
{
ds = new DataSet();
da.Fill(ds,"温度");
int a = MaxValue - MinValue;
for (double i = 0; i < a; i = i + 0.25)
{
Point p1 = new Point();
p1.X = 0;
p1.Y = Convert.ToInt16(190 - 30 * (i * 4));
g.DrawString(Convert.ToString(8+i*2),f,b,p1);
Point p2 = new Point();
Point p3 = new Point();
p2.X = 30; p2.Y = Convert.ToInt16(200 - 30 * (i * 4));
p3.X = 360; p3.Y = Convert.ToInt16(200 - 30 * (i * 4));
g.DrawLine(p, p2,p3);
}
NUM = ds.Tables[0].Rows.Count;
double[] velocity = new double[NUM];
for (int C = 0; C < NUM; C++)
{
velocity[C] = Convert.ToDouble(ds.Tables[0].Rows[C][2].ToString());
g.DrawString(Convert.ToDateTime(ds.Tables[0].Rows[C][1].ToString()).Day + "日", f, b, 30 * (C + 1) - 10, 210);
g.DrawLine(p, 30 * (C + 1), 200, 30 * (C + 1), 10);
}
Point[] P = new Point[NUM];
for (int i = 0; i < NUM; i++)
{
P[i].X = 30 * (i + 1);
P[i].Y = Convert.ToInt32( 200 - (velocity[i]-8)*2*30);
}
Pen pp = new Pen(Color.Red, 2f);
g.DrawLines(pp,P);
}
g.Clear(Color.SeaShell);
Brush b = new SolidBrush(Color.Blue);
Font f = new Font("Arial", 9, FontStyle.Regular);
Pen p = new Pen(b); using (da = new SqlDataAdapter("select * from hjb where 温度='" + str + "' order by 温度", con))
{
ds = new DataSet();
da.Fill(ds,"温度");
int a = MaxValue - MinValue;
for (double i = 0; i < a; i = i + 0.25)
{
Point p1 = new Point();
p1.X = 0;
p1.Y = Convert.ToInt16(190 - 30 * (i * 4));
g.DrawString(Convert.ToString(8+i*2),f,b,p1);
Point p2 = new Point();
Point p3 = new Point();
p2.X = 30; p2.Y = Convert.ToInt16(200 - 30 * (i * 4));
p3.X = 360; p3.Y = Convert.ToInt16(200 - 30 * (i * 4));
g.DrawLine(p, p2,p3);
}
NUM = ds.Tables[0].Rows.Count;
double[] velocity = new double[NUM];
for (int C = 0; C < NUM; C++)
{
velocity[C] = Convert.ToDouble(ds.Tables[0].Rows[C][2].ToString());
g.DrawString(Convert.ToDateTime(ds.Tables[0].Rows[C][1].ToString()).Day + "日", f, b, 30 * (C + 1) - 10, 210);
g.DrawLine(p, 30 * (C + 1), 200, 30 * (C + 1), 10);
}
Point[] P = new Point[NUM];
for (int i = 0; i < NUM; i++)
{
P[i].X = 30 * (i + 1);
P[i].Y = Convert.ToInt32( 200 - (velocity[i]-8)*2*30);
}
Pen pp = new Pen(Color.Red, 2f);
g.DrawLines(pp,P);
}
Point[] points =
{
new Point(10, 10),
new Point(10, 100),
new Point(200, 50),
new Point(250, 300)
};
e.Graphics.DrawLines(pen, points);
单步看看数据
if(NUM <=0)
{
return;
}确保NUM〉0不然后面的无意义
{
int MaxValue = 0, MinValue = 0; int NUM;
using (cmd = new SqlCommand("select Max(温度) from hjb'" + str + "'", con))
{
con.Open();
MaxValue = Convert.ToInt32(cmd.ExecuteScalar());
con.Close();
}
using (cmd = new SqlCommand("select Min(温度) from hjb '" + str + "'", con))
{
con.Open();
MinValue = Convert.ToInt32(cmd.ExecuteScalar());
con.Close();
}
Graphics g = this.groupBox1.CreateGraphics();
g.Clear(Color.SeaShell);
Brush b = new SolidBrush(Color.Blue);
Font f = new Font("Arial", 9, FontStyle.Regular);
Pen p = new Pen(b); using (da = new SqlDataAdapter("select * from hjb where 温度='" + str + "' order by 温度", con))
{
ds = new DataSet();
da.Fill(ds,"温度");
int a = MaxValue - MinValue;
for (double i = 0; i < a; i = i + 0.25)
{
Point p1 = new Point();
p1.X = 0;
p1.Y = Convert.ToInt32(190 - 30 * (i * 4));
g.DrawString(Convert.ToString(8+i*2),f,b,p1);
Point p2 = new Point();
Point p3 = new Point();
p2.X = 30; p2.Y = Convert.ToInt16(200 - 30 * (i * 4));
p3.X = 360; p3.Y = Convert.ToInt16(200 - 30 * (i * 4));
g.DrawLine(p, p2,p3);
}
NUM = ds.Tables[0].Rows.Count;
double[] velocity = new double[NUM];
NUM = ds.Tables[0].Rows.Count;
if (NUM <= 0)
{
return;
} for (int C = 0; C < NUM; C++)
{
velocity[C] = Convert.ToDouble(ds.Tables[0].Rows[C][2].ToString());
g.DrawString(Convert.ToDateTime(ds.Tables[0].Rows[C][1].ToString()).Day + "日", f, b, 30 * (C + 1) - 10, 210);
g.DrawLine(p, 30 * (C + 1), 200, 30 * (C + 1), 10);
}
Point[] P = new Point[NUM];
for (int i = 0; i < NUM; i++)
{
P[i].X = 30 * (i + 1);
P[i].Y = Convert.ToInt32( 200 - (velocity[i]-8)*2*30);
}
Pen pp = new Pen(Color.Red, 2f);
g.DrawLines(pp,P);
这样还是不行 大侠们帮忙 谢谢