我们经常在项目中遇到,许多的数据为了真观的体现给用户,不得不引和饼图,趋势图,等等柱状图来开形象的来呈现数据,如果在不使用第三方控件的情况下,我们都知道路在winform程序中是非常容易实现的,如是webform的实现就有点麻烦。本程序是在webform上放Image控件,加上.ashx一般处理文件实现的,原理为将Image的rsc属性转到xxxxx.ashx文件处,xxxxx.ashx文件反加一张已经画好的图片,在调用xxxxx.ashx文件时可以传递参数,如用户信息,根据用户ID生成各用户相将要使用的图:
(1)饼图:
bintu.ashx文件的内容如下:
using System;
using System.Collections;
using System.Data;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.IO;
namespace WebApplication3
{
/// <summary>
/// $codebehindclassname$ 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class getSourceImage : IHttpHandler
{
private long TotalSalary;
public void ProcessRequest(HttpContext context)
{
const int PieHeight = 500;
const int PIeWidth = 520;
Bitmap objBitmap = new Bitmap(PIeWidth, PieHeight);
Graphics objGraphics = Graphics.FromImage(objBitmap);
objGraphics.SmoothingMode = SmoothingMode.AntiAlias;
objGraphics.FillRectangle(new SolidBrush(Color.YellowGreen), 0, 0, PIeWidth, PieHeight);
int iLoop2;
// 定义位置与椭圆的大小。
int x = 20;
int y = 20;
int width = 300;
int height = 150;
Rectangle DepartmentLegend;
int DepartmentLegend_Y = 40;
// 初始化起点的角度与每块饼的扫过角度。
int startAngle = 0;
int sweepAngle = 45;