如何让百分比总是出现在相应饼图扇区的中央位置?
如题,下面是我的代码,如何才能让百分比随着所在扇区角度的变化而变化,并且总是出现在该扇区的中央位置。
Sub ShowPicture1(ByVal mBad As Integer, ByVal mVendor As String, ByVal Qty As Integer)
Dim iFlags%
Dim sql As String = ""
Dim ds As DataSet
Dim BMP1 As New Bitmap(Me.PictureBox1.Width, PictureBox1.Height)
Dim BMP2 As New Bitmap(Me.P1.Width, P1.Height)
Try
sql = "select FIELD_DATA from udtKeyWord where KeyWord='Dining' and FIELD_TYPE='Title'"
ds = SQLiteHelper.ExecuteDataset(connectstr, CommandType.Text, sql)
If ds.Tables(0).Rows.Count > 0 Then
Title_1.Text = ds.Tables(0).Rows(0).Item(0).ToString
Else
iFlags = vbInformation Or vbOKOnly
MessageBoxTimeout(Me.Handle, "标题没有维护!", "Message", iFlags, 0, 3000)
Exit Sub
End If
Name_1.Text = mVendor.ToString
Dim i As Integer = 0
Dim Sc As String = My.Computer.Screen.Bounds.Width.ToString & "*" & My.Computer.Screen.Bounds.Height.ToString
'Dim MyGraphics As Graphics = Me.PictureBox1.CreateGraphics
Dim MyGraphics As Graphics = Graphics.FromImage(BMP1)
MyGraphics.Clear(Color.White)
'Dim MyGraphicsP1 As Graphics = Me.P1.CreateGraphics
Dim MyGraphicsP1 As Graphics = Graphics.FromImage(BMP2)
Dim MyBrush As New SolidBrush(Color.Red)
Dim MyProportion As Single
Dim MyRect As New Rectangle
Dim MyPoint As New PointF
Dim R As Single
Dim arrValues(1) As Integer
arrValues(0) = Qty
arrValues(1) = mBad
Dim arrValueNames(1) As String
arrValueNames(0) = "总计:" + arrValues(0).ToString
arrValueNames(1) = "不满意:" + arrValues(1).ToString
'Const PI = 3.1415926
MyGraphics.Clear(Me.PictureBox1.BackColor)
MyGraphicsP1.Clear(Me.P1.BackColor)
Dim MyStartAngel As Double
Dim MySweepAngel As Double
Dim MyM As Double
Dim MyN As Double
R = Math.Min(Me.PictureBox1.Width, Me.PictureBox1.Height) / 2 - 5
MyPoint.X = Me.PictureBox1.Width / 2
MyPoint.Y = Me.PictureBox1.Height / 2
MyRect.X = MyPoint.X - R
MyRect.Y = MyPoint.Y - R
MyRect.Width = R * 2
MyRect.Height = R * 2
'画不满意扇区
MyStartAngel = 0
MyProportion = mBad / Qty
MySweepAngel = 360 * MyProportion
MyM = MySweepAngel
MyBrush.Color = Color.Red
MyGraphics.FillPie(MyBrush, MyRect, MyStartAngel, MySweepAngel)
'画满意扇区
MyStartAngel = MyStartAngel + MySweepAngel
MyProportion = (Qty - mBad) / Qty
MySweepAngel = 360 * MyProportion
MyN = MySweepAngel
MyBrush.Color = Color.Blue
MyGraphics.FillPie(MyBrush, MyRect, MyStartAngel, MySweepAngel)
'画百分比
If MyN = 360 Then
MyGraphics.DrawString("满意 " + Math.Round(((Qty - mBad) * 100 / Qty), 2).ToString + "%", New Font("宋体", 12 * Me.Width / x, FontStyle.Bold), Brushes.Green, MyRect.X + R * 3 / 4, MyRect.Y + R)
Else
If MyN <> 0 Then
MyGraphics.DrawString("满意 " + Math.Round(((Qty - mBad) * 100 / Qty), 2).ToString + "%", New Font("宋体", 12 * Me.Width / x, FontStyle.Bold), Brushes.Green, MyRect.X + R, MyRect.Y + R * 3 / 4)
End If
End If
If MyM <> 0 Then
If MyM = 360 Then
MyGraphics.DrawString("不满意 " + Math.Round(((mBad) * 100 / Qty), 2).ToString + "%", New Font("宋体", 12 * Me.Width / x, FontStyle.Bold), Brushes.Green, MyRect.X + R * 3 / 4, MyRect.Y + R)
Else
MyGraphics.DrawString("不满意 " + Math.Round(((mBad) * 100 / Qty), 2).ToString + "%", New Font("宋体", 12 * Me.Width / x, FontStyle.Bold), Brushes.Green, MyRect.X + R, MyRect.Y + R)
End If
End If
Dim mW As Integer = Panel1.Width / 15
Dim mH As Integer = Panel1.Height / 40
Dim symbolLeg As PointF = New PointF(1, 10)
Dim descLeg As PointF = New PointF(mW + 1, 10)
'画杂项
For i = 0 To arrValueNames.Length - 1
MyGraphicsP1.FillRectangle(New SolidBrush(GetColor(i)), symbolLeg.X, symbolLeg.Y, mW, mH)
MyGraphicsP1.DrawRectangle(Pens.LightBlue, symbolLeg.X, symbolLeg.Y, mW, mH)
MyGraphicsP1.DrawString(arrValueNames(i).ToString, New Font("宋体", 10 * Me.Width / x, FontStyle.Bold), Brushes.Navy, descLeg)
symbolLeg.Y += 35
descLeg.Y += 35
Next
PictureBox1.Image = BMP1
P1.Image = BMP2
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
[解决办法]
没人回答。。。
[解决办法]
哪位大侠赐教下,谢谢。