borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Previous Topic (Subclassing a command button)Next Topic (Getting a window path) New Topic New Poll Post Reply
AndreaVB Forum : API : api pie help!
Poster Message
larryjf
Level: Protégé

Registered: 28-03-2004
Posts: 8

icon api pie help!

I am trying to create a pie chart that shows the minimum balance of an account in relation to the actual balance of the account.

My problem is i can't figure out how to get this percentage into actual coordinates.

I am using 0,0 as my starting left point and 100,100 as my ending right point of the pie chart.

So if the numbers were $25 minimum $100 balance, how could i convert that into pie chart points?

03-05-2004 at 05:22 PM
View Profile Send Email to User Show All Posts | Quote Reply
Goran
Level: Moderator

Registered: 16-05-2002
Posts: 1681
icon Re: api pie help!

I dont have math book with me, but there are formulas to calculate starting and ending points of the pie. In your example, 25% would be simple, cause no big calculations are necessary.

Pie Me.hdc, 0, 0, 100, 100, 100, 50, 50, 0



I have attached an graphics example (drawn by me   ) of how pie API works, so oyu can understand it better (x1,y1)-(x2,y2) are left-top/right-bottom coordinaters of rectangle, (Sx,Sy) - starting point of the pie (Ex,Ey) ending point of the pie.

[Edited by Goran on 04-05-2004 at 05:39 PM GMT]

____________________________
If you find the answer helpful, please mark this topic as solved.

____________________________
Attached:
pie.gif (4 KB)

04-05-2004 at 04:38 PM
View Profile Send Email to User Show All Posts | Quote Reply
Goran
Level: Moderator

Registered: 16-05-2002
Posts: 1681
icon Re: api pie help!

By the way, similar thing you can do with Circle command, I have made you a code that will show you the idea:

Private Sub DrawPie(Percent As Single)
Const pi = 3.141592654
Dim ratio As Single

    Me.Cls
    ratio = (10 / 8 - Percent / 100)
    If ratio > 1 Then ratio = ratio - 1
    
    Circle (2500, 2500), 1000, , -2 * pi * ratio, -pi / 2
End Sub


____________________________
If you find the answer helpful, please mark this topic as solved.

04-05-2004 at 05:30 PM
View Profile Send Email to User Show All Posts | Quote Reply
larryjf
Level: Protégé

Registered: 28-03-2004
Posts: 8
icon Re: api pie help!

Thank you very much for the help.

I worked out an approximation that works pretty good...


dblBal = (minBalance / AcctBalance) * 100
If dblBal <= 25 Then
    X1 = dblBal * 2
    Y1 = 0
    X2 = 0
    Y2 = dblBal * 2
    XX1 = 0
    YY1 = dblBal * 2
    XX2 = dblBal * 2
    YY2 = 0
End If
If dblBal > 25 And dblBal <= 50 Then
    X1 = dblBal
    Y1 = 0
    X2 = dblBal
    Y2 = dblBal * 2
    XX1 = dblBal
    YY1 = dblBal * 2
    XX2 = dblBal
    YY2 = 0
End If
If dblBal > 50 And dblBal <= 75 Then
    X1 = dblBal * 0.667
    Y1 = 0
    X2 = dblBal * 1.333
    Y2 = dblBal * 0.667
    XX1 = dblBal * 1.333
    YY1 = dblBal * 0.667
    XX2 = dblBal * 0.667
    YY2 = 0
End If
If dblBal > 75 And dblBal <= 99 Then
    X1 = dblBal * 1.143
    Y1 = 0
    X2 = dblBal * 1.143
    Y2 = dblBal * 0.571
    XX1 = dblBal * 1.143
    YY1 = dblBal * 0.571
    XX2 = dblBal * 1.143
    YY2 = 0
End If
If dblBal = 100 Then
    X1 = 50
    Y1 = 0
    X2 = 50
    Y2 = 0
End If


Here is my teachers reply to this problem...

quote:

This looks to be a kind of approximation.  The problem is it's a linear approximation of a curve.  I think for the purposes of this pie chart it should work out okay--the visual appearance of the chart will be close enough for its purpose.  However, if you want to get exact about it, here's the right approach as I remember it.  Let's suppose that the percentage is between 0 and 12.5%, and we want our wedge to be in the upper part of the right side of the pie.  That means that the angle of our pie piece is between 0 and 45 degrees, right?  If you place the whole pie in a square that's the same size, then if we extend the lines on the side of the pie piece they would make a right triangle when they met the line on the right side of the square.  We need both points where these lines would meet the square.  One is fixed, it's halfway up the right side.  The other's the trick.  But since we have a right triangle, we just use the tangent function, which gives us the ratio of the opposite side to the adjacent side.  The adjacent side's length is just the radius of the circle, and we can get the angle by dividing 100 percentage points into 360 degrees.  That gives us the length of the opposite side which tells us where to place that other point.

05-05-2004 at 12:24 PM
View Profile Send Email to User Show All Posts | Quote Reply
Goran
Level: Moderator

Registered: 16-05-2002
Posts: 1681
icon Re: api pie help!

Yes, your teacher is right. He was explaining yoo how to determine your second line of the pie, since first line is not changing. And as I said, there is a math formula, but I cant recall how it goes, and your teacher was giving you a clue how to implement this function (as he says it is tangent function which is used on right triangle). You would have to look in a math book and find this funciton in order to implement it in your code.

____________________________
If you find the answer helpful, please mark this topic as solved.

05-05-2004 at 06:08 PM
View Profile Send Email to User Show All Posts | Quote Reply
AndreaVB Forum : API : api pie help!
Previous Topic (Subclassing a command button)Next Topic (Getting a window path) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder