Announcement

Collapse
No announcement yet.

gbChartMaster - Discussion

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Gary Beene
    replied
    In gbChartMaster (the application) I provide support for images using code from Jose's include files.

    If you don't need image support, you can remove the image functions and the remainder of the code should compile just fine using PowerBASIC include files.

    Leave a comment:


  • Gary Beene
    replied
    Online Help has a section on how to add the charting features to your own PowerBASIC app. But, here's a minimal code example, which includes the following steps:

    1. Create two variables - D() as ChartData and B as ChartSettings.
    2. Create Graphic control
    3. Create some data to graph
    4. Initialize the two variables
    5. Resize the Graphic control as needed.

    The code below gets you this (no image support):




    Code:
    'Compilable Example:
    #Compiler PBWin 10
    #Compile Exe
    #Dim All
    %Unicode = 1
    #Include "Win32API.inc"
    #Include "gbchartmaster.inc"
    
    Enum Equates Singular
       IDC_Graphic = 500
    End Enum
    
    Global hDlg,hGraphic As Dword
    Global D() As ChartData, B As ChartSettings
    
    Function PBMain() As Long
       Dialog New Pixels, 0, "PowerBASIC",300,300,600,300, %WS_OverlappedWindow To hDlg
       Control Add Graphic, hDlg, %IDC_Graphic,"Push", 0,0,600,300, %SS_Notify
       Control Handle hDlg, %IDC_Graphic To hGraphic
       Graphic Attach hDlg, %IDC_Graphic, ReDraw
       Dialog Show Modal hDlg Call DlgProc
    End Function
    
    CallBack Function DlgProc() As Long
       Local w,h As Long
       Select Case Cb.Msg
          Case %WM_InitDialog
             CreateFakeData
             InitializeChart hDlg, %IDC_Graphic
             B.Xmax = 60 : B.Xmin = 10 : B.Pivot = 40
          Case %WM_Size
             Dialog Get Client hDlg To w,h
             Control Set Size hDlg, %IDC_Graphic, w,h
             DrawChart D(), B, %True
       End Select
    End Function
    
    Sub CreateFakeData         'this is a user function
       Local i As Long
       ReDim D(1 To 100)
       For i = 1 To 40  : D(i).v(1) = 100 * (1.05)^i : Next i
       For i = 41 To 60 : D(i).v(1) = D(40).v(1) - 600 * (1.2)^(i-60)  : Next i
       For i = 1 To 60
          D(i).altColor(1) = %Gray : D(i).altColor(2) = %Gray : D(i).altColor(3) = %Gray
    
          D(i).v(2) = D(i).v(1) - 150 * Rnd
          D(i).v(3) = D(i).v(1) + 150 * Rnd
    
          D(i).altText(1)  = "Bar" + LTrim$(Str$(i)) + "_1"  'Chr$(Rnd(97,122)) + Chr$(Rnd(97,122)) + Chr$(Rnd(97,122)) + Chr$(Rnd(97,122)) + Chr$(Rnd(97,122))
          D(i).altText(2)  = "Bar" + LTrim$(Str$(i)) + "_2"  'Chr$(Rnd(97,122)) + Chr$(Rnd(97,122)) + Chr$(Rnd(97,122)) + Chr$(Rnd(97,122)) + Chr$(Rnd(97,122))
          D(i).altText(3)  = "Bar" + LTrim$(Str$(i)) + "_3"  'Chr$(Rnd(97,122)) + Chr$(Rnd(97,122)) + Chr$(Rnd(97,122)) + Chr$(Rnd(97,122)) + Chr$(Rnd(97,122))
    
          D(i).barlabel(1) = "Label" + LTrim$(Str$(i)) + "_1" 'Chr$(Rnd(97,122)) + Chr$(Rnd(97,122)) + Chr$(Rnd(97,122)) + Chr$(Rnd(97,122)) + Chr$(Rnd(97,122)) + Chr$(Rnd(97,122)) + Chr$(Rnd(97,122)) + Chr$(Rnd(97,122))
          D(i).barlabel(2) = "Label" + LTrim$(Str$(i)) + "_2" 'Chr$(Rnd(97,122)) + Chr$(Rnd(97,122)) + Chr$(Rnd(97,122)) + Chr$(Rnd(97,122)) + Chr$(Rnd(97,122)) + Chr$(Rnd(97,122)) + Chr$(Rnd(97,122)) + Chr$(Rnd(97,122))
          D(i).barlabel(3) = "Label" + LTrim$(Str$(i)) + "_3" 'Chr$(Rnd(97,122)) + Chr$(Rnd(97,122)) + Chr$(Rnd(97,122)) + Chr$(Rnd(97,122)) + Chr$(Rnd(97,122)) + Chr$(Rnd(97,122)) + Chr$(Rnd(97,122)) + Chr$(Rnd(97,122))
       Next i
       For i = 1 To 60
          If D(i).v(1) < 0 Then D(i).v(1) = 0
          If D(i).v(2) < 0 Then D(i).v(2) = 0
          If D(i).v(3) < 0 Then D(i).v(3) = 0
       Next i
    End Sub
    
    Sub InitializeChart(hWnd As Dword, cID As Long)    'this a user function for assigning Chart settings
       B.hParent       = hWnd
       B.cID           = cID
       Control Handle B.hParent, B.cID To B.hGraphic
       Graphic Get DC To B.hGraphicDC
       B.LM            = 100
       B.RM            = 80
       B.TM            = 60
       B.BM            = 40
       B.Title         = "gbChartMaster"
       B.XTitle        = "X-Value:"
       B.YTitle        = "Y-Value:"
       B.DataSetTitle(1) = "Title 1"
       B.DataSetTitle(2) = "Title 2"
       B.DataSetTitle(3) = "Title 3"
       B.DivYCount     = 5
       B.Xmax          = UBound(D)
       B.XMin          = 1
       B.maxYValue     = 0
       B.usefixedYvalue= 0
       B.fixedYvalue   = 10000    '1=10 2=100 3=1000 ...
       B.coverage      = 0.6 '>0.1 and <=1.0
       B.Pivot         = UBound(D)
       B.FadeValue     = 0
       B.AllBars       = 1
       B.ShowGrid      = 1
       B.ShowTitle     = 1
       B.ShowAxisTitles = 1
       B.ShowAxisValues = 1
       B.HoverTips     = 1
    
       B.UserData(1)   = "10" + $CrLf    + "40" + $CrLf    + "90" + $CrLf    + "160" + $CrLf     + "120"
       B.AltText(1)    = "One" + $CrLf   + "Four" + $CrLf  + "Nine" + $CrLf  + "Twenty" + $CrLf  + "Twelve"
       B.BarLabels(1)  = "Plum" + $CrLf  + "Peach" + $CrLf + "Pear" + $CrLf  + "Apple" + $CrLf   + "Orange"
    
       B.UserData(2)   = "8" + $CrLf     + "32" + $CrLf    + "70" + $CrLf    + "120" + $CrLf     + "115"
       B.AltText(2)    = "Left" + $CrLf  + "Right" + $CrLf + "Top" + $CrLf   + "Bottom" + $CrLf  + "Center"
       B.BarLabels(2)  = "Oak" + $CrLf   + "Elm" + $CrLf   + "Birch" + $CrLf + "Redwood" + $CrLf + "Magnolia"
    
       B.UserData(3)   = "14" + $CrLf    + "43" + $CrLf    + "120" + $CrLf   + "175" + $CrLf     + "132"
       B.AltText(3)    = "North" + $CrLf + "South" + $CrLf + "East" + $CrLf  + "West" + $CrLf    + "None"
       B.BarLabels(3)  = "Pigs" + $CrLf  + "Cows" + $CrLf  + "Sheep" + $CrLf + "Horses" + $CrLf  + "Goats"
    
    
       B.GraphType     = 1        '1=2D 2=3D 3=Line 4=DOT
       B.BarGradientType  = 1        '1=flat
       B.ThreeDX       = 15
       B.ThreeDY       = 20
       B.titleFontName = "Tahoma"
       B.titleFontSize = 14
       B.titleFontBold = 1
    
       B.axisTitleFontName = "Tahoma"
       B.axisTitleFontSize = 10
       B.axisTitleFontBold = 1
    
       B.DataSet           = 1
    
       B.axisValueFontName = "Tahoma"
       B.axisValueFontSize = 10
       B.axisValueFontBold = 0
    
       B.useAltColors   = 0
       B.useAltText     = 0
       B.gradientBG     = 0
       B.fadeBG         = 0
    
       B.cBG           = %White
       B.cTitle        = %Black
       B.cAxisLines    = %Black
       B.cAxisValues   = %Black
    
       B.cPreBars(1)   = %Green
       B.cPreBars(2)   = %rgb_DarkGreen
       B.cPreBars(3)   = %rgb_LightGreen
       B.cPostBars(1)  = %Red
       B.cPostBars(2)  = %rgb_DarkRed
       B.cPostBars(3)  = %rgb_Salmon
       B.cSymbols(1)   = %rgb_DarkGray
       B.cSymbols(2)   = %Gray
       B.cSymbols(3)   = %rgb_LightGray
    
       B.BarBorder     = 2       '1=none 2=black 3=white
       B.ShowBarLabel  = 0
       B.VertBarLabels = 0
       B.Annotation    = 0
       B.LargeStamp    = 1
       B.RoundedBar    = 0
       B.MinusYAxis    = 0
       B.VertYLabel    = 0
       B.SoftGrid      = 0
       B.LeftTitle     = 0       '0=mid 1=left
       B.LeftXTitle    = 1       '0=left 1=mid
       B.TopYTitle     = 1
       B.AutoXCount    = 1
       B.ExportFormat  = 2       '1=bmp 2=jpg 3=gif 4=png
       B.Equation(1)   = "1:100:0:0.3:20+10 * sin(x)"
       B.Equation(2)   = "1:100:0:1:100*x + 70"
       B.Equation(3)   = "1:100:0:0.3:20+10 * ABS(sin(x))"
       B.EquationAnimate = 0
    
    '   B.StampList     = ""
    '   B.Stamp         = Exe.Path$ + "stamps\" + Dir$(Exe.Path$ + "stamps\_markerblue.png")
    '   If IsFalse IsFile(B.Stamp) Then B.Stamp = Exe.Path$ + "stamps\" + Dir$(Exe.Path$ + "stamps\*.*")
    
       B.ShowBGImage   = 0
    
    '   B.BGImage       = Exe.Path$ + "bgimages\eyes.jpg"
    '   If IsFalse IsFile(B.BGImage) Then B.BGImage = Exe.Path$ + "bgimages\" + Dir$(Exe.Path$ + "bgimages\*.*")
    '   LoadBGImage ((B.BGImage), B.hBGImage)  'Graphic Bitmap Load B.BGimage, 0, 0 To B.hBGImage
    
       B.BGImageFit    = 1       '0-no resize 1=resize to fit
       B.LineSymbol    = 2       '1-dot 1=circle 2=triangle 3=square 4=emptydot
       B.LineThickness = 1
       B.SymbolSize    = 1
       B.Interval      = 100     'milliseconds
    
       CreateFonts
    End Sub
    
    Sub CreateFonts
       'set Graphic to default font to free up other fonts for deletion
       Graphic Set Font 0
       'delete other fonts
       Font End B.TitleFont
       Font End B.axisTitleFont
       Font End B.axisTitleFontR
       Font End B.axisValueFont
       Font End B.axisValueFontR
       'rebuild fonts
       Font New B.TitleFontName,     B.TitleFontSize,     B.TitleFontBold     To B.TitleFont
       Font New B.axisTitleFontName, B.axisTitleFontSize, B.axisTitleFontBold To B.axisTitleFont
       Font New B.axisTitleFontName, B.axisTitleFontSize, B.axisTitleFontBold,1,0, 900 To B.axisTitleFontR
       Font New B.axisValueFontName, B.axisValueFontSize, B.axisValueFontBold To B.axisValueFont
       Font New B.axisValueFontName, B.axisValueFontSize, B.axisValueFontBold,1,0, 900 To B.axisValueFontR
    End Sub

    Leave a comment:


  • Gary Beene
    replied
    Some images of sample charts:



    Leave a comment:


  • Gary Beene
    started a topic gbChartMaster - Discussion

    gbChartMaster - Discussion

    This page is for discussion of my latest posted application, gbChartMaster, which generates a variety of charts - bar charts (2D and 3D), stacked bar charts, line charts, multi-line charts, points/symbols only and a hi-lo bar chart. Control over all aspects of the graph elements - position, color, fonts, margins, grid, and more - is provided. Images for background and for annotation stamps are also supported.



    While chart data is typically provided point by point by the user, gbChartMaster also allows the user to supply an equation which can be used to automatically generate the graph data.

    The chart source code is written so that it can be easily inserted into PowerBASIC applications, so that other programmers can add the graphing capabilities to their own applications. The gbChartMaster application is essentially a demonstration of how to use the include source code in a PowerBASIC application, including how to use all 100+ available settings!

    As always, comments and suggestions are welcome!
    Last edited by Gary Beene; 27 Jul 2015, 02:02 PM.
Working...
X