using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms; using System.Data.SqlClient;
using System.Drawing.Drawing2D;
namespace MyFillPie
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} SqlConnection conn; //声明一个connection变量 private void Form1_Paint(object sender, PaintEventArgs e)
{
//连接SQLserver数据库
conn = new SqlConnection("server=.;database=AssetSys;uid=sa;pwd=sa");
conn.Open();
string str2 = string.Format("select SUM(tp) from tb_vote");
SqlCommand cmd=new SqlCommand (str2,conn);
int sum = Convert.ToInt32(cmd.ExecuteScalar());
SqlDataAdapter sda = new SqlDataAdapter("select * from tb_vote",conn);
DataSet ds = new DataSet();
sda.Fill(ds); int man20and25 = Convert.ToInt32(ds.Tables[].Rows[][].ToString());
int man26and30 = Convert.ToInt32(ds.Tables[].Rows[][].ToString());
int man31and40 = Convert.ToInt32(ds.Tables[].Rows[][].ToString());
int width = , height = ;
Bitmap bitmap = new Bitmap(width, height);
Graphics g = Graphics.FromImage(bitmap); try
{
g.Clear(Color.White); //使用Clear方法使画布变成白色
Pen pen = new Pen(Color.Red);
//创建4个Brush对象,用于填充颜色
Brush brush1 = new SolidBrush(Color.PowderBlue);
Brush brush2 = new SolidBrush(Color.Blue);
Brush brush3 = new SolidBrush(Color.Wheat);
Brush brush4 = new SolidBrush(Color.Orange);
Font f1 = new Font("Courier New", , FontStyle.Bold);
Font f2 = new Font("Courier New", ); g.FillRectangle(brush1, , , width, height); //绘制背景图
g.DrawString("点赞比例", f1, brush2, new Point(, )); //绘制标题 int piex = , piey = , piew = , pieh = ; float age1 = Convert.ToSingle((/Convert.ToSingle(sum))*man20and25);
float age2 = Convert.ToSingle(( / Convert.ToSingle(sum)) * man26and30);
float age3 = Convert.ToSingle(( / Convert.ToSingle(sum)) * man31and40);
g.FillPie(brush2,piex,piey,piew,pieh,,age1);
g.FillPie(brush3, piex, piey, piew, pieh, age1,age2);
g.FillPie(brush4, piex, piey, piew, pieh, age1+age2,age3); g.DrawRectangle(pen,,,,);
g.FillRectangle(brush2,,,,);
g.DrawString("点赞比例1:" + Convert.ToSingle(man20and25) * / sum + "%", f2, brush2, , );
g.FillRectangle(brush3, , , , );
g.DrawString("点赞比例2:" + Convert.ToSingle(man26and30) * / sum + "%", f2, brush2, , );
g.FillRectangle(brush4, , , , );
g.DrawString("点赞比例3:" + Convert.ToSingle(man31and40) * / sum + "%", f2, brush2, , );
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
pictureBox1.Image = bitmap;
}
}
}

T-SQL:

USE [AssetSys]
GO /****** Object: Table [dbo].[tb_vote] Script Date: 2018/10/27 9:12:00 ******/
SET ANSI_NULLS ON
GO SET QUOTED_IDENTIFIER ON
GO CREATE TABLE [dbo].[tb_vote](
[Id] [int] IDENTITY(1,1) NOT NULL,
[Name] [nvarchar](50) NOT NULL,
[TP] [int] NOT NULL,
[CreateTime] [datetime] NOT NULL,
[Remake] [nvarchar](50) NOT NULL,
[State] [int] NOT NULL,
[Sort] [int] NOT NULL,
CONSTRAINT [PK_tb_vote] PRIMARY KEY CLUSTERED
(
[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] GO ALTER TABLE [dbo].[tb_vote] ADD CONSTRAINT [DF_tb_vote_CreateTime] DEFAULT (getdate()) FOR [CreateTime]
GO

  

WinFrom饼形图的更多相关文章

  1. winfrom 隐藏任务栏(win7)

    1:新建winfrom 窗体应用程序 2:拖入contextMenuStrip.notifyIcon 2个控件 3:如图 4:code: 注意:复制控件事件要注册 using System; usin ...

  2. winfrom 文字滚动

    winfrom 文字滚动 http://www.codeproject.com/Articles/6913/Creating-a-professional-looking-GDI-drawn-cust ...

  3. Web API应用架构在Winform混合框架中的应用(3)--Winfrom界面调用WebAPI的过程分解

    最近一直在整合WebAPI.Winform界面.手机短信.微信公众号.企业号等功能,希望把它构建成一个大的应用平台,把我所有的产品线完美连接起来,同时也在探索.攻克更多的技术问题,并抽空写写博客,把相 ...

  4. C# Winfrom 页面传值

    2个窗体 Parent,Children 代码: Parent public partial class Parent : Form { public string parentValue = &qu ...

  5. WinFrom 登录窗体 密码保存效果

    WinFrom 登录窗体 保存密码效果 开发CS程序的程序员都会遇到 今天突然想把这个功能加到我的项目中 之后总结下 不多说 上图   如果关闭程序 下次在登录的时候 用户名.密码会自动保留下来  一 ...

  6. BackgroundWorker实现的winfrom中实现异步等待加载图片显示

    BackgroundWorker简介    BackgroundWorker在winfrom中有对应控件,该有三个事件:DoWork .ProgressChanged 和 RunWorkerCompl ...

  7. Winfrom中ListBox绑定List数据源更新问题

    Winfrom中ListBox绑定List数据源更新问题 摘自:http://xiaocai.info/2010/09/winform-listbox-datasource-update/ Winfr ...

  8. 笔记6:winfrom连接sql server 进行数据交换

    今天的作业是用winfrom窗体做一个留言板,如图: 要求和数据库有查询和添加功能.下拉框里的值是直接获取数据库中的值 一.连接数据库,获取表中数据 //创建一个存数据的表 DataTable tab ...

  9. ***百度统计图表Echarts的php实现类,支持柱形图、线形图、饼形图

    /** * 百度数据统计图表echart的PHP实现类 * * 原作者: * @author: chenliujin <liujin.chen@qq.com> * @since 2013- ...

随机推荐

  1. [Objective-C语言教程]结构体(17)

    Objective-C数组可定义包含多个相同类型的数据项的变量类型,但结构体是Objective-C编程中的另一个用户定义数据类型,它可组合不同类型的数据项. 结构体用于表示记录,假设要图书馆中跟踪书 ...

  2. 关于字典的几个类--defaultdict,OrderedDict, zip()

    一.  1个键对应多个值 比如:d = {'a' : [1, 2, 3],  'b' : [4, 5]},可以使用 collections 模块中的 defaultdict 来构造这样的字典 from ...

  3. eclipse左边的项目栏消失的处理方法

    window —–> Show View —–> other —–> package Explorer

  4. python3.6.4没有raw_input

    之前是一直在用Python2.7版本,2.7里面raw_input()和input个人认为区别在于raw_input()可以输入字符串和中文,而input()只接受数字,输入字符串就会报错. 现在用的 ...

  5. [DPF] DB2 DPF 搭建实战

    1. Server 准备 2. NFS 系统设置 3. 创建实例 4. rsh/ssh 5. 测试 Server: 192.168.122.1  dpf01.dpf.com  dpf01 192.16 ...

  6. hibernate的反向生成改懒加载的地方

    改变懒加载只需要把生成的文件中的获取类型改为eager fetch = FetchType.EAGER @ManyToOne(fetch = FetchType.EAGER)//把懒加载换成饿加载模式 ...

  7. nginx: [alert] kill(3475, 15) failed (3: No such process) 解决方案

    cd nginx安装目录下/conf/nginx.conf 查看pid文件存放路径  (如果自己知道就不用执行上面这一步) 然后删除这个nginx.pid文件 然后再次杀掉nginx进程 搞定

  8. PHP 对目录下所有TXT进行遍历 并正则进行处理 preg_replace

    <?php set_time_limit(); //遍历 指定目录下的所有 文件/ $pattern是要匹配的 文件规则 function file_list($dir,$pattern=&qu ...

  9. 17.Generator函数的异步应用

    异步编程对 JavaScript 语言太重要.Javascript 语言的执行环境是“单线程”的,如果没有异步编程,根本没法用,非卡死不可. 1.传统方法 ES6 诞生以前,异步编程的方法,大概有下面 ...

  10. 《LeetBook》leetcode题解(14):Longest Common Prefix[E]

    我现在在做一个叫<leetbook>的免费开源书项目,力求提供最易懂的中文思路,目前把解题思路都同步更新到gitbook上了,需要的同学可以去看看 书的地址:https://hk029.g ...