All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
多国语言的实现方法在ASP.NET中_[Asp.Net教程]
怎样使用AJAX进行WEB应用程序开发_[AJAX教程]
Visual,Studio,2008,And,.NET,3.5,11月底正式发布_[Asp.Net教程]
ASP.NET十分有用的页面间传值方法_.net资料_编程技术
在PHP的图形函数中显示汉字_php资料_编程技术
PHP中使用crypt()实现用户身份验证_php资料_编程技术
VS2008简体中文版下载(及升级为正式版办法,见截图)_[Asp.Net教程]
C#教程: 控制鼠标操作使用实例
使用ASP.NET,AJAX框架扩展HTML,Map控件_.net资料_编程技术
ADO.NET2.0跟ADO.NET3.0的一些新特性简要介绍_.net资料_编程技术
Reading number is top 10 pictures
So beauty, will let you spray blood7
Born After 90 Beijing sports university campus flower photos4
中国处女图鉴1
支持判处贩卖儿童者死刑
锄禾日了几个人?
人美胸美腿更美4
Terrorist smile the largest human history an explosion1
Summer is most suitable for young people to travel in China9
何炅哥为中国人的平均工资鸣不平了
A beautiful girl to bud3
Download software ranking
Sora aoi, the nurse, uniform ,nursing assistant
Wild things 2
Visual C++界面编程技术
美女游泳记
Boxer's Top ten classic battle8
Unix video tutorial19
Unix video tutorial4
Unix video tutorial1
Tram sex maniac 2 (H) rar bag2
Boxer's Top ten classic battle7
qq published in(发表于) 2014/7/11 9:29:17 Edit(编辑)
GDI+绘制饼图分析男女比例

GDI+绘制饼图分析男女比例

GDI+绘制饼图分析男女比例

绘制饼图分析男女比例

饼图是一种常用来显示数据比例的图表技术,常用来突出某一重要数据。本节将通过一个实例来介绍使用饼图显示公司员工的男女比例情况。实例运行结果如图1所示。

程序开发步骤如下所示。

(1)新建一个Windows应用程序,命名为26_02,其主窗体默认为Form1.cs。

(2)Form1.cs窗体中,添加一个Button控件,用来执行画图操作。

(3)程序主要代码如下。

单击【分析男女比例】按钮,程序调用Graphics对象的FillPie方法,根据数据库中记录,绘制一张体现公司员工男女比例的饼图。【分析男女比例】按钮的Click事件代码如下:

private void button1_Click(object sender, EventArgs e)

{

//连数据库

SqlConnection sqlcon = new SqlConnection("Data Source=(local);Database=db_26;Uid=sa;Pwd=");

string P_str_sel = "select * from tb_02";

SqlDataAdapter myda1 = new SqlDataAdapter(P_str_sel, sqlcon);

DataSet myds1 = new DataSet();

myda1.Fill(myds1);

//计算男、女总和

string P_str_sumNum = "select sum(boyNum+girlNum) as sumNum FROM tb_02";

SqlDataAdapter myda2 = new SqlDataAdapter(P_str_sumNum, sqlcon);

DataSet myds2 = new DataSet();

myda2.Fill(myds2);

int P_int_sum = Convert.ToInt32(myds2.Tables[0].Rows[0][0].ToString());

//获取男员工数目

int P_int_boy = Convert.ToInt32(myds1.Tables[0].Rows[0][0].ToString());

//获取女员工数目

int P_int_girl = Convert.ToInt32(myds1.Tables[0].Rows[0][1].ToString());

Graphics graphics = this.CreateGraphics();

try

{

graphics.Clear(Color.White);

Pen pen1 = new Pen(Color.Red);

Brush brush1 = new SolidBrush(Color.YellowGreen);

Brush brush2 = new SolidBrush(Color.Blue);

Brush brush3 = new SolidBrush(Color.Brown);

Font font1 = new Font("Courier New", 16, FontStyle.Bold);

Font font2 = new Font("Courier New", 8);

graphics.FillRectangle(brush1, 0, 0, 370, 350); //绘制背景

graphics.DrawString("公司员工男女比例分析", font1, brush2, new Point(60, 20)); //书写标题

//男员工在圆中分配的角度

float angle1 = Convert.ToSingle((360 * (Convert.ToSingle(P_int_boy) / Convert.ToSingle(P_int_sum))));

//女员工在圆中分配的角度

float angle2 = Convert.ToSingle((360 * (Convert.ToSingle(P_int_girl) / Convert.ToSingle(P_int_sum))));

graphics.FillPie(brush2, 100, 60, 180, 180, 0, angle1); //绘制男员工所占比例

graphics.FillPie(brush3, 100, 60, 180, 180, angle1, angle2); //绘制女员工所占比例

//绘制标识

graphics.DrawRectangle(pen1, 50, 255, 260, 50); //绘制范围框

graphics.FillRectangle(brush2, 85, 265, 20, 10); //绘制小矩形

graphics.DrawString("男员工占公司总人数比例:" + Convert.ToInt32(P_int_boy) * 100 / Convert.ToInt32 (P_int_sum) + "%", font2, brush2, 120, 265);

graphics.FillRectangle(brush3, 85, 285, 20, 10);

graphics.DrawString("女员工占公司总人数比例:" + Convert.ToInt32(P_int_girl) * 100 / Convert.ToInt32 (P_int_sum) + "%", font2, brush3, 120, 285);

}

catch (Exception ex)

{

MessageBox.Show(ex.Message, "信息", MessageBoxButtons.OK, MessageBoxIcon.Information);

}

graphics.Dispose();

}

完整程序代码如下:

★ ★★★★Form1.cs窗体代码文件完整程序代码★★★★★

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

using System.Drawing.Drawing2D;

using System.Data.SqlClient;

namespace _6_02

{

public partial class Form1 : Form

{

public Form1()

{

InitializeComponent();

}

private void button1_Click(object sender, EventArgs e)

{

//连数据库

SqlConnection sqlcon = new SqlConnection("Data Source=(local);Database=db_26;Uid=sa;Pwd=");

string P_str_sel = "select * from tb_02";

SqlDataAdapter myda1 = new SqlDataAdapter(P_str_sel, sqlcon);

DataSet myds1 = new DataSet();

myda1.Fill(myds1);

//计算男、女总和

string P_str_sumNum = "select sum(boyNum+girlNum) as sumNum FROM tb_02";

SqlDataAdapter myda2 = new SqlDataAdapter(P_str_sumNum, sqlcon);

DataSet myds2 = new DataSet();

myda2.Fill(myds2);

int P_int_sum = Convert.ToInt32(myds2.Tables[0].Rows[0][0].ToString());

//获取男员工数目

int P_int_boy = Convert.ToInt32(myds1.Tables[0].Rows[0][0].ToString());

//获取女员工数目



添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.