asp.net 如何去画多条折线图
3个回答
展开全部
直接调用该方法即可:
private void CreateImage()
{
int height = 480, width = 700;
Bitmap image = new Bitmap(width, height);
Graphics g = Graphics.FromImage(image);
try
{
//清空图片背景色
g.Clear(Color.White);
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);
Brush brush1 = new SolidBrush(Color.Blue);
Brush brush2 = new SolidBrush(Color.SaddleBrown);
//画图片的边框线
g.DrawRectangle(new Pen(Color.Blue), 0, 0, image.Width - 1, image.Height - 1);
Pen mypen = new Pen(brush1, 1);
Pen mypen2 = new Pen(Color.Red, 2);
//绘制线条
//绘制纵向线条
int x = 60;
for (int i = 0; i < 8; i++)
{
g.DrawLine(mypen, x, 80, x, 340);
x = x + 80;
}
Pen mypen1 = new Pen(Color.Blue, 3);
x = 60;
g.DrawLine(mypen1, x, 82, x, 340);
//绘制横向线条
int y = 106;
for (int i = 0; i < 10; i++)
{
g.DrawLine(mypen, 60, y, 620, y);
y = y + 26;
}
// y = 106;
g.DrawLine(mypen1, 60, y - 26, 620, y - 26);
//x轴
String[] n = { "0", "12秒", "24秒", "36秒", "48秒", "60秒", "72秒","84秒","","" };
x = 45;
for (int i = 0; i < 10; i++)
{
g.DrawString(n[i].ToString(), font, Brushes.Red, x, 348); //设置文字内容及输出位置
x = x + 77;
}
//y轴
String[] m = { "220", " 200", " 175", "150", " 125", " 100", " 75", " 50",
" 25"};
y = 100;
for (int i = 0; i < 9; i++)
{
g.DrawString(m[i].ToString(), font, Brushes.Red, 10, y); //设置文字内容及输出位置
y = y + 26;
}
int[] Count1 = new int[10];
int[] Count2 = new int[7];
//报名人数
Count1[0] = 103;
Count1[1] = 200;
Count1[2] = 152;
Count1[3] = 201;
Count1[6] = 75;
Count1[4] = 50;
Count1[5] = 200;
Count1[7] = 200;
Count1[8] = 200;
Count1[9] = 200;
Count2[0] = 15;
Count2[1] = 24;
Count2[2] = 25;
Count2[3] = 13;
Count2[6] = 77; //全年
Count2[4] = 39;
Count2[5] = 38;
//显示折线效果
Font font3 = new System.Drawing.Font("Arial", 10, FontStyle.Bold);
SolidBrush mybrush = new SolidBrush(Color.Red);
Point[] points1 = new Point[10];
int istart = 60;
for (int l = 0; l < 10; l++)
{
points1[l].X = istart;
points1[l].Y = 340 - Count1[l]; //从106纵坐标开始, 到(0, 0)坐标时
istart += 80;
}
g.DrawLines(mypen2, points1); //绘制折线
//绘制数字
int sstat = 58;
for (int p = 0; p < 10; p++)
{
g.DrawString(Count1[p].ToString(), font3, Brushes.Red, sstat, points1[p].Y - 20);
sstat += 80;
}
Pen mypen3 = new Pen(Color.Green, 2);
Point[] points2 = new Point[7];
points2[0].X = 60; points2[0].Y = 340 - Count2[0];
points2[1].X = 140; points2[1].Y = 340 - Count2[1];
points2[2].X = 220; points2[2].Y = 340 - Count2[2];
points2[3].X = 300; points2[3].Y = 340 - Count2[3];
points2[4].X = 380; points2[4].Y = 340 - Count2[4];
points2[5].X = 460; points2[5].Y = 340 - Count2[5];
points2[6].X = 540; points2[6].Y = 340 - Count2[6];
g.DrawLines(mypen3, points2); //绘制折线
//绘制通过人数
g.DrawString(Count2[0].ToString(), font3, Brushes.Green, 61, points2[0].Y - 15);
g.DrawString(Count2[1].ToString(), font3, Brushes.Green, 131, points2[1].Y - 15);
g.DrawString(Count2[2].ToString(), font3, Brushes.Green, 221, points2[2].Y - 15);
g.DrawString(Count2[3].ToString(), font3, Brushes.Green, 301, points2[3].Y - 15);
g.DrawString(Count2[4].ToString(), font3, Brushes.Green, 381, points2[4].Y - 15);
g.DrawString(Count2[5].ToString(), font3, Brushes.Green, 461, points2[5].Y - 15);
g.DrawString(Count2[6].ToString(), font3, Brushes.Green, 541, points2[6].Y - 15);
//绘制标识
g.DrawRectangle(new Pen(Brushes.Red), 180, 390, 250, 50); //绘制范围框
g.FillRectangle(Brushes.Red, 270, 402, 20, 10); //绘制小矩形
g.DrawString("入口温度", font2, Brushes.Red, 292, 400);
g.FillRectangle(Brushes.Green, 270, 422, 20, 10);
g.DrawString("出口温度", font2, Brushes.Green, 292, 420);
System.IO.MemoryStream ms = new System.IO.MemoryStream();
image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
Response.ClearContent();
Response.ContentType = "image/Jpeg";
Response.BinaryWrite(ms.ToArray());
}
finally
{
g.Dispose();
image.Dispose();
}
}
private void CreateImage()
{
int height = 480, width = 700;
Bitmap image = new Bitmap(width, height);
Graphics g = Graphics.FromImage(image);
try
{
//清空图片背景色
g.Clear(Color.White);
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);
Brush brush1 = new SolidBrush(Color.Blue);
Brush brush2 = new SolidBrush(Color.SaddleBrown);
//画图片的边框线
g.DrawRectangle(new Pen(Color.Blue), 0, 0, image.Width - 1, image.Height - 1);
Pen mypen = new Pen(brush1, 1);
Pen mypen2 = new Pen(Color.Red, 2);
//绘制线条
//绘制纵向线条
int x = 60;
for (int i = 0; i < 8; i++)
{
g.DrawLine(mypen, x, 80, x, 340);
x = x + 80;
}
Pen mypen1 = new Pen(Color.Blue, 3);
x = 60;
g.DrawLine(mypen1, x, 82, x, 340);
//绘制横向线条
int y = 106;
for (int i = 0; i < 10; i++)
{
g.DrawLine(mypen, 60, y, 620, y);
y = y + 26;
}
// y = 106;
g.DrawLine(mypen1, 60, y - 26, 620, y - 26);
//x轴
String[] n = { "0", "12秒", "24秒", "36秒", "48秒", "60秒", "72秒","84秒","","" };
x = 45;
for (int i = 0; i < 10; i++)
{
g.DrawString(n[i].ToString(), font, Brushes.Red, x, 348); //设置文字内容及输出位置
x = x + 77;
}
//y轴
String[] m = { "220", " 200", " 175", "150", " 125", " 100", " 75", " 50",
" 25"};
y = 100;
for (int i = 0; i < 9; i++)
{
g.DrawString(m[i].ToString(), font, Brushes.Red, 10, y); //设置文字内容及输出位置
y = y + 26;
}
int[] Count1 = new int[10];
int[] Count2 = new int[7];
//报名人数
Count1[0] = 103;
Count1[1] = 200;
Count1[2] = 152;
Count1[3] = 201;
Count1[6] = 75;
Count1[4] = 50;
Count1[5] = 200;
Count1[7] = 200;
Count1[8] = 200;
Count1[9] = 200;
Count2[0] = 15;
Count2[1] = 24;
Count2[2] = 25;
Count2[3] = 13;
Count2[6] = 77; //全年
Count2[4] = 39;
Count2[5] = 38;
//显示折线效果
Font font3 = new System.Drawing.Font("Arial", 10, FontStyle.Bold);
SolidBrush mybrush = new SolidBrush(Color.Red);
Point[] points1 = new Point[10];
int istart = 60;
for (int l = 0; l < 10; l++)
{
points1[l].X = istart;
points1[l].Y = 340 - Count1[l]; //从106纵坐标开始, 到(0, 0)坐标时
istart += 80;
}
g.DrawLines(mypen2, points1); //绘制折线
//绘制数字
int sstat = 58;
for (int p = 0; p < 10; p++)
{
g.DrawString(Count1[p].ToString(), font3, Brushes.Red, sstat, points1[p].Y - 20);
sstat += 80;
}
Pen mypen3 = new Pen(Color.Green, 2);
Point[] points2 = new Point[7];
points2[0].X = 60; points2[0].Y = 340 - Count2[0];
points2[1].X = 140; points2[1].Y = 340 - Count2[1];
points2[2].X = 220; points2[2].Y = 340 - Count2[2];
points2[3].X = 300; points2[3].Y = 340 - Count2[3];
points2[4].X = 380; points2[4].Y = 340 - Count2[4];
points2[5].X = 460; points2[5].Y = 340 - Count2[5];
points2[6].X = 540; points2[6].Y = 340 - Count2[6];
g.DrawLines(mypen3, points2); //绘制折线
//绘制通过人数
g.DrawString(Count2[0].ToString(), font3, Brushes.Green, 61, points2[0].Y - 15);
g.DrawString(Count2[1].ToString(), font3, Brushes.Green, 131, points2[1].Y - 15);
g.DrawString(Count2[2].ToString(), font3, Brushes.Green, 221, points2[2].Y - 15);
g.DrawString(Count2[3].ToString(), font3, Brushes.Green, 301, points2[3].Y - 15);
g.DrawString(Count2[4].ToString(), font3, Brushes.Green, 381, points2[4].Y - 15);
g.DrawString(Count2[5].ToString(), font3, Brushes.Green, 461, points2[5].Y - 15);
g.DrawString(Count2[6].ToString(), font3, Brushes.Green, 541, points2[6].Y - 15);
//绘制标识
g.DrawRectangle(new Pen(Brushes.Red), 180, 390, 250, 50); //绘制范围框
g.FillRectangle(Brushes.Red, 270, 402, 20, 10); //绘制小矩形
g.DrawString("入口温度", font2, Brushes.Red, 292, 400);
g.FillRectangle(Brushes.Green, 270, 422, 20, 10);
g.DrawString("出口温度", font2, Brushes.Green, 292, 420);
System.IO.MemoryStream ms = new System.IO.MemoryStream();
image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
Response.ClearContent();
Response.ContentType = "image/Jpeg";
Response.BinaryWrite(ms.ToArray());
}
finally
{
g.Dispose();
image.Dispose();
}
}
展开全部
添加命名空间
using System.Drawing;
using System.Drawing.Drawing2D;
Graphics g;//g画笔
每条折线图是有点组成,对一条折线图也就是点的集合,用points[]存储,如果点想在折线图中反映出来,就要有点的半径Radius,用for循环画点:
g.FillEllipse(new SolidBrush(pointcolor),points[i].X - Radius,points[i].Y - Radius,Radius * 2,Radius * 2);//画点,pointcolor点的颜色,颜色类型为Color
画线:
Pen pen = new Pen(linecolor);//linecolor线的颜色
g.DrawLines(pen, points);//画线,points数组中点要有顺序,按x坐标排序
using System.Drawing;
using System.Drawing.Drawing2D;
Graphics g;//g画笔
每条折线图是有点组成,对一条折线图也就是点的集合,用points[]存储,如果点想在折线图中反映出来,就要有点的半径Radius,用for循环画点:
g.FillEllipse(new SolidBrush(pointcolor),points[i].X - Radius,points[i].Y - Radius,Radius * 2,Radius * 2);//画点,pointcolor点的颜色,颜色类型为Color
画线:
Pen pen = new Pen(linecolor);//linecolor线的颜色
g.DrawLines(pen, points);//画线,points数组中点要有顺序,按x坐标排序
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
可以用GDI+的技术,去分析一下微软的TaskVision,你就是个中高手了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询