用的是C#winform,数据库用的是sql sever 2008想要做一个这样的功能:
text框是血压值,点击button就可以保存到数据库中,然后界面有曲线图(趋势图)表现出来,类似这样:
数据保存这部分做好了,曲线图这部分不知道怎么下手,希望大佬们帮帮我(真挚的感谢)
int pbHeight = PBth.Height, pbWidtht = PBth.Width;
Graphics g = PBth.CreateGraphics();
try
{
//清空图片背景色
g.Clear(Color.White);
DateTime ssss = DateTime.Parse(DtpTH.Text.ToString());
Font font = new System.Drawing.Font("Arial", 9, FontStyle.Regular);
Font font1 = new System.Drawing.Font("宋体", 20, FontStyle.Regular);
Font font2 = new System.Drawing.Font("Arial", 8, FontStyle.Regular);
LinearGradientBrush brush = new LinearGradientBrush(new Rectangle(0, 0, pbWidtht, pbHeight), Color.Blue, Color.Blue, 1.2f, true);
g.FillRectangle(Brushes.AliceBlue, 0, 0, pbWidtht, pbHeight);
Brush brush1 = new SolidBrush(Color.Blue);
Brush brush2 = new SolidBrush(Color.SaddleBrown);
g.DrawString(cobRo.SelectedItem+"节点"+ DtpTH.Text.ToString() + "温湿度变化折线图", font1, brush1, new PointF(pbWidtht/2-250, 30));
//画图片的边框线
g.DrawRectangle(new Pen(Color.Blue), 0, 0, pbWidtht - 1, pbHeight - 1);
Pen mypen = new Pen(brush, 1);
Pen mypen2 = new Pen(Color.Red, 2);
//绘制线条
//绘制纵向线条
int Ww = (pbWidtht - 100) / 24;
int x = 60;
for (int i = 0; i < 24; i++)
{
g.DrawLine(mypen, x, 80, x, 331);
x = x + Ww;
}
Pen mypen1 = new Pen(Color.Blue, 3);
//x = 60;
g.DrawLine(mypen1,60, 82, 60, 331);
//绘制横向线条
int y = 106;
for (int i = 0; i < 10; i++)
{
g.DrawLine(mypen, 60, y, x, y);
y = y + 25;
}
// y = 106;
g.DrawLine(mypen1, 60, y - 25, x, y - 25);
//x轴
String[] n = { "0时", "1时", "2时", "3时", "4时", "5时", "6时", "7时", "8时", "9时", "10时", "11时", "12时", "13时", "14时", "15时", "16时", "17时", "18时", "19时", "20时", "21时", "22时", "23时" };
x = 45;
for (int i = 0; i < 24; i++)
{
g.DrawString(n[i].ToString(), font, Brushes.Black, x, 348); //设置文字内容及输出位置
x = x + Ww;
}
//y轴
String[] m = { "50","45", "40", "35", "30", "25", "20", "15", "10", "5","0" };
y = 98-25;
for (int i = 0; i < 11; i++)
{
g.DrawString(m[i].ToString(), font, Brushes.Black, 35, y); //设置文字内容及输出位置
y = y + 25;
}
conn.Open();
string cmdtxt2 = "select * from remote_THinfo where remote_address='" + cobRo.SelectedItem + "' and addTime between '"+ ssss.ToString("yyyy/MM/dd") + " 00:00:01' and '" + ssss.ToString("yyyy/MM/dd") + " 23:59:59'";
SqlDataAdapter da = new SqlDataAdapter(cmdtxt2, conn);
DataTable dt = new DataTable("remote_THinfo");
da.Fill(dt);
int PointNum = dt.Rows.Count;
if (PointNum < 2)
{
return;
}
int[] Count1 = new int[PointNum];
int[] Count2 = new int[PointNum];
//温湿度
for (int i = 0; i < PointNum; i++)
{
Count1[i] = int.Parse(dt.Rows[i]["Temperature"].ToString());
Count2[i] = int.Parse(dt.Rows[i]["Humidity"].ToString());
}
//显示折线效果
Font font3 = new System.Drawing.Font("Arial", 10, FontStyle.Bold);
SolidBrush mybrush = new SolidBrush(Color.Red);
Point[] points1 = new Point[PointNum];
for (int i = 0; i < PointNum; i++)
{
points1[i].X = 60 + Ww * i; points1[i].Y = 331 - Count1[i] * 5;
g.DrawString(Count1[i].ToString() + "℃", font3, Brushes.Red, 58 + i * Ww, points1[i].Y - 20);
}
g.DrawLines(mypen2, points1); //绘制折线
Pen mypen3 = new Pen(Color.Green, 2);
Point[] points2 = new Point[PointNum];
for (int i = 0; i < PointNum; i++)
{
points2[i].X = 60 + i * Ww; points2[i].Y = 331 - Count2[i] * 5;
g.DrawString(Count2[i].ToString() + "%", font3, Brushes.Green, 61 + i * Ww, points2[i].Y - 15);
}
g.DrawLines(mypen3, points2); //绘制折线
//绘制标识
g.DrawRectangle(new Pen(Brushes.Red), pbWidtht / 2 - 155, 390, 250, 50); //绘制范围框
g.FillRectangle(Brushes.Red, pbWidtht / 2 - 50, 402, 20, 10); //绘制小矩形
g.DrawString("温度", font2, Brushes.Red, pbWidtht / 2 - 30, 400);
g.FillRectangle(Brushes.Green, pbWidtht / 2 - 50, 422, 20, 10);
g.DrawString("湿度", font2, Brushes.Green, pbWidtht / 2 - 30, 420);
System.IO.MemoryStream ms = new System.IO.MemoryStream();
}
catch (Exception ex)
{
tools.WriteLog(ex,"");
}
finally
{
conn.Close();
g.Dispose();
//PBth.Dispose();
}
