国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

ASP.Net生成業(yè)務數(shù)據(jù)的統(tǒng)計圖形

2024-07-10 12:55:05
字體:
來源:轉載
供稿:網(wǎng)友
    在使用excel處理報表時候,往往要利用系統(tǒng)帶的圖表工具生成比例示意圖,不僅直觀,又顯專業(yè)。當然,在web應用程序中,也可以使用office web components 功能,但是卻很復雜。在.net框架下,通過簡單的編程,就可以輕松地做出地道的比例示意圖。在使用gdi+作圖的時候,除了要熟練應用.net提供的類外,還要從整體上把握圖形生成的坐標。在gdi+里,最左上角的坐標為(0,0),最右下角的做標值最大。

  本節(jié)我們將通過gid+繪制圖形。便于實例模擬,我們采用數(shù)組數(shù)據(jù)來模擬公司業(yè)務數(shù)據(jù)。

  新建一個web窗體,命名為gdi_sample2.aspx,邏輯代碼如下:

  '-----code begin-----

  imports system.drawing

  imports system.drawing.bitmap

  imports system.drawing.graphics

  imports system.drawing.imaging

  public class gdi_sample4

  inherits system.web.ui.page

  #region " web 窗體設計器生成的代碼 "

  '此處省略窗體設計器生成的代碼

  #end region

  '定義公共數(shù)組變量,用來存放模擬公司銷售額數(shù)據(jù)

  public data(5, 1) as string

  private sub page_load(byval sender as system.object, byval e as system.eventargs) handles mybase.load

  '在此處放置初始化頁的用戶代碼

  dim i as int16

  dim objbitmap as bitmap

  objbitmap = new bitmap(400, 300)

  '聲明graphics對象

  dim objgraphics as graphics

  '指定畫布

  objgraphics = graphics.fromimage(objbitmap)

  '設置背景色為白色

  objgraphics.clear(color.white)

  '畫出圖形邊框,注意留出劃線的空間,為一個象素

  objgraphics.drawrectangle(pens.black, 1, 1, 398, 298)

  '生成表頭文字

  objgraphics.drawstring("本公司上半年營業(yè)額統(tǒng)計圖", new font("宋體", 16, fontstyle.bold), brushes.black, new pointf(60, 5))

  '獲取模擬數(shù)據(jù)

  getdata()

  dim monthcolor as pointf = new pointf(260, 40)

  dim fontinfor as pointf = new pointf(285, 36)

  '畫出示意顏色圖例

  for i = 0 to 5

  '畫出填充矩形。

  objgraphics.fillrectangle(new solidbrush(getcolor(i)), monthcolor.x, monthcolor.y, 20, 10)

  '畫出矩形邊框。

  objgraphics.drawrectangle(pens.black, monthcolor.x, monthcolor.y, 20, 10)

  '畫出圖例說明文字--data(i, 0)

  objgraphics.drawstring(data(i, 0), new font("宋體", 10), brushes.black, fontinfor)

  '移動坐標位置,只移動y方向的值即可。

  monthcolor.y += 15

  fontinfor.y += 15

  next i

  '遍歷數(shù)據(jù)源的每一項數(shù)據(jù),并根據(jù)數(shù)據(jù)的大小畫出矩形圖(即柱形圖的柱)。

  for i = 0 to 5

  '畫出填充矩形。

  objgraphics.fillrectangle(new solidbrush(getcolor(i)), (i * 25) + 35, 270 - cint(data(i, 1)), 15, cint(data(i, 1)))

  '畫出矩形邊框線。

  objgraphics.drawrectangle(pens.black, (i * 25) + 35, 270 - cint(data(i, 1)), 15, cint(data(i, 1)))

  next

  '畫出示意坐標

  objgraphics.drawline(new pen(color.blue, 1), 10, 0, 10, 320)

  objgraphics.drawline(new pen(color.blue, 1), 10, 270, 200, 270)

  '在示意坐標上添加數(shù)值標志,注意坐標的計算

  for i = 0 to 5

  objgraphics.drawline(new pen(color.blue, 1), 10, i * 50 + 20, 20, i * 50 + 20)

  objgraphics.drawstring((250 - i * 50).tostring, new font("宋體", 10), brushes.black, 12, i * 50 + 8)

  next

  ' 統(tǒng)計總銷售額

  dim scount as integer

  for i = 0 to 5

  scount += cint(data(i, 1))

  next

  '定義畫出扇形角度變量

  dim scg as single = 0

  dim stg as single = 0

  for i = 0 to 5

  '計算當前角度值:當月銷售額 / 總銷售額 * 360,得到餅圖中當月所占的角度大小。

  scg = cint(data(i, 1)) / scount * 360

  • 本文來源于網(wǎng)頁設計愛好者web開發(fā)社區(qū)http://www.html.org.cn收集整理,歡迎訪問。
  • 發(fā)表評論 共有條評論
    用戶名: 密碼:
    驗證碼: 匿名發(fā)表
    主站蜘蛛池模板: 大庆市| 仁怀市| 任丘市| 隆安县| 丹巴县| 丰宁| 赤水市| 大姚县| 民权县| 石河子市| 茂名市| 泾阳县| 洪泽县| 新竹市| 米易县| 毕节市| 永川市| 阿巴嘎旗| 雷波县| 潞城市| 永州市| 昭苏县| 广安市| 浙江省| 邛崃市| 乐东| 平潭县| 通河县| 巴林右旗| 四川省| 图们市| 兴海县| 博白县| 德兴市| 合肥市| 临夏市| 银川市| 巢湖市| 宁德市| 江口县| 福贡县|