作者MOONRAKER (㊣乌笨秃,又笨又秃)
看板Visual_Basic
标题Re: [.NET] 圆饼图
时间Sat Jun 28 00:57:43 2008
一时兴起写了以下的code,就算是范例吧
献丑了
http://dpaste.com/hold/59527/
---
NAME
drawpie - 简易圆饼图绘制工具
SYNOPSIS
drawpie(g, pieLeft, pieTop, pieWidth, pieHeight, colors(), slices())
PARAMETERS
g 要画图的graphics
pieLeft 圆饼图的左上角X座标(想像一个圆的外接正方形的左上方顶点)
pieTop 圆饼图的左上角Y座标
pieWidth 圆饼图宽度
pieHeight 圆饼图高度
colors() brush阵列,画圆饼图各块要用的颜色
slices() integer阵列,圆饼图各块的百分比。是百分比喔!不是角度喔!
REMARKS
* 本sub不检查slices()中各项总和是否为100,所以使用者要自己注意。
(不过这样可以玩点花样,例如画不从正上方开始的圆饼图)
* colors可以包含任意数量的brush,不会发生错误。如果brush比slice多,
多出来的不会用到;如果brush比slice少,那麽各个slice会循环使用颜色。
如果colors中只有一个brush就是指定所有的slice为同一个颜色。
* 本sub会自动给每个slice加白边,还没有写给每个slice画不同边的code,
但是很容易改出来。
* 还有以前很多商业图范例都会做的某一块pie外推若干pixels,目前也没
写,不过自己写也很容易,用一点cos()和sin()就可以了。
---
Public Class Form1
Private Sub drawpie(ByRef g As Graphics, ByVal pieLeft As Integer, ByVal pieTop As Integer, _
ByVal pieWidth As Integer, ByVal pieHeight As Integer, _
ByRef colors As Brush(), ByRef slices As Integer())
Dim i As Integer, j As Integer, startAngle As Integer = -90
Dim borderPen As Pen = New Pen(Color.AntiqueWhite, 2.5)
Dim sliceDeg As Integer
Try
j = LBound(colors)
For i = LBound(slices) To UBound(slices)
sliceDeg = slices(i) * 360 / 100
g.FillPie(colors(j), pieLeft, pieTop, pieWidth, pieHeight, startAngle, sliceDeg)
g.DrawPie(borderPen, pieLeft, pieTop, pieWidth, pieHeight, startAngle, sliceDeg)
startAngle += sliceDeg
j += 1
If j > UBound(colors) Then j = LBound(colors)
Next i
Catch ex As Exception
End Try
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim b As Bitmap = New Bitmap(Pic1.Width, Pic1.Height)
Dim g As Graphics = Graphics.FromImage(b)
g.Clear(Color.Gray)
g.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias
Dim pieleft As Integer = 10, pieTop As Integer = 10
Dim pieWidth As Integer = Pic1.Width - pieleft - 10
Dim pieHeight As Integer = Pic1.Height - pieTop - 10
Dim piecolors As Brush() = {Brushes.RoyalBlue, Brushes.Lime, Brushes.Turquoise, Brushes.SaddleBrown}
Dim pieslices As Integer() = {34, 19, 16, 10, 9, 7, 5}
drawpie(g, pieleft, pieTop, pieWidth, pieHeight, piecolors, pieslices)
Pic1.Image = b
End Sub
End Class
--
BATCH 1 (4/20) - 如何隐身 - SPAM - 英国杀人笑话 -
http://tinyurl.com/65vvbx
BATCH 2 (5/10) - 当众脱裤 - 主教 - 傻蛋奥运会 -
http://tinyurl.com/68grk7
BATCH 3 (6/14) - 买张床 - 切达大侠 - 伐木人之歌 -
http://tinyurl.com/3zpyx5
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
■ 蒙帝派松正体中文计画 ■ Spam-a-lot and enjoy the pythonesque delight!
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 59.115.199.251
※ 编辑: MOONRAKER 来自: 59.115.213.174 (06/28 11:16)