最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

asp.net中生成餅狀與柱狀圖實(shí)例

 更新時間:2014年11月12日 09:33:33   投稿:shichen2014  
這篇文章主要介紹了asp.net中生成餅狀與柱狀圖的方法,以實(shí)例形式較為詳細(xì)的講述了生成餅狀與柱狀圖的原理與具體代碼,包括前后臺的實(shí)現(xiàn)代碼,需要的朋友可以參考下

本文實(shí)例講述了asp.net中生成餅狀與柱狀圖的實(shí)現(xiàn)方法。分享給大家供大家參考。具體方法如下:

一、生成圖形的公共方法:

復(fù)制代碼 代碼如下:
using System;
using System.Collections.Generic;
using System.Text;
//
//using System.Data;
//using System.Web.UI.WebControls;
//
using System.Drawing;
using System.Drawing.Imaging;
 
namespace Tools
{
    public static class OWCImageHelp
    {
        /// <summary>
        /// 動態(tài)的生成柱狀圖和餅狀圖
        /// </summary>
        /// <param name="arrValueNames">行坐標(biāo)要顯示的字段</param>
        /// <param name="arrValues">縱坐標(biāo)要顯示的數(shù)字</param>
        /// <param name="title">標(biāo)題</param>
        public static void GetZBImage(string[] arrValueNames, int[] arrValues, string title)
        {
            Bitmap objBitMap = new Bitmap(650, 300);
            Graphics objGraphics;
            objGraphics = Graphics.FromImage(objBitMap);
            objGraphics.Clear(Color.White);
            //int[] arrValues = { 40000, 32000, 24000, 30000, 36000, 28000 };
            //string[] arrValueNames = new string[] { "第一次", "第二次", "第三次", "第四次", "第五次", "第六次" };
            objGraphics.DrawString(title, new System.Drawing.Font("宋體", 16), Brushes.Blue, new PointF(5, 5));
            PointF symbolLeg = new PointF(335, 20);
            PointF descLeg = new PointF(360, 16);
            //畫出說明部分的圖形
            for (int i = 0; i < arrValueNames.Length; i++)
            {
                objGraphics.FillRectangle(new SolidBrush(GetColor(i)), symbolLeg.X, symbolLeg.Y, 20, 10);
                objGraphics.DrawRectangle(Pens.Black, symbolLeg.X, symbolLeg.Y, 20, 10);
                objGraphics.DrawString(arrValueNames[i].ToString(), new System.Drawing.Font("宋體", 10), Brushes.Black, descLeg);
                symbolLeg.Y += 15;
                descLeg.Y += 15;
            }
            float TotalValues = 0;
            for (int i = 0; i <= arrValues.Length - 1; i++)
            {
                TotalValues += arrValues[i];
            }
            //繪出矩形圖。
            float Rectangleheight = 0;
            PointF recLeg = new PointF(12, 200 - arrValues[0] / TotalValues * 300);
            for (int i = 0; i < arrValues.Length; i++)
            {
                Rectangleheight = arrValues[i] / TotalValues * 300;
                objGraphics.FillRectangle(new SolidBrush(GetColor(i)), (i * 35) + 15, 200 - Rectangleheight, 20, Rectangleheight + 50);
                objGraphics.DrawRectangle(Pens.Black, (i * 35) + 15, 200 - Rectangleheight, 20, Rectangleheight + 50);
                recLeg.Y = 200 - Rectangleheight - 14;
                objGraphics.DrawString(arrValues[i].ToString(), new System.Drawing.Font("宋體", 10), Brushes.Blue, recLeg);
                recLeg.X += 35;
            }
            //繪出圓形圖。
            float sglCurrentAngle = 0;
            float sglTotalAngle = 0;
            for (int i = 0; i < arrValues.Length; i++)
            {
                sglCurrentAngle = arrValues[i] / TotalValues * 360;
                objGraphics.FillPie(new SolidBrush(GetColor(i)), 220, 95, 100, 100, sglTotalAngle, sglCurrentAngle);
                objGraphics.DrawPie(Pens.Black, 220, 95, 100, 100, sglTotalAngle, sglCurrentAngle);
                sglTotalAngle += sglCurrentAngle;
            }
            objBitMap.Save(System.Web.HttpContext.Current.Response.OutputStream, ImageFormat.Gif);
        }
        //定義顏色。
        private static Color GetColor(int itemIndex)
        {
            Color objColor;
            if (itemIndex == 0)
            {
                objColor = Color.Maroon;
            }
            else if (itemIndex == 1)
            {
                objColor = Color.Red;
            }
            else if (itemIndex == 2)
            {
                objColor = Color.Gray;
            }
            else if (itemIndex == 3)
            {
                objColor = Color.Blue;
            }
            else if (itemIndex == 4)
            {
                objColor = Color.Orange;
            }
            else if (itemIndex == 5)
            {
                objColor = Color.Cyan;
            }
            else if (itemIndex == 6)
            {
                objColor = Color.Bisque;
            }
            else if (itemIndex == 7)
            {
                objColor = Color.Maroon;
            }
            else if (itemIndex == 8)
            {
                objColor = Color.Maroon;
            }
            else
            {
                objColor = Color.Blue;
            }
            return objColor;
        }
    }
}

二、新建生成餅狀柱狀圖頁面BZImage.aspx:
后臺:
復(fù)制代碼 代碼如下:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using BLL;
using Models;
public partial class GridViewDemo_BZImage : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        GetBZIamge();
    }
    /// <summary>
    /// 生成餅狀柱狀圖
    /// </summary>
    public void GetBZIamge()
    {
        DataTable dt = BLL.StudentBLL.SelAllStudent();
        string[] rows = new string[dt.Rows.Count];
        int[] columns = new int[dt.Rows.Count];
        for (int i = 0; i < dt.Rows.Count; i++)
        {
            rows[i] = dt.Rows[i]["學(xué)生姓名"].ToString();
            columns[i] = Convert.ToInt32(dt.Rows[i]["薪金"].ToString());
        }
        Tools.OWCImageHelp.GetZBImage(rows, columns, "學(xué)生薪水查詢");
    }
}

三、顯示餅狀柱狀圖的頁面:
前臺:
復(fù)制代碼 代碼如下:
<table style="width: 600px" onMouseOver="over()" onMouseOut="out()">
            <tr>
             <td style="height: 21px; width: 35px;" align="center">
                    <img id="BZImage" src="BZImage.aspx" alt=""/>
                </td>
            </tr>
</table>

希望本文所述對大家的asp.net程序設(shè)計有所幫助。

相關(guān)文章

最新評論

兴和县| 宜丰县| 宜昌市| 托克逊县| 东港市| 香河县| 鸡泽县| 彭阳县| 城口县| 高平市| 双柏县| 保山市| 兰考县| 布尔津县| 乐业县| 且末县| 贺州市| 大安市| 集安市| 莆田市| 新竹县| 宁化县| 南阳市| 仁化县| 抚远县| 肃宁县| 大同市| 永济市| 唐海县| 新宁县| 新蔡县| 云安县| 阿拉善右旗| 千阳县| 田东县| 太仆寺旗| 藁城市| 安丘市| 扶风县| 和平区| 汤阴县|