C#如何实现在窗体上的统计图(云服务器、云主机、高防IP、高防服务器、香港服务器、美国服务器,开发技术)

时间:2024-05-02 06:13:43 作者 : 石家庄SEO 分类 : 开发技术
  • TAG :

具体内容如下

忽然要用到C#来制作统计图,起初不太清除怎么弄,看了一些代码实现统计图的文档。终于实现了条形图的设置,后来又需要饼状图。本来还是想自己画的后来才发现C#是有这种窗体控件的,控件画比我强太多了。

这是我自己做的条形图的函数:

publicstaticintwidth=400,height=400;//声明宽与高Bitmapbitmap=newBitmap(width,height);//创建一个绘图对象//这四个参数分别是表的列名,tp1,tp2,tp3均是条形的长,s1,s2,s3代表每个条形的数据publicvoidcreateImage(strings,inttp1,inttp2,inttp3,strings1,strings2,strings3){Graphicsg=Graphics.FromImage(bitmap);g.FillRectangle(Brushes.Black,0,0,400,400);//边框try{g.Clear(Color.White);//创建6个brush,用于填充颜色Brushbrush2=newSolidBrush(Color.White);Brushbrush3=newSolidBrush(Color.Black);Brushbrush4=newSolidBrush(Color.Red);Brushbrush5=newSolidBrush(Color.Green);Brushbrush6=newSolidBrush(Color.Orange);Brushbrush7=newSolidBrush(Color.DarkBlue);//创建两个Font对象,用于设置字体Fontfont1=newFont("宋体",16,FontStyle.Bold);Fontfont2=newFont("CourierNew",8);g.FillRectangle(brush2,0,0,width,height);//绘制背景图g.DrawString(s,font1,brush3,newPoint(90,20));//绘制标题Pointp1=newPoint(30,300);Pointp2=newPoint(330,300);//这里用到的减式是由于画布的坐标系和数学中的坐标系不同,参考下面的图g.DrawString(s1,font2,brush3,newPoint(90,285-(tp1*10)));g.DrawString(s2,font2,brush3,newPoint(150,285-(tp2*10)));g.DrawString(s2,font2,brush3,newPoint(210,285-(tp3*10)));g.FillRectangle(brush4,90,300-(tp1*10),50,tp1*10);//g.FillRectangle(brush5,150,300-(tp2*10),50,tp2*10);//g.FillRectangle(brush6,210,300-(tp3*10),50,tp3*10);g.DrawLine(newPen(Color.Black),p1,p2);//绘制一条直线pictureBox1.Image=bitmap;}catch(Exception){throw;}}

画布中的坐标系:

C#如何实现在窗体上的统计图

如果换成C#中的chart控件来做就简单多了

1.找到控件的Legends属性把其中的Enabled改成False。
2.找到控件的Series属性把其中的ChartType改成你需要的表形式。
3.接下就是为chart控件添加数据。

添加数据的方式之一:

string[]xData={"经理","总监","销售"};int[]yData={10,20,30};chart1.Series[0]["PieLabelStyle"]="Outside";//将文字移到外侧chart1.Series[0]["PieLineColor"]="Black";//绘制黑色的连线。chart1.Series[0].Points.DataBindXY(xData,yData);
 </div> <div class="zixun-tj-product adv-bottom"></div> </div> </div> <div class="prve-next-news">
本文:C#如何实现在窗体上的统计图的详细内容,希望对您有所帮助,信息来源于网络。
上一篇:Python的if else语句实例分析下一篇:

4 人围观 / 0 条评论 ↓快速评论↓

(必须)

(必须,保密)

阿狸1 阿狸2 阿狸3 阿狸4 阿狸5 阿狸6 阿狸7 阿狸8 阿狸9 阿狸10 阿狸11 阿狸12 阿狸13 阿狸14 阿狸15 阿狸16 阿狸17 阿狸18