C# 绘制统计图柱状图 折线图 扇形图文档格式.docx
- 文档编号:21869830
- 上传时间:2023-02-01
- 格式:DOCX
- 页数:17
- 大小:557.69KB
C# 绘制统计图柱状图 折线图 扇形图文档格式.docx
《C# 绘制统计图柱状图 折线图 扇形图文档格式.docx》由会员分享,可在线阅读,更多相关《C# 绘制统计图柱状图 折线图 扇形图文档格式.docx(17页珍藏版)》请在冰豆网上搜索。
}
4.绘制纵向坐标线
9;
g.DrawLine(mypen,60,y,620,y);
y=y+26;
5.绘制横坐标值
String[]n={"
第一期"
"
第二期"
第三期"
第四期"
全年"
};
7;
g.DrawString(n[i].ToString(),font,Brushes.Blue,x,348);
x=x+78;
6.绘制纵坐标值
String[]m={"
250"
225"
200"
175"
150"
125"
100“};
10;
g.DrawString(m[i].ToString(),font,Brushes.Blue,25,y);
7.定义数组存储数据库中统计的数据
int[]Count1=newint[7];
//存储从数据库读取的报名人数
int[]Count2=newint[7];
//存储从数据库读取的通过人数
8.从数据库中读取报名人数与通过人数
SqlConnectionCon=newSqlConnection(
"
Server=(Local);
Database=committeeTraining;
);
Con.Open();
stringcmdtxt2="
SELECT*FROM##Count
whereCompany='
+****+"
'
;
SqlDataAdapterda=newSqlDataAdapter(cmdtxt2,Con);
DataSetds=newDataSet();
da.Fill(ds);
9.将读取的数据存储到数组中
Count1[0]=Convert.ToInt32(ds.Tables[0].Rows[0][“count1”].ToString());
Count1[1]=Convert.ToInt32(ds.Tables[0].Rows[0][“count3”].ToString());
Count2[0]=Convert.ToInt32(ds.Tables[0].Rows[0][“count2”].ToString());
Count2[1]=Convert.ToInt32(ds.Tables[0].Rows[0]["
count4"
].ToString());
10.定义画笔和画刷准备绘图
x=80;
Fontfont2=newSystem.Drawing.Font(
Arial"
10,FontStyle.Bold);
SolidBrushmybrush=newSolidBrush(Color.Red);
SolidBrushmybrush2=newSolidBrush(Color.Green);
11.根据数组中的值绘制柱状图
(1)第一期报名人数
g.FillRectangle(mybrush,x,340-Count1[0],20,Count1[0]);
g.DrawString(Count1[0].ToString(),font2,
Brushes.Red,x,340-Count1[0]-15);
(2)第一期通过人数
x=x+20;
g.FillRectangle(mybrush2,x,340-Count2[0],20,Count2[0]);
g.DrawString(Count2[0].ToString(),font2,
Brushes.Green,x,340-Count2[0]-15);
12.将图形输出到页面.
System.IO.MemoryStreamms=new
System.IO.MemoryStream();
image.Save(ms,System.Drawing.Imaging.ImageFormat.Jpeg);
Response.ClearContent();
Response.ContentType="
image/Jpeg"
Response.BinaryWrite(ms.ToArray());
最终柱状图的效果图:
柱状图的完整代码:
privatevoidCreateImage()
{
//创建Graphics类对象
try
//清空图片背景色
g.Clear(Color.White);
Fontfont=newFont("
10,FontStyle.Regular);
Fontfont1=newFont("
宋体"
20,FontStyle.Bold);
LinearGradientBrushbrush=newLinearGradientBrush(newRectangle(0,0,image.Width,image.Height),
Color.Blue,Color.BlueViolet,1.2f,true);
//Brushbrush1=newSolidBrush(Color.Blue);
g.DrawString(this.ddlTaget.SelectedItem.Text+"
"
+this.ddlYear.SelectedItem.Text+
成绩统计柱状图"
font1,brush,newPointF(70,30));
//画图片的边框线
g.DrawRectangle(newPen(Color.Blue),0,0,image.Width-1,image.Height-1);
//绘制线条
//绘制横向线条
intx=100;
Penmypen1=newPen(Color.Blue,2);
x=60;
g.DrawLine(mypen1,x,80,x,340);
//绘制纵向线条
inty=106;
g.DrawLine(mypen1,60,y,620,y);
//x轴
上半年"
下半年"
全年统计"
x=78;
//设置文字内容及输出位置
x=x+78;
//y轴
100"
75"
50"
25"
0"
};
y=72;
SqlConnectionCon=newSqlConnection("
Uid=sa;
Pwd=**"
SELECT*FROM##CountwhereCompany='
+this.ddlTaget.SelectedItem.Text.Trim()+"
Count1[0]=Convert.ToInt32(ds.Tables[0].Rows[0]["
count1"
Count1[1]=Convert.ToInt32(ds.Tables[0].Rows[0]["
count3"
Count1[2]=Convert.ToInt32(ds.Tables[0].Rows[0]["
count5"
Count1[3]=Convert.ToInt32(ds.Tables[0].Rows[0]["
count7"
Count1[4]=Count1[0]+Count1[1];
Count1[5]=Count1[2]+Count1[3];
Count1[6]=Convert.ToInt32(ds.Tables[0].Rows[0]["
count9"
Count2[0]=Convert.ToInt32(ds.Tables[0].Rows[0]["
count2"
Count2[1]=Convert.ToInt32(ds.Tables[0].Rows[0]["
Count2[2]=Convert.ToInt32(ds.Tables[0].Rows[0]["
count6"
Count2[3]=Convert.ToInt32(ds.Tables[0].Rows[0]["
count8"
Count2[4]=Count2[0]+Count2[1];
Count2[5]=Count2[2]+Count2[3];
Count2[6]=Convert.ToInt32(ds.Tables[0].Rows[0]["
count10"
//绘制柱状图.
Fontfont2=newSystem.Drawing.Font("
//第一期
g.DrawString(Count1[0].ToString(),font2,Brushes.Red,x,340-Count1[0]-15);
g.DrawString(Count2[0].ToString(),font2,Brushes.Green,x,340-Count2[0]-15);
//第二期
x=x+60;
g.FillRectangle(mybrush,x,340-Count1[1],20,Count1[1]);
g.DrawString(Count1[1].ToString(),font2,Brushes.Red,x,340-Count1[1]-15);
g.FillRectangle(mybrush2,x,340-Count2[1],20,Count2[1]);
g.DrawString(Count2[1].ToString(),font2,Brushes.Green,x,340-Count2[1]-15);
//第三期
g.FillRectangle(mybrush,x,340-Count1[2],20,Count1[2]);
g.DrawString(Count1[2].ToString(),font2,Brushes.Red,x,340-Count1[2]-15);
g.FillRectangle(mybrush2,x,340-Count2[2],20,Count2[2]);
g.DrawString(Count2[2].ToString(),font2,Brushes.Green,x,340-Count2[2]-15);
//第四期
g.FillRectangle(mybrush,x,340-Count1[3],20,Count1[3]);
g.DrawString(Count1[3].ToString(),font2,Brushes.Red,x,340-Count1[3]-15);
g.FillRectangle(mybrush2,x,340-Count2[3],20,Count2[3]);
g.DrawString(Count2[3].ToString(),font2,Brushes.Green,x,340-Count2[3]-15);
//上半年
g.FillRectangle(mybrush,x,340-Count1[4],20,Count1[4]);
g.DrawString(Count1[4].ToString(),font2,Brushes.Red,x,340-Count1[4]-15);
g.FillRectangle(mybrush2,x,340-Count2[4],20,Count2[4]);
g.DrawString(Count2[4].ToString(),font2,Brushes.Green,x,340-Count2[4]-15);
//下半年
g.FillRectangle(mybrush,x,340-Count1[5],20,Count1[5]);
g.DrawString(Count1[5].ToString(),font2,Brushes.Red,x,340-Count1[5]-15);
g.FillRectangle(mybrush2,x,340-Count2[5],20,Count2[5]);
g.DrawString(Count2[5].ToString(),font2,Brushes.Green,x,340-Count2[5]-15);
//全年
g.FillRectangle(mybrush,x,340-Count1[6],20,Count1[6]);
g.DrawString(Count1[6].ToString(),font2,Brushes.Red,x,340-Count1[6]-15);
g.FillRectangle(mybrush2,x,340-Count2[6],20,Count2[6]);
g.DrawString(Count2[6].ToString(),font2,Brushes.Green,x,340-Count2[6]-15);
//绘制标识
Fontfont3=newSystem.Drawing.Font("
g.DrawRectangle(newPen(Brushes.Blue),170,400,250,50);
//绘制范围框
g.FillRectangle(Brushes.Red,270,410,20,10);
//绘制小矩形
g.DrawString("
报名人数"
font3,Brushes.Red,292,408);
g.FillRectangle(Brushes.Green,270,430,20,10);
通过人数"
font3,Brushes.Green,292,428);
System.IO.MemoryStreamms=newSystem.IO.MemoryStream();
finally
g.Dispose();
image.Dispose();
二.折线统计图的绘制
效果:
折线图的完整代码:
intheight=480,width=700;
Fontfont=newSystem.Drawing.Font("
9,FontStyle.Regular);
Fontfont1=newSystem.Drawing.Font("
20,FontStyle.Regular);
8,FontStyle.Regular);
LinearGradientBrushbrush=newLinearGradientBrush(
newRectangle(0,0,image.Width,image.Height),Color.Blue,Color.Blue,1.2f,true);
g.FillRectangle(Brushes.AliceBlue,0,0,width,height);
Brushbrush1=newSolidBrush(Color.Blue);
Brushbrush2=newSolidBrush(Color.SaddleBrown);
成绩统计折线图"
font1,brush1,newPointF(85,30));
Penmypen2=newPen(Color.Red,2);
intx=60;
8;
x=x+80;
Penmypen1=newPen(Color.Blue,3);
g.DrawLine(mypen1,x,82,x,340);
//y=106;
g.DrawLine(mypen1,60,y-26,620,y-26);
x=45;
for(int
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- C# 绘制统计图柱状图 折线图 扇形图 绘制 统计图 柱状图 折线 扇形