统计图形种类繁多,有柱状图,折线图,扇形图等等,而统计图形的绘制方法也有很多,有Flash制作的统计图形,有水晶报表生成统计图形,有专门制图软件制作,也有编程语言自己制作的;这里我们用就C#制作三款最经典的统计图:柱状图,折线图和扇形图;既然是统计,当然需要数据,这里演示的数据存于SqlServer2000中,,:需求不一样,统计图形绘制后的显示效果也不一样,比如这里柱状图的主要需求是为了比较每一期报名人数与通过人数的差,:=500,width=700;Bitmapimage=newBitmap(width,height);Graphicsg=(image);Penmypen=newPen(brush,1);(,0,0,width,height);(inti=0;i<14;i++){(mypen,x,80,x,340);x=x+40;}(inti=0;i<9;i++){(mypen,60,y,620,y);y=y+26;}[]n={"第一期","第二期","第三期","第四期","全年"};for(inti=0;i<7;i++){(n[i].ToString(),font,,x,348);x=x+78;}[]m={"250","225","200","175","150","125","100“};for(inti=0;i<10;i++){(m[i].ToString(),font,,25,y);y=y+26;}[]Count1=newint[7];//存储从数据库读取的报名人数int[]Count2=newint[7];//=newSqlConnection("Server=(Local);mitteeTraining;");();stringcmdtxt2="SELECT*FROM##pany='"+****+"'";SqlDataAdapterda=newSqlDataAdapter(cmdtxt2,Con);DataSetds=newDataSet();(ds);[0]=([0].Rows[0][“count1”].ToString());Count1[1]=([0].Rows[0][“count3”].ToString());Count2[0]=([0].Rows[0][“count2”].ToString());Count2[1]=([0].Rows[0]["count4"].ToString());=80;Fontfont2=("Arial",10,);SolidBrushmybrush=newSolidBrush();SolidBrushmybrush2=newSolidBrush();(1)(mybrush,x,340-Count1[0],20,Count1[0]);(Count1[0].ToString(),font2,,x,340-Count1[0]-15);(2)第一期通过人数x=x+20;(mybrush2,x,340-Count2[0],20,Count2[0]);(Count2[0].ToString(),font2,,x,340-Count2[0]-15);
C#绘制统计图(柱状图 来自淘豆网www.taodocs.com转载请标明出处.