Home | Blog | Software | Reviews and Features | Forum | Help | Donate | About us
topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • December 08, 2016, 11:50:58 PM
  • Proudly celebrating 10 years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: FBSL - How to do charts  (Read 2062 times)

Gerome

  • Charter Honorary Member
  • Joined in 2006
  • ***
  • Posts: 154
    • View Profile
    • Get my Freestyle Basic Script Language + compiler!
    • Donate to Member
FBSL - How to do charts
« on: March 29, 2006, 01:51:10 PM »
Hello,

FBSL has some GUI primitives that allows user to develop simple but efficient 'charts'.
Here's the code that will make random charts...

Charts.fbs
Dim %hdc = GetDC(ME)
Const WM_DRAW = WM_USER + &H100

Fbsl_SetText(ME, "Horns & Hoofs, Inc. (left click to redraw)")
BackColor(hdc, Rgb(255, 255, 0))
Resize(ME, 0, 0, 800, 500)
Center(ME)
Show(ME)
Draw()

Begin Events
Select Case CBMSG
Case WM_DRAW
Draw()
Case WM_PAINT, WM_NCPAINT, WM_LBUTTONDOWN
PostMessage(ME, WM_DRAW, 0, 0)
Case WM_CLOSE
ReleaseDC(ME, hdc)
ExitProgram(0)
End Select
End Events

Sub Draw()
Clear(hdc)
FontTransparent(hdc, TRUE)
DrawArrows(10)
CurrentX(hdc, 20): CurrentY(hdc, 40)
DrawLine(Rgb(0, 0, 255), DRAW_DASH)
CurrentX(hdc, 20): CurrentY(hdc, 120)
DrawLine(Rgb(255, 0, 0), DRAW_DASHDOT)
CurrentX(hdc, 20): CurrentY(hdc, 160)
DrawLine(Rgb(0, 255, 0), DRAW_DASHDOTDOT)
DrawText(200, 20)
DrawBoxes()
DrawArrows(250)
CurrentX(hdc, 320): CurrentY(hdc, 250)
Text(hdc, "Production Turnover")
End Sub

Sub DrawLine(ByVal clr, ByVal style)
Dim %stp = 775 \ 12
DrawStyle(style)
ForeColor(hdc, clr)
For i = stp To 775 Step stp
Line(hdc, CurrentX(hdc), CurrentY(hdc), i, RandInt(1, 4) * 40)
Next
End Sub

Sub DrawText(ByVal x, ByVal y)
ForeColor(hdc, Rgb(0, 0, 255)): CurrentX(hdc, x): CurrentY(hdc, y)
Text(hdc, "Income")
ForeColor(hdc, Rgb(255, 0, 0)): CurrentX(hdc, CurrentX(hdc) + 200)
Text(hdc, "Expenses")
ForeColor(hdc, Rgb(0, 255, 0)): CurrentX(hdc, CurrentX(hdc) + 200)
Text(hdc, "Profit")
End Sub

Sub DrawArrows(ByVal y)
Dim %stp = 775 \ 12
ForeColor(hdc, 0)
DrawStyle(DRAW_SOLID)
DrawWidth(2)
Line(hdc, 10, y, 10, y + 190)
Line(hdc, 10, y, 7, y + 5)
Line(hdc, 10, y, 12, y + 5)
Line(hdc, 10, y + 190, 780, y + 190)
Line(hdc, 780, y + 190, 776, y + 187)
Line(hdc, 780, y + 190, 776, y + 192)
DrawWidth(3)
For i = stp To 775 Step stp
PSet(hdc, i, y + 190)
Text(hdc, i * 12 \ 775 + 1)
Next
For i = y + 30 To y + 160 Step 40
PSet(hdc, 10, i)
Text(hdc, (y + 190 - i) \ 40)
Next
CurrentX(hdc, 18): CurrentY(hdc, y)
Text(hdc, "Bln USD")
CurrentX(hdc, 730): CurrentY(hdc, y + 170)
Text(hdc, "Month")
DrawWidth(1)
End Sub

Sub DrawBoxes()
Dim %stp = 775 \ 12
DrawStyle(DRAW_SOLID)
For i = stp To 775 Step stp
FillStyle(RandInt(0, 6))
FillColor(Rgb(%RandInt(0, 255), %RandInt(0, 255), %RandInt(0, 255)))
Line(hdc, i - 3, 400 - %RandInt(0, 3) * 40, i - 47, 438, _
Rgb(%RandInt(0, 255), %RandInt(0, 255), %RandInt(0, 255)), _
TRUE, %RandInt(0, 1))
Next
End Sub


Here's a screnshot of the result:

Enjoy ;)
Yours,
(¯`·._.·[Gerome GUILLEMIN]·._.·´¯)
http://www.fbsl.net [FBSL Author]
http://gedd123.free.fr/FBSLv3.zip [FBSL Help file]
(¯`·._.·[If you need help... just ask]·._.·´¯)
« Last Edit: April 07, 2006, 12:11:35 PM by Gerome »