Asp.Net实例:C# 绘制统计图(一) ——柱状图
Asp.Net实例:C# 绘制统计图
(柱状图, 折线图, 扇形图)
int height = 500, width = 700;
Bitmap p_w_picpath = new Bitmap(width, height);
Graphics g = Graphics.FromImage(p_w_picpath);
Pen mypen = new Pen(brush, 1);
g.FillRectangle(Brushes.WhiteSmoke, 0, 0, width, height);
for (int i = 0; i < 14; i++)
{
g.DrawLine(mypen, x, 80, x, 340);
x = x + 40;
}
for (int i = 0; i < 9; i++)
{
g.DrawLine(mypen, 60, y, 620, y);
y = y + 26;
}
String[] n = { "第一期", "第二期", "第三期", "第四期", "全年" };
for (int i = 0; i < 7; i++)
{
g.DrawString(n[i].ToString(), font, Brushes.Blue, x, 348);
x = x + 78;
}
String[] m = {"250","225", "200", "175", "150", "125", "100“};
for (int i = 0; i < 10; i++)
{
g.DrawString(m[i].ToString(), font, Brushes.Blue, 25, y);
y = y + 26;
}
7. 定义数组存储数据库中统计的数据
int[] Count1 = new int[7]; //存储从数据库读取的报名人数
int[] Count2 = new int[7]; //存储从数据库读取的通过人数
SqlConnection Con = new SqlConnection(
"Server=(Local);Database=committeeTraining;");
Con.Open();
string cmdtxt2 = "SELECT * FROM ##Count
where Company='" + ****+ "'";
SqlDataAdapter da = new SqlDataAdapter(cmdtxt2, Con);
DataSet ds = new DataSet();
da.Fill(ds);
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());
x = 80;
Font font2 = new System.Drawing.Font(
"Arial", 10, FontStyle.Bold);
SolidBrush mybrush = new SolidBrush(Color.Red);
SolidBrush mybrush2 = new SolidBrush(Color.Green);
绘制柱状图
g.FillRectangle(mybrush, x, 340 - Count1[0], 20, Count1[0]);
g.DrawString(Count1[0].ToString(), font2,
Brushes.Red, x, 340 - Count1[0] - 15);
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);
System.IO.MemoryStream ms = new
System.IO.MemoryStream();
p_w_picpath.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
Response.ClearContent();
Response.ContentType = "p_w_picpath/Jpeg";
Response.BinaryWrite(ms.ToArray());
![](/assets/blank.gif)
private void CreateImage()
{
int height = 500, width = 700;
Bitmap p_w_picpath = new Bitmap(width, height);
//创建Graphics类对象
Graphics g = Graphics.FromImage(p_w_picpath);
{
//清空图片背景色
g.Clear(Color.White);
Font font1 = new Font("宋体", 20, FontStyle.Bold);
Color.Blue, Color.BlueViolet, 1.2f, true);
g.FillRectangle(Brushes.WhiteSmoke, 0, 0, width, height);
// Brush brush1 = new SolidBrush(Color.Blue);
" 成绩统计柱状图", font1, brush, new PointF(70, 30));
//画图片的边框线
g.DrawRectangle(new Pen(Color.Blue), 0, 0, p_w_picpath.Width - 1, p_w_picpath.Height - 1);
Pen mypen = new Pen(brush, 1);
//绘制线条
//绘制横向线条
int x = 100;
for (int i = 0; i < 14; i++)
{
g.DrawLine(mypen, x, 80, x, 340);
x = x + 40;
}
Pen mypen1 = new Pen(Color.Blue, 2);
x = 60;
g.DrawLine(mypen1, x, 80, x, 340);
int y = 106;
for (int i = 0; i < 9; i++)
{
g.DrawLine(mypen, 60, y, 620, y);
y = y + 26;
}
g.DrawLine(mypen1, 60, y, 620, y);
String[] n = { "第一期", "第二期", "第三期", "第四期", "上半年", "下半年", "全年统计" };
x = 78;
for (int i = 0; i < 7; i++)
{
g.DrawString(n[i].ToString(), font, Brushes.Blue, x, 348); //设置文字内容及输出位置
x = x + 78;
}
String[] m = {"250","225", "200", "175", "150", "125", "100", " 75",
" 50", " 25", " 0"};
y = 72;
for (int i = 0; i < 10; i++)
{
g.DrawString(m[i].ToString(), font, Brushes.Blue, 25, y); //设置文字内容及输出位置
y = y + 26;
}
int[] Count2 = new int[7];
Con.Open();
string cmdtxt2 = "SELECT * FROM ##Count where Company='" + this.ddlTaget.SelectedItem.Text.Trim() + "'";
SqlDataAdapter da = new SqlDataAdapter(cmdtxt2, Con);
DataSet ds = new DataSet();
da.Fill(ds);
Count1[1] = Convert.ToInt32(ds.Tables[0].Rows[0]["count3"].ToString());
Count1[2] = Convert.ToInt32(ds.Tables[0].Rows[0]["count5"].ToString());
Count1[3] = Convert.ToInt32(ds.Tables[0].Rows[0]["count7"].ToString());
Count1[5] = Count1[2] + Count1[3];
Count2[0] = Convert.ToInt32(ds.Tables[0].Rows[0]["count2"].ToString());
Count2[1] = Convert.ToInt32(ds.Tables[0].Rows[0]["count4"].ToString());
Count2[2] = Convert.ToInt32(ds.Tables[0].Rows[0]["count6"].ToString());
Count2[3] = Convert.ToInt32(ds.Tables[0].Rows[0]["count8"].ToString());
Count2[5] = Count2[2] + Count2[3];
x = 80;
Font font2 = new System.Drawing.Font("Arial", 10, FontStyle.Bold);
SolidBrush mybrush = new SolidBrush(Color.Red);
SolidBrush mybrush2 = new SolidBrush(Color.Green);
g.FillRectangle(mybrush, x, 340 - Count1[0], 20, Count1[0]);
g.DrawString(Count1[0].ToString(), font2, Brushes.Red, x, 340 - Count1[0] - 15);
g.FillRectangle(mybrush2, x, 340 - Count2[0], 20, Count2[0]);
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);
x = x + 20;
g.FillRectangle(mybrush2, x, 340 - Count2[1], 20, Count2[1]);
g.DrawString(Count2[1].ToString(), font2, Brushes.Green, x, 340 - Count2[1] - 15);
//第三期
x = x + 60;
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);
x = x + 60;
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);
x = x + 60;
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);
x = x + 60;
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);
x = x + 60;
g.FillRectangle(mybrush, x, 340 - Count1[6], 20, Count1[6]);
g.DrawString(Count1[6].ToString(), font2, Brushes.Red, x, 340 - Count1[6] - 15);
x = x + 20;
g.FillRectangle(mybrush2, x, 340 - Count2[6], 20, Count2[6]);
g.DrawString(Count2[6].ToString(), font2, Brushes.Green, x, 340 - Count2[6] - 15);
//绘制标识
Font font3 = new System.Drawing.Font("Arial", 10, FontStyle.Regular);
g.DrawRectangle(new Pen(Brushes.Blue), 170, 400, 250, 50); //绘制范围框
g.FillRectangle(Brushes.Red, 270, 410, 20, 10); //绘制小矩形
g.DrawString("报名人数", font3, Brushes.Red, 292, 408);
g.DrawString("通过人数", font3, Brushes.Green, 292, 428);
p_w_picpath.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
Response.ClearContent();
Response.ContentType = "p_w_picpath/Jpeg";
Response.BinaryWrite(ms.ToArray());
}
finally
{
g.Dispose();
p_w_picpath.Dispose();
}
}
Asp.Net实例:C# 绘制统计图(一) ——柱状图相关推荐
- vb.net 教程 5-12 绘图实例之统计图 1 柱状图
版权声明:本文为博主原创文章,转载请在显著位置标明本文出处以及作者网名,未经作者允许不得用于商业目的. 前面几篇介绍了如何使用graphics绘制图像,这几篇准备介绍如何使用graphics提供的方法 ...
- 数据可视化 | Python绘制多维柱状图:一图展示西部各省人口变迁【附本文数据和代码】
查看原文:[数据seminar]https://mp.weixin.qq.com/s/pvx2ZzLbrBL-6cyOwVATOA Part1前言 柱状图是利用柱子的高度来反映数据差异的统计图,与一维 ...
- C#ASP.NET使用Echarts制作统计图
卓越项目需要所以想要用ASP绘制统计图,但是从来没有接触过echarts和ajax,于是在哔哩哔哩上看了一些简短的课程大致了解了一下echarts和ajax. 前端代码: <%@ Page La ...
- Python使用matplotlib绘制分组对比柱状图(bar plot)可视化时汉语(中文)标签显示成了框框□□、什么情况、我们有解决方案
Python使用matplotlib绘制分组对比柱状图可视化时(bar plot)汉语(中文)标签显示成了框框□□.什么情况.我们有解决方案 目录
- 用g.raphael.js高速绘制饼图、柱状图、点状图、折线图(上)
首先介绍一下什么是g.raphael.这个又要说到什么是raphael.js.raphael是一个javascript库,可以用来跨浏览器绘制各种图形,只要是你想得到的图形都可以用raphael绘制出 ...
- python hist函数_虎哥的python小技巧放送之绘制统计图(2)
先放出第一期让大家回顾一下上次的内容 虎哥的python小技巧放送之绘制统计图(1) 第一期主要给大家讲了一些图形设置的东西.这一次开始正式带大家画图~ 折线图:折线图可以通过matplotlib中的 ...
- c#中chart绘制曲线,柱状图等
通常我们需要在界面中绘制波形图,柱状图,折线图等等.此时用到Chart控件是非常方便的. 先以图一条样条曲线(Spline)为例 (1)在Visual Studio中新建一个"Windows ...
- IOS开发基础之绘制饼图、柱状图、自定义进度条
IOS开发基础之绘制饼图.柱状图.自定义进度条 源码在我的主页里 1.绘制饼图 效果 源码 // LJView.m // 34-绘图饼图 // Created by 鲁军 on 2021/2/23. ...
- matlab rgb三维直方图,MATLAB小技巧之十:利用MATLAB绘制三维彩色柱状图[转载]
MATLAB自带有绘制三维柱状图的函数bar3,有版友反映不好控制柱子的颜色,特别是bar3不能绘制渐变色的柱子,并且bar3不能根据用户指定的散点数据绘制柱状图.为此,我编写了一个函数(scatte ...
最新文章
- Actipro WPF Studio破解
- maven WEB项目启动没问题访问页面就报错:org.apache.jasper.JasperException: Unable to compile class for JSP
- 4、已知圆的半径radius= 1.5,求其面积
- php curl和file get,PHP cURL与file_get_contents
- 硬币找零问题,动态规划基础,百度面试题
- pytorch实现LeNet5
- css里calculate,css3 calc会计算的属性
- Python自定义类中定义属性的两种方式
- 普通的Spring Web项目正常启动,在访问某些JSP页面时,页面会报错 http://java.sun.com/jsp/jstl/core
- 【c++模板实现】二叉查找树
- Windows下 Anaconda + VScode Python 环境搭建 多图 非常详细
- fpcx教程:在Final Cut Pro中添加多语言字幕
- 日期时间编辑器(模拟QDateTimeEdit的自定义控件)——QML
- 【flutter】整合高德地图amap_base
- java有一只兔子 从出生_Java解决题目:有一对兔子,从出生第三个月起每个月都生一对兔子,小兔子长到第三个月后,每个月又生一对兔子。。。...
- RGMII_PHY测试笔记1 基于开发板MiS603-X25
- 基于注解实现SpringMVC的配置文件
- “气球” 的最大数量
- JAVA和MySQL实现公交管理_基于JSP公交管理系统的设计与实现(SSH,MySQL)(含录像)
- 【渝粤教育】电大中专计算机职业素养 (14)作业 题库
热门文章
- 【正点原子STM32连载】第五十九章 USB U盘(Host)实验 摘自【正点原子】MiniPro STM32H750 开发指南_V1.1
- 使用ES对一段中文进行分词
- VMware16安装Centos8配置
- 我国典型电子垃圾拆解地持久性有毒化学污染物污染现状
- 数据库、数据库可视化软件的区别
- 登鹳雀楼(网页设计代码)
- Intel sgx里实现Pairing(双线性映射)
- matlab编程反演S参数求电磁参数,如何通过CST仿真出来的S参数获得SRR结构的等效电磁参数...
- Python selenium 拉钩爬虫
- 易用性测试及GUI常见的测试要求