Announcement

Collapse

Forum Guidelines

This forum is for finished source code that is working properly. If you have questions about this or any other source code, please post it in one of the Discussion Forums, not here.
See more
See less

gbChartMaster - Charts for Your PowerBASIC Application

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

  • PBWin gbChartMaster - Charts for Your PowerBASIC Application

    Here's my latest application, gbChartMaster v2.0which generates a variety of charts - bar charts (2D and 3D), stacked bar charts, line charts, multi-line charts, points/symbols only, a hi-lo bar chart, and pie charts with up to 3 datasets displayed at one time. 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!

    Discussion is here.
    Online Help is here.
    Download the EXE, source code and images here.

    Here's a typical image of gbChartMaster - bar charts with an image in the background.



    Here's a few images of the types of charts that are provided:



    And here are some of the gradient styles supported:



    Several kinds of graphics features are supported:



    Pie charts are supported, with up to 3 datasets drawn at one time:



    And, finally, you can use provide the chart data via an equation which gbChartMaster can plot.



    gbChartMaster offers the following features:

    Data Sets
    • 3 Independent Data Sets
    • Limit Graph to a Range of Data Points in Each Data Set

    Charts
    • Bar and Pie Charts
    • 12 Chart Types
    • Over 100 Chart Settings
    • Bar Charts (2D and 3D)
    • Pie Charts (2D and 3D)
    • Line and Point Charts
    • Multi-Line Charts (2-Lines and 3-Lines)
    • Stacked Bar Charts (2-Stacks and 3-Stacks)
    • Hi-Lo Bar Charts (Bar, Beam, Beam+Symbol)
    • Pie Charts (2D and 3D, 1-3 DataSetes)
    • Multiple Line Symbols (Point, Square, Rectangle, Circle)
    • Real-Time Graph Updates as Application is Resized
    • Real-Time Graph Updates as Settings Are Changed
    • Optional Display of All Graph Elements
    • Independent Margins for All Sides of the Charts
    • Selection of Individual Bars Via Mouse
    • Display of Bar/Point Data As Mouse Moves Over Graph Elements
    • Main Title positions (Left, Center, Right)
    • X-Axis title positions (InlineLeft, Left, Center, Right, InlineRight)
    • Y-Axis title positions (Top, Center, Bottom)
    • Margins automatically position to accommodate title font changes
    • Anti-Aliasing of line charts
    • Smoothing of line charts
    • Line styles (dash-dot combinations)
    • Control over which of 3 data types are used for labelling charts
    • Rounded Bars (variable amount of rounding)
    • Horizontal and Vertical Grid
    • Bar labels positions adjust to match symbol size
    • Current chart type displayed on StatusBar
    • Rotation of pie charts
    • Hide unselected pie chart sections
    • Adjust pie chart size with available area
    • Gradient pie charts (light center to full color perimeter)
    • Legends for all pie charts
    • Explosion of pie chart sections
    • User control of pie chart explosion distances
    • Fixed circle or ellipse pie charts shapes

    Text/Colors/Font
    • Graph Title, Axis Titles, Data Values and Data Set Labels
    • Font/Color Control of All Graph Elements
    • Data Labels (Displayed Above Points/Bars)
    • Alternate Text for the X-Axis
    • Graph/Axis Title Positioning
    • Vertical/Horizontal Titles (Y-Axis and Bar Labels)
    • Pivot Point for Alternating Chart Colors
    • Multiple Gradient Options (Background and Bars)
    • Color Fading
    • Automatic X-Axis Value Display to Avoid Overlap of Bar Labels or X Axis Values
    • Automatic Generation of Y-Axis Value Divisions (Optional)
    • Line and Border Thickness/Color Control
    • Select Grid Color and Line Style

    Images
    • Background Image Support
    • Annotation - Images
    • Annotation - Free-Style Drawing
    • Fit Graph to Background Image
    • Capture Chart Image to Clipboard
    • Export Chart Image to JPG/GIF/PNG/BMP
    • Save JPG Chart Image to Chart File Location

    File Functions
    • Automatically Save Session
    • Save Chart to File
    • Open Existing Chart Files
    • Save Settings to File
    • Open Existing Settings Files

    Other
    • Automatic Generation of Data from User Equations
    • Onscreen instructions for mouse actions
    • Speed test to determine draw time
    • Online Help


    The gbChartMaster application source code is here:
    Code:
    'Compilable Example:
    #Compiler PBWin 10
    #Compile Exe  "gbchartmaster.exe"
    #Dim All
    
    #Debug Display On
    #Debug Error On
    
    %Unicode = 1
    #Include "Win32API.inc"
    #Include "cgdiplus.inc"
    #Include "gbchartmaster.inc"
    
    #Resource Icon logo "icons\gbchartmaster.ico"
    #Resource Icon xsettings "icons\settings.ico"
    #Resource Icon xhelp "icons\help.ico"
    #Resource Wave, xcamera, "icons\camera.wav"
    
    $SessionFile = "tempfiles\session.gbc"
    $Ver         = "2.0"
    
    Type CustomColors
       c(15) As Long
    End Type
    
    Enum Equates Singular
       IDC_Graphic
       IDC_StatusBar
    
       IDC_Label
       IDC_Frame
       IDC_LM
       IDC_RM
       IDC_TM
       IDC_BM
       IDC_UseAltColors
       IDC_UseAltXText
       IDC_GradientBG
       IDC_FadeBG
       IDC_ColorUnder
       IDC_cGrid
       IDC_cBG
       IDC_cTitle
       IDC_cAxisLines
       IDC_cAxisValues
    
       IDC_cPreBars1
       IDC_cPostBars1
       IDC_cSymbols1
       IDC_cPreBars2
       IDC_cPostBars2
       IDC_cSymbols2
       IDC_cPreBars3
       IDC_cPostBars3
       IDC_cSymbols3
    
       IDC_Title
       IDC_XTitle
       IDC_YTitle
       IDC_MainTitleLoc
       IDC_XTitleLoc
       IDC_YTitleLoc
       IDC_DataSet1Title
       IDC_DataSet2Title
       IDC_DataSet3Title
       IDC_TitleFont
       IDC_axisTitleFont
       IDC_axisValueFont
       IDC_LabelFont
    
       IDC_MainTitleFontSize
       IDC_AxisTitleFontSize
       IDC_ValuesFontSize
       IDC_LabelFontSize
    
    
       IDC_AllBars
       IDC_ShowHGrid
       IDC_ShowVGrid
       IDC_ShowMargins
       IDC_SpeedTest
       IDC_Instructions
       IDC_ShowMainTitle
       IDC_DotGrid
       IDC_ShowAxisTitles
       IDC_ShowAxisValues
       IDC_UseAntiAliasing
       IDC_UserData
       IDC_GraphType
       IDC_BarGradientType
       IDC_ThreeDX
       IDC_ThreeDY
    
       IDC_PieRadius
       IDC_PieCircle
       IDC_PieExplode
       IDC_PieExplodeDistance
       IDC_PieEject
       IDC_PiePerCent
       IDC_PieDonut
       IDC_PieDonutCaption
       IDC_PieLegend
       IDC_PieRotate
       IDC_Pie3D
       IDC_PieGradient
       IDC_PieGradientValue
       IDC_PieHideUnSelected
       IDC_PieHighlightSelected
    
       IDC_Coverage
       IDC_Pivot
       IDC_ApplyAll
       IDC_Fade
       IDC_XMax
       IDC_XMin
       IDC_DivYCount
       IDC_UseFixedYValue
       IDC_FixedYValue
       IDC_SaveAs
       IDC_Open
       IDC_Reset
       IDC_Resize
       IDC_RandomColors
       IDC_Copy
       IDC_Print
       IDC_Export
       IDC_EraseAllStamps
       IDC_EraseLastStamp
       IDC_ApplyDataFile
       IDC_ApplyAltXText
       IDC_ApplyBarLabels
       IDC_ApplyColors
       IDC_AltXText
       IDC_BarLabels
       IDC_BarColors
    
       IDC_BarBorder
       IDC_ShowBarLabel
       IDC_VertBarLabels
       IDC_ValueBarLabels
       IDC_VertYTitle
       IDC_LargeStamp
       IDC_RoundedBar
       IDC_RoundValue
       IDC_AutoXCount
       IDC_ExportFormat
       IDC_Equation
       IDC_EvalEquation
       IDC_TransferData
       IDC_EquationAnimation
       IDC_Stamp
       IDC_StampPreview
       IDC_BGImagePreview
       IDC_ShowBGImage
       IDC_BGImage
       IDC_BGImageFit
       IDC_Annotation
       IDC_LineSymbol
       IDC_HiLoSymbol
       IDC_LineThickness
       IDC_SymbolSize
       IDC_ShowDataSetTitles
       IDC_OnLineHelp
       IDC_SaveSettings
       IDC_OpenSettings
    
       IDC_GridOnTop
       IDC_SmoothLines
       IDC_LineStyle
       IDC_LabelType
    
       IDC_ShowV1
       IDC_ShowV2
       IDC_ShowV3
    
       IDM_Cut
       IDM_Copy
       IDM_Paste
       IDM_Delete
       IDM_Escape
       IDM_GraphType
       IDM_AutoXCount
       IDM_CopyImage
       IDM_ExportToGBC
       IDM_Export
       IDM_EraseLastStamp
       IDM_NextBGImage
       IDM_NextChart
       IDM_BarGradient
       IDM_Image
       IDM_Open
       IDM_SaveAs
       IDM_BarLabels
       IDM_SpeedTest
       IDM_Instructions
       IDM_ShowMargins
       IDM_Radar
       IDM_Reset
       IDM_Settings
       IDM_Help
       IDM_UnSelectBars
       IDM_Test
    End Enum
    
    Global hDlg,hGraphic,hSet,OldGraphicProc,hContext,OldEditProc As Dword, CFN, CFNS As WStringZ * %Max_Path
    Global D() As ChartData, B As ChartSettings, LastX, LastY As Long
    Global CustomColorList As CustomColors, ghHook As Dword, SettingsVisible As Long
    Global SettingsX, SettingsY As Long
    
    Function PBMain() As Long
       Dialog Default Font "Tahoma", 10, 0
       Dialog New Pixels, 0, "gbChartMaster    v" + $Ver,300,300,1100,350, %WS_OverlappedWindow To hDlg
       Dialog Set Icon hDlg, "logo"
       Control Add Graphic, hDlg, %IDC_Graphic,"Push", 0,0,300,200, %SS_Notify
       Control Add Statusbar, hDlg, %IDC_StatusBar,"Welcome to gbChartMaster!",0,0,0,0
       Statusbar Set Parts hDlg, %IDC_StatusBar, 200,200,300,9999
       Control Handle hDlg, %IDC_Graphic To hGraphic
       OldGraphicProc = SetWindowLong(hGraphic, %GWL_WndProc, CodePtr(NewGraphicProc))  'subclass
       Graphic Attach hDlg, %IDC_Graphic, ReDraw
       Dialog Show Modal hDlg Call DlgProc
    End Function
    
    CallBack Function DlgProc() As Long
       Local i,j,w,h,x,y, Flag As Long, MM As MinMaxInfo Ptr, pt As Point, temp$, rc As Rect
       Select Case Cb.Msg
          Case %WM_InitDialog
             Randomize Timer
             If IsFolder (Exe.Path$ + "settings") = %False Then MkDir Exe.Path$ + "settings"
             If IsFolder (Exe.Path$ + "charts") = %False Then MkDir Exe.Path$ + "charts"
             If IsFolder (Exe.Path$ + "stamps") = %False Then MkDir Exe.Path$ + "stamps"
             If IsFolder (Exe.Path$ + "bgimages") = %False Then MkDir Exe.Path$ + "bgimages"
             If IsFolder (Exe.Path$ + "tempfiles") = %False Then MkDir Exe.Path$ + "tempfiles"
             BuildAcceleratorTable
             CreateContextMenu
             LastX = -1
             Settings_INI "get"
             If IsFile(Exe.Path$ + $SessionFile) Then
                OpenChartFile Exe.Path$ + $SessionFile
                Dialog Set Text hDlg, "gbChartMaster    v" + $Ver + "    " + CFN
             Else
                CreateFakeData
                InitializeChart hDlg, %IDC_Graphic
                B.Xmax = 60 : B.Xmin = 10 : B.Pivot = 40
             End If
             Statusbar Set Text hDlg, %IDC_StatusBar, 2, 0, " Right-click to show Settings"
             Statusbar Set Text hDlg, %IDC_StatusBar, 4, 0, Choose$(B.GraphType," 2D Bar", " 3D Bar", " Symbols", " Line", " 2-Line", " 3-Line", " 2-Bar Stacked", " 3-Bar Stacked", " Bar Group", " Pie", " 2-Pie", " 3-Pie", " HiLo") + " Chart"
    
          Case %WM_Destroy
             Settings_INI "save"
             SaveChartFile Exe.Path$ + $SessionFile
    
          Case %WM_GetMinMaxInfo
             MM=Cb.LParam
             @MM.ptMinTrackSize.x=350  '<-- Min X size of your window
             @MM.ptMinTrackSize.y=300  '<-- Min Y size of your window
    
          Case %WM_ContextMenu
             GetCursorPos(pt)
             ScreenToClient(hGraphic,pt)
             Select Case B.GraphType
                Case %Chart_2D, %Chart_3D
                   For i = B.XMin To B.XMax
                      SetRC(rc,i)
                      If PtInRect(rc,pt) Then
                         D(i).Selected(B.DataSet) Xor= 1
                         Flag = 1
                      End If
                   Next i
                   If Flag Then DrawChart D(), B, %True: DisplayStampList
                Case %Chart_2stack
                   For i = B.XMin To B.XMax
                      SetRC(rc,i)
                      If PtInRect(rc,pt) Then
                         D(i).Selected(1) Xor= 1
                         D(i).Selected(2) Xor= 1
                         Flag = 1
                      End If
                   Next i
                   If Flag Then DrawChart D(), B, %True : DisplayStampList
                Case %Chart_3stack
                   For i = B.XMin To B.XMax
                      SetRC(rc,i)
                      If PtInRect(rc,pt) Then
                         D(i).Selected(1) Xor= 1
                         D(i).Selected(2) Xor= 1
                         D(i).Selected(3) Xor= 1
                         Flag = 1
                      End If
                   Next i
                   If Flag Then DrawChart D(), B, %True : DisplayStampList
                Case %Chart_HiLo
                   For i = B.XMin To B.XMax
                      SetRC(rc,i)
                      If PtInRect(rc,pt) Then
                         D(i).Selected(B.DataSet) Xor= 1
                         Flag = 1
                      End If
                   Next i
                   If Flag Then DrawChart D(), B, %True : DisplayStampList
                Case %Chart_Pie
                   For i = B.XMin To B.XMax
                      If PtInEllipse(D(i).rc(B.DataSet), pt, D(i).arcStart(B.DataSet), D(i).arcEnd(B.DataSet)) Then
                         D(i).Selected(B.DataSet) Xor= 1
                         Flag = 1
                      End If
                   Next i
                   If Flag Then DrawChart D(), B, %True : DisplayStampList
                Case %Chart_2Pie
                   For j = 1 To 2
                      For i = B.XMin To B.XMax
                         If PtInEllipse(D(i).rc(j), pt, D(i).arcStart(j), D(i).arcEnd(j)) Then
                            D(i).Selected(j) Xor= 1
                            Flag = 1
                         End If
                      Next i
                   Next j
                   If Flag Then DrawChart D(), B, IIf(j=1,%True,%False) : DisplayStampList
                Case %Chart_3Pie
                   For j = 1 To 3
                      For i = B.XMin To B.XMax
                         If PtInEllipse(D(i).rc(j), pt, D(i).arcStart(j), D(i).arcEnd(j)) Then
                            D(i).Selected(j) Xor= 1
                            Flag = 1
                         End If
                      Next i
                   Next j
                   'If Flag Then DrawChart D(), B, IIf(j=1,%True,%False) : DisplayStampList
                   If Flag Then DrawChart D(), B, %True : DisplayStampList
             End Select
             If Flag = 0 And SettingsVisible = 0 Then ShowSettingsDialog
    
          Case %WM_LButtonDown
             SetCapture hDlg
    
          Case %WM_SetCursor
             If B.HoverTips And Cb.WParam = hGraphic Then
                GetCursorPos(pt)
                ScreenToClient(hGraphic,pt)
                For i = B.XMin To B.XMax
                   Select Case B.GraphType
                      Case %Chart_Pie
                         If PtInEllipse(D(i).rc(B.DataSet), pt, D(i).arcStart(B.DataSet), D(i).arcEnd(B.DataSet)) Then
                            Statusbar Set Text hDlg, %IDC_StatusBar, 2, 0, " X: " + Str$(i) + "    " + D(i).altXText(B.DataSet) + "  Theta: " + Format$(D(i).arcStart(B.DataSet),"##0.0") + "  " + Format$(D(i).arcEnd(B.DataSet),"##0.0")
                            Statusbar Set Text hDlg, %IDC_StatusBar, 3, 0, " Y: " + Str$(D(i).v(B.DataSet)) + "    " + D(i).label(B.DataSet)
                         End If
                      Case %Chart_2Pie
                         For j = 1 To 2
                            If PtInEllipse(D(i).rc(j), pt, D(i).arcStart(j), D(i).arcEnd(j)) Then
                               Statusbar Set Text hDlg, %IDC_StatusBar, 2, 0, " X: " + Str$(i) + "    " + D(i).altXText(j) + "  Theta: " + Format$(D(i).arcStart(j),"##0.0") + "  " + Format$(D(i).arcEnd(j),"##0.0")
                               Statusbar Set Text hDlg, %IDC_StatusBar, 3, 0, " Y: " + Str$(D(i).v(j)) + "    " + D(i).label(j)
                            End If
                         Next j
                      Case %Chart_3Pie
                         For j = 1 To 3
                            If PtInEllipse(D(i).rc(j), pt, D(i).arcStart(j), D(i).arcEnd(j)) Then
                               Statusbar Set Text hDlg, %IDC_StatusBar, 1, 0, " X: " + Str$(i) + "    " + D(i).altXText(j) + "  Theta: " + Format$(D(i).arcStart(j),"##0.0") + "  " + Format$(D(i).arcEnd(j),"##0.0")
                               Statusbar Set Text hDlg, %IDC_StatusBar, 2, 0, " X: " + Str$(i) + "    " + D(i).altXText(j) + "  Theta: " + Format$(D(i).arcStart(j),"##0.0") + "  " + Format$(D(i).arcEnd(j),"##0.0")
                               Statusbar Set Text hDlg, %IDC_StatusBar, 3, 0, " Y: " + Str$(D(i).v(j)) + "    " + D(i).label(j)
                            End If
                         Next j
                      Case %Chart_HiLo
                         SetRC(rc,i)
                         If PtInRect(RC,pt) Then
                            Statusbar Set Text hDlg, %IDC_StatusBar, 2, 0, " X: " + Str$(i) + "    " + D(i).altXText(3) + "  " + D(i).altXText(2)
                            Statusbar Set Text hDlg, %IDC_StatusBar, 3, 0, " Y: " + Str$(D(i).v(3)) + "    " + D(i).label(3) + Str$(D(i).v(2)) + "    " + D(i).label(2)
                         End If
                      Case Else
                         If PtInRect(D(i).rc(B.DataSet),pt) Then
                            Statusbar Set Text hDlg, %IDC_StatusBar, 2, 0, " X: " + Str$(i) + "    " + D(i).altXText(B.DataSet)
                            Statusbar Set Text hDlg, %IDC_StatusBar, 3, 0, " Y: " + Str$(D(i).v(B.DataSet)) + "    " + D(i).label(B.DataSet)
                         End If
                   End Select
                Next i
             End If
    
          Case %WM_Command
             Select Case Cb.Ctl
                Case %IDM_Cut   : SendMessage GetFocus, %WM_CUT, 0, 0
                Case %IDM_Copy  : SendMessage GetFocus, %WM_COPY, 0, 0
                Case %IDM_Paste : SendMessage GetFocus, %WM_PASTE, 0, 0
                Case %IDM_Delete: SendMessage GetFocus, %WM_CLEAR, 0, 0
    
                Case %IDC_Graphic
                   Select Case Cb.CtlMsg
                      Case %STN_DblClk
                         Graphic Get Canvas To w,h
                         GetCursorPos(pt)
                         ScreenToClient(B.hGraphic,pt)
                         If pt.x < 40 And pt.y < 40 Then
                            B.StampList = ""
                            DrawChart D(), B, %True : DisplayStampList
                         ElseIf pt.x > w-40 And pt.y < 40 Then
                            For i = 1 To UBound(D) : D(i).Selected(1) = 0 : D(i).Selected(2) = 0 : D(i).Selected(3) = 0 : Next i
                         ElseIf pt.x > w-40 And pt.y > h-40 Then
                            If SettingsVisible = 0 Then ShowSettingsDialog
                         ElseIf pt.x < 40 And pt.y > h-40 Then
                            If SettingsVisible = 0 Then ShowSettingsDialog
                            Dialog Set Loc hSet, 200,200
                         Else
                            B.StampList += ";;;" + Str$(pt.x) +  "," + Str$(pt.y) + "," + B.stamp + "," + IIf$(B.LargeStamp,"1","2")
                            DisplayStampList
                         End If
                         DrawChart D(), B, %True : DisplayStampList
    
                      Case %STN_Clicked
                         GetCursorPos(pt)
                         ScreenToClient(B.hGraphic,pt)
                         If pt.x < 40 And pt.y < 40 Then EraseLastStamp
                   End Select
    
                Case %IDM_NextBGImage
                   B.BGImage = NextFile((B.BGImage),"*.*")
                   LoadBGImage ((B.BGImage), B.hBGImage)  'Graphic Bitmap Load B.BGimage, 0, 0 To B.hBGImage
                   DrawChart D(), B, %True : DisplayStampList
                   If SettingsVisible Then Dialog End hSet : ShowSettingsDialog
    
                Case %IDM_NextChart
                   CFN = NextFile((CFN),"*.gbc")
                    Dialog Set Text hDlg, "gbChartMaster    v" + $Ver + "    " + CFN
                    OpenChartFile((CFN))
                    DrawChart D(), B, %True : DisplayStampList
                    If SettingsVisible Then Dialog End hSet : ShowSettingsDialog
    
                Case %IDM_EraseLastStamp  : EraseLastStamp
                Case %IDM_Escape          : Dialog End hSet
                Case %IDM_SaveAs          : SaveChartAs
                Case %IDM_Open            : SelectChartToOpen
                Case %IDM_AutoXCount      : B.AutoXCount Xor= 1
    
                Case %IDM_ExportToGBC
                   GDIPlus_SaveImage B.hGraphicDC, "jpg", Left$(CFN, Len(CFN)-3) + "jpg"
                   temp$ = PathName$(Path,CFN)
                   i = ShellExecute(hDlg, "Open", (temp$), $Nul, $Nul, %SW_ShowNormal)
                   Sleep 500
                   SetForeGroundWindow hDlg
    
                Case %IDM_CopyImage
                   Clipboard Reset : Clipboard Set Bitmap B.hGraphic
                   sndPlaySound("xcamera", %SND_Async Or %SND_Resource)
    
                Case %IDM_UnSelectBars
                   For i = 1 To UBound(D) : D(i).selected(B.DataSet) = 0 : Next i
                   DrawChart D(), B, %True : DisplayStampList
    
                Case %IDM_GraphType
                   Incr B.GraphType
                   If B.GraphType > %Chart_3Pie Then B.GraphType = %Chart_2D : SetFontButtonText
                   DrawChart D(), B, %True : DisplayStampList
                   If SettingsVisible Then ComboBox Select hSet, %IDC_GraphType, B.GraphType
                   Statusbar Set Text hDlg, %IDC_StatusBar, 4, 0, Choose$(B.GraphType," 2D Bar", " 3D Bar", " Symbols", " Line", " 2-Line", " 3-Line", " 2-Bar Stacked", " 3-Bar Stacked", " Bar Group", " Pie", " 2-Pie", " 3-Pie", " HiLo") + " Chart"
    
                Case %IDM_Export
                   GDIPlus_SaveImage B.hGraphicDC, Choose$(B.ExportFormat,"bmp","jpg","gif","png"), Exe.Path$ + "tempfiles\gbchartmaster." + Choose$(B.ExportFormat,"bmp","jpg","gif","png")
                   i = ShellExecute(hDlg, "Open", (Exe.Path$ + "tempfiles"), $Nul, $Nul, %SW_ShowNormal)
    
                Case %IDM_BarGradient
                   Incr B.BarGradientType
                   If B.BarGradientType > %Gradient_ColorCenterToBlackSide Then B.BarGradientType = %Gradient_None
                   DrawChart D(), B, %True : DisplayStampList
                   If SettingsVisible Then ComboBox Select hSet, %IDC_BarGradientType, B.BarGradientType
    
                Case %IDM_Image
                   B.ShowBGImage Xor=1
                   DrawChart D(), B, %True : DisplayStampList
                   If SettingsVisible Then Dialog End hSet : ShowSettingsDialog
    
                Case %IDM_BarLabels
                   B.ShowBarLabel Xor= 1
                   DrawChart D(), B, %True : DisplayStampList
                   If SettingsVisible Then Dialog End hSet : ShowSettingsDialog
    
                Case %IDM_SpeedTest
                   B.SpeedTest Xor= 1
                   DrawChart D(), B, %True : DisplayStampList
                   If B.SpeedTest = 0 Then Dialog Set Text hDlg, "gbChartMaster    v" + $Ver + "    " + CFN
    
                Case %IDM_Instructions
                   B.Instructions Xor= 1
                   DrawChart D(), B, %True : DisplayStampList
                   If SettingsVisible Then Dialog End hSet : ShowSettingsDialog
    
                Case %IDM_ShowMargins
                   B.ShowMargins Xor= 1
                   DrawChart D(), B, %True : DisplayStampList
                   If SettingsVisible Then Dialog End hSet : ShowSettingsDialog
    
                Case %IDM_Radar
                   If SettingsVisible = 0 Then ShowSettingsDialog
                   Dialog Set Loc hSet, 200,200
    
                Case %IDM_Reset
                   CreateFakeData
                   InitializeChart hDlg, %IDC_Graphic
                   B.Xmax = 60 : B.Xmin = 10 : B.Pivot = 40
                   DrawChart D(), B, %True : DisplayStampList
                   Statusbar Set Text hDlg, %IDC_StatusBar, 2, 0, ""
                   Statusbar Set Text hDlg, %IDC_StatusBar, 3, 0, ""
    
                Case %IDM_Help
                   i = ShellExecute(hDlg, "Open", ("http://www.garybeene.com/sw/gbchartmaster.htm"), $Nul, $Nul, %SW_ShowNormal)
    
                Case %IDM_Settings
                   If SettingsVisible = 0 Then ShowSettingsDialog
    
                Case %IDM_Test
    '               For i = 1 to 5 : D(i).selected(1) = 0 : next i
                   ? Str$(D(1).selected(1)) + Str$(D(2).selected(1)) + Str$(D(3).selected(1)) + Str$(D(4).selected(1)) + Str$(D(5).selected(1))
    
    
             End Select
          Case %WM_Size
             Dialog Get Client hDlg To w,h
             Control Set Client hDlg, %IDC_Graphic, w,h-25
             DrawChart D(), B, %True : DisplayStampList
       End Select
    End Function
    
    Sub BuildAcceleratorTable
       Local c As Long, ac() As ACCELAPI, hAccelerator As Dword  ' for keyboard accelator table values
       Dim ac(22)
       ac(c).fvirt = %FVIRTKEY              : ac(c).key   = %VK_F1 : ac(c).cmd  = %IDM_Help           : Incr c
       ac(c).fvirt = %FVIRTKEY              : ac(c).key   = %VK_Escape : ac(c).cmd   = %IDM_Escape    : Incr c
       ac(c).fvirt = %FVIRTKEY Or %FCONTROL : ac(c).key   = %VK_A : ac(c).cmd   = %IDM_Instructions   : Incr c
       ac(c).fvirt = %FVIRTKEY Or %FCONTROL : ac(c).key   = %VK_B : ac(c).cmd   = %IDM_NextBGImage    : Incr c
       ac(c).fvirt = %FVIRTKEY Or %FCONTROL : ac(c).key   = %VK_D : ac(c).cmd   = %IDM_Settings       : Incr c
       ac(c).fvirt = %FVIRTKEY Or %FCONTROL : ac(c).key   = %VK_E : ac(c).cmd   = %IDM_EraseLastStamp : Incr c
       ac(c).fvirt = %FVIRTKEY Or %FCONTROL : ac(c).key   = %VK_F : ac(c).cmd   = %IDM_GraphType      : Incr c
       ac(c).fvirt = %FVIRTKEY Or %FCONTROL : ac(c).key   = %VK_G : ac(c).cmd   = %IDM_BarGradient    : Incr c
       ac(c).fvirt = %FVIRTKEY Or %FCONTROL : ac(c).key   = %VK_H : ac(c).cmd   = %IDM_Help           : Incr c
       ac(c).fvirt = %FVIRTKEY Or %FCONTROL : ac(c).key   = %VK_I : ac(c).cmd   = %IDM_Image          : Incr c
       ac(c).fvirt = %FVIRTKEY Or %FCONTROL : ac(c).key   = %VK_J : ac(c).cmd   = %IDM_AutoXCount     : Incr c
       ac(c).fvirt = %FVIRTKEY Or %FCONTROL : ac(c).key   = %VK_K : ac(c).cmd   = %IDM_SpeedTest      : Incr c
       ac(c).fvirt = %FVIRTKEY Or %FCONTROL : ac(c).key   = %VK_L : ac(c).cmd   = %IDM_BarLabels      : Incr c
       ac(c).fvirt = %FVIRTKEY Or %FCONTROL : ac(c).key   = %VK_M : ac(c).cmd   = %IDM_ShowMargins    : Incr c
       ac(c).fvirt = %FVIRTKEY Or %FCONTROL : ac(c).key   = %VK_N : ac(c).cmd   = %IDM_Reset          : Incr c
       ac(c).fvirt = %FVIRTKEY Or %FCONTROL : ac(c).key   = %VK_O : ac(c).cmd   = %IDM_Open           : Incr c
       ac(c).fvirt = %FVIRTKEY Or %FCONTROL : ac(c).key   = %VK_Q : ac(c).cmd   = %IDM_NextChart      : Incr c
       ac(c).fvirt = %FVIRTKEY Or %FCONTROL : ac(c).key   = %VK_R : ac(c).cmd   = %IDM_Radar          : Incr c
       ac(c).fvirt = %FVIRTKEY Or %FCONTROL : ac(c).key   = %VK_S : ac(c).cmd   = %IDM_SaveAs         : Incr c
       ac(c).fvirt = %FVIRTKEY Or %FCONTROL : ac(c).key   = %VK_T : ac(c).cmd   = %IDM_Test           : Incr c
       ac(c).fvirt = %FVIRTKEY Or %FCONTROL : ac(c).key   = %VK_U : ac(c).cmd   = %IDM_UnSelectBars   : Incr c
       ac(c).fvirt = %FVIRTKEY Or %FCONTROL : ac(c).key   = %VK_W : ac(c).cmd   = %IDM_ExportToGBC    : Incr c
       ac(c).fvirt = %FVIRTKEY Or %FCONTROL : ac(c).key   = %VK_Y : ac(c).cmd   = %IDM_CopyImage      : Incr c
       Accel Attach hDlg, AC() To hAccelerator
    End Sub
    
    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).altXText(1)  = "AltX" + 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).altXText(2)  = "AltX" + 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).altXText(3)  = "AltX" + 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).label(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).label(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).label(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            = 110
       B.RM            = 80
       B.TM            = 60
       B.BM            = 50
       B.Title         = "gbChartMaster"
       B.XTitle        = "X-Values"
       B.YTitle        = "Y-Values"
       B.MainTitleLoc  = %MainTitle_Center
       B.XTitleLoc     = %XTitle_LeftInline
       B.YTitleLoc     = %YTitle_Top
       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.ShowHGrid     = 1
       B.ShowVGrid     = 0
       B.ShowMargins   = 0
       B.DotGrid       = 0
       B.ShowMainTitle   = 1
       B.ShowAxisTitles  = 1
       B.ShowAxisValues  = 1
       B.UseAntiAliasing = 0
       B.HoverTips       = 1
       B.GridOnTop       = 0
       B.SmoothLines     = 0
       B.LineStyle       = 0
       B.LabelType       = 1
    
       B.UserData(1)   = "60" + $CrLf    + "40" + $CrLf    + "90" + $CrLf    + "160" + $CrLf     + "120"
       B.altXText(1)    = "One" + $CrLf   + "Four" + $CrLf  + "Nine" + $CrLf  + "Twenty" + $CrLf  + "Twelve"
       B.labels(1)  = "Plum" + $CrLf  + "Peach" + $CrLf + "Pear" + $CrLf  + "Apple" + $CrLf   + "Orange"
       B.BarColors(1)  = "192 48 158" + $CrLf  + "102 222 45" + $CrLf + "142 220 15" + $CrLf  + "121 184 234" + $CrLf   + "226 88 130"
    
       B.UserData(2)   = "35" + $CrLf     + "32" + $CrLf    + "70" + $CrLf    + "85" + $CrLf     + "115"
       B.altXText(2)    = "Left" + $CrLf  + "Right" + $CrLf + "Top" + $CrLf   + "Bottom" + $CrLf  + "Center"
       B.labels(2)  = "Oak" + $CrLf   + "Elm" + $CrLf   + "Birch" + $CrLf + "Redwood" + $CrLf + "Magnolia"
       B.BarColors(2)  = "135 129 160" + $CrLf  + "199 201 147" + $CrLf + "73 156 143" + $CrLf  + "47 101 147" + $CrLf   + "192 165 108"
    
       B.UserData(3)   = "80" + $CrLf    + "43" + $CrLf    + "120" + $CrLf   + "95" + $CrLf     + "132"
       B.altXText(3)    = "North" + $CrLf + "South" + $CrLf + "East" + $CrLf  + "West" + $CrLf    + "None"
       B.labels(3)  = "Pigs" + $CrLf  + "Cows" + $CrLf  + "Sheep" + $CrLf + "Horses" + $CrLf  + "Goats"
       B.BarColors(3)  = "212 194 232" + $CrLf  + "125 213 176" + $CrLf + "52 207 47" + $CrLf  + "80 246 63" + $CrLf   + "88 117 160"
    
       B.GraphType     = 1        '1=2D 2=3D 3=Line 4=DOT
       B.BarGradientType  = 1        '1=flat
       B.ThreeDX       = 15
       B.ThreeDY       = 20
    
       B.BezierTension = 0.5
       B.BezierDT      = 0.01
    
       B.PieRadius     = 75    '% of client area
       B.PieCircle     = 1
       B.PieEject      = 1
       B.PieExplode    = 0
       B.PieExplodeDistance = 10
       B.PieRotate     = 0
       B.PieAngle      = 90
       B.PieLegend     = 1
       B.PiePerCent    = 1
       B.PieDonut      = 0
       B.PieDonutCaption(1) = "Center 1"
       B.PieDonutCaption(2) = "Center 2"
       B.PieDonutCaption(3) = "Center 3"
       B.PieBeveled     = 0
       B.Pie3D          = 0
       B.Pie3DThickness = 60
       B.PieGradient    = 0
       B.PieGradientValue = 155
       B.PieHideUnSelected = 0
       B.PieHighlightSelected = 1
    
       B.InstructFontName = "Tahoma"
       B.InstructFontSize = 10
       B.InstructFontBold = 0
    
       B.titleFontName = "Tahoma"
       B.titleFontSize = 14
       B.titleFontBold = 1
    
       B.axisTitleFontName = "Tahoma"
       B.axisTitleFontSize = 10
       B.axisTitleFontBold = 1
    
       B.LabelFontName = "Tahoma"
       B.LabelFontSize = 10
       B.LabelFontBold = 1
    
       B.DataSet           = 1
    
       B.axisValueFontName = "Tahoma"
       B.axisValueFontSize = 10
       B.axisValueFontBold = 0
    
       B.useAltColors   = 0
       B.usealtXText     = 0
       B.gradientBG     = 0
       B.fadeBG         = 0
       B.colorUnder     = 0
    
       B.cGrid         = %Black
       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.RoundValue    = 100
       B.MinusYAxis    = 0
       B.VertYTitle    = 0
       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.HiLoSymbol    = 1
       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.axisTitleFontBold
       Font End B.axisTitleFontR
    
       Font End B.InstructFont
    
       Font End B.axisValueFont
       Font End B.axisValueFontBold
       Font End B.axisValueFontR
    
       Font End B.LabelFont
       Font End B.LabelFontR
    
       'rebuild fonts
       Font New B.InstructFontName,  B.InstructFontSize,  B.InstructFontBold  To B.InstructFont
    
       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.axisValueFontName, B.axisValueFontSize, B.axisValueFontBold To B.axisValueFont
       Font New B.LabelFontName,     B.LabelFontSize,     B.LabelFontBold     To B.LabelFont
    
       Font New B.axisTitleFontName, B.axisTitleFontSize, B.axisTitleFontBold,1,0, 900 To B.axisTitleFontR
       Font New B.axisValueFontName, B.axisValueFontSize, B.axisValueFontBold,1,0, 900 To B.axisValueFontR
       Font New B.LabelFontName,     B.LabelFontSize,     B.LabelFontBold,1,0, 900 To B.LabelFontR
    End Sub
    
    Function SelectColor(hWnd As Dword, startcolor&) As Long    'works on pControl
       Local ColorResult&
       Display Color hWnd, 200, 200, startcolor&, CustomColorList ,0 To ColorResult&
       If ColorResult& = -1 Then Function = startcolor& Else Function = ColorResult&
    End Function
    
    Sub SelectMainFont(FontName As StringZ * 100, FontSize As Long, FontBold As Long, hNewFont As Dword)
       Local fName As String, fPoints, fStyle, fColor, CharSet, Style As Long
       Style = %CF_ForceFontExist Or %CF_NoScriptSel Or %CF_NoSimulations Or %CF_ScreenFonts 'Or %CF_FixedPitchOnly 'OR %CF_ScreenFonts Or
       ghHook = SetWindowsHookEx(%WH_CBT, CodePtr(FontDialogProc), GetModuleHandle(""), GetCurrentThreadId)
       Display Font hSet, 100,100, FontName, FontSize, FontBold, Style To fName, fPoints, fStyle, fColor, CharSet
       UnhookWindowsHookEx ghHook
       If Len(fName) Then FontName = fName : FontSize = fPoints : FontBold = fStyle
    End Sub
    
    Function FontDialogProc(ByVal nCode As Long, ByVal WParam As Long, ByVal LParam As Long) As Long
        Local szTemp As WStringZ * %Max_Path, cw As CBT_CREATEWND Ptr, cst As CREATESTRUCT Ptr
        Function = CallNextHookEx(ByVal ghHook, ByVal nCode, ByVal WParam, ByVal LParam)
        If nCode < 0 Then Exit Function
        If nCode = %HCBT_ACTIVATE Then UnhookWindowsHookEx ghHook
        If nCode = %HCBT_CREATEWND Then
            cw = LParam         ' Get pointer to CBT_CREATEWND struct so we can...    TT: Nick Melnick
            cst = @cw.lpcs      ' get a pointer to the CREATESTRUCT struct
            GetClassName WParam, szTemp, %Max_Path      ' for each window / control as it is created
            If UCase$(szTemp) = "#32770" Then @cst.cy = @cst.cy - 165 : @cst.cx = @cst.cx - 10  'dialog
        End If
    End Function
    
    Sub ShowSettingsDialog
       Local i,w,h,x,y,iPos,iStyle As Long, temp$
       SettingsVisible = 1
    
       'make sure it is visible
       'Desktop Get Client to w,h
       'If SettingsX > w Then SettingsX = w - 100
       'IF SettingsY > h Then SettingsY = h - 100
       'IF SettingsX + 1220 < 0 Then SettingsX = 100
       'If SettingsY + 520  < 0 THen SettingsY = 100
    
       iStyle = %WS_Child Or %WS_Visible Or %ES_MultiLine Or %WS_VScroll Or %ES_AutoHScroll Or %WS_HScroll Or %ES_AutoVScroll Or %ES_WantReturn Or %ES_NoHideSel Or %WS_TabStop
       Dialog Font "Tahoma",10,0
    
       Desktop Get Size To w,h
       Dialog Get Loc hDlg To x,y
       If x+SettingsX < 0 Then SettingsX = 50 - x
       If y+SettingsY > h Then SettingsY = h - y - 200
    
       Dialog New Pixels, hDlg, "gbChartMaster Settings",SettingsX,SettingsY,1220,520, %WS_SysMenu To hSet
       Dialog Set Icon hSet, "xsettings"
    
       'optional display
       Control Add Frame, hSet, %IDC_Frame, "Elements",10,10,120,365
       Control Add ComboBox, hSet, %IDC_GraphType,,20,35,105,400,%CBS_DropDownList Or %WS_TabStop Or %WS_VScroll, %WS_Ex_ClientEdge
       ComboBox Add hSet, %IDC_GraphType, "2D Bars"
       ComboBox Add hSet, %IDC_GraphType, "3D Bars"
       ComboBox Add hSet, %IDC_GraphType, "Symbols"
       ComboBox Add hSet, %IDC_GraphType, "Line"
       ComboBox Add hSet, %IDC_GraphType, "2-Line"
       ComboBox Add hSet, %IDC_GraphType, "3-Line"
       ComboBox Add hSet, %IDC_GraphType, "2-Bar Stacked"
       ComboBox Add hSet, %IDC_GraphType, "3-Bar Stacked"
       ComboBox Add hSet, %IDC_GraphType, "Hi-Lo Bars"
       ComboBox Add hSet, %IDC_GraphType, "Pie Chart"
       ComboBox Add hSet, %IDC_GraphType, "2-Pie Chart"
       ComboBox Add hSet, %IDC_GraphType, "3-Pie Chart"
       ComboBox Select hSet, %IDC_GraphType, B.GraphType
    
       Control Add CheckBox, hSet, %IDC_AllBars,"All Bars",20,70,100,20
       Control Set Check hSet, %IDC_AllBars, B.AllBars
       Control Add CheckBox, hSet, %IDC_ShowMainTitle,"Title",20,90,100,20
       Control Set Check hSet, %IDC_ShowMainTitle, B.ShowMainTitle
       Control Add CheckBox, hSet, %IDC_ShowAxisTitles,"Axis Titles",20,110,100,20
       Control Set Check hSet, %IDC_ShowAxisTitles, B.ShowAxisTitles
       Control Add CheckBox, hSet, %IDC_ShowAxisValues,"X-Axis Values",20,130,100,20
       Control Set Check hSet, %IDC_ShowAxisValues, B.ShowAxisValues
       Control Add CheckBox, hSet, %IDC_ShowBarLabel,"Labels",20,150,100,20
       Control Set Check hSet, %IDC_ShowBarLabel, B.ShowBarLabel
       Control Add CheckBox, hSet, %IDC_UseAltColors,"Alt Colors",20,170,100,20
       Control Set Check hSet, %IDC_UseAltColors, B.UseAltColors
       Control Add CheckBox, hSet, %IDC_UsealtXText,"Alt XText",20,190,100,20
       Control Set Check hSet, %IDC_UsealtXText, B.UsealtXText
       Control Add CheckBox, hSet, %IDC_ShowBGImage,"BG Image",20,210,100,20
       Control Set Check hSet, %IDC_ShowBGImage, B.ShowBGImage
       Control Add CheckBox, hSet, %IDC_Annotation,"Annotation",20,230,100,20
       Control Set Check hSet, %IDC_Annotation, B.Annotation
       Control Add CheckBox, hSet, %IDC_ShowDataSetTitles,"DataSet Titles",20,250,100,20
       Control Set Check hSet, %IDC_ShowDataSetTitles, B.ShowDataSetTitles
       Control Add CheckBox, hSet, %IDC_ShowHGrid,"Horz Grid",20,270,100,20
       Control Set Check hSet, %IDC_ShowHGrid, B.ShowHGrid
       Control Add CheckBox, hSet, %IDC_ShowVGrid,"Vert Grid",20,290,100,20
       Control Set Check hSet, %IDC_ShowVGrid, B.ShowVGrid
       Control Add CheckBox, hSet, %IDC_ShowMargins,"Margins",20,310,100,20
       Control Set Check hSet, %IDC_ShowMargins, B.ShowMargins
       Control Add CheckBox, hSet, %IDC_SpeedTest,"Speed Test",20,330,100,20
       Control Set Check hSet, %IDC_SpeedTest, B.SpeedTest
       Control Add CheckBox, hSet, %IDC_Instructions,"Instructions",20,350,100,20
       Control Set Check hSet, %IDC_Instructions, B.Instructions
    
       'Titles
       Control Add Frame, hSet, %IDC_Frame, "Titles/Labels",140,10,160,365
       Control Add TextBox, hSet, %IDC_Title,  B.Title, 150,30,100,20
       Control Add TextBox, hSet, %IDC_XTitle, B.XTitle, 150,55,100,20
       Control Add TextBox, hSet, %IDC_YTitle, B.YTitle, 150,80,100,20
       Control Add Label, hSet, %IDC_Label, "Title",255,30,40,140
       Control Add Label, hSet, %IDC_Label, "XTitle",255,55,40,140
       Control Add Label, hSet, %IDC_Label, "YTitle",255,80,40,140
       'Font
       Control Add Button, hSet, %IDC_TitleFont,"Chart Title Font", 150,105,100,20
       Control Add Button, hSet, %IDC_axisTitleFont,"Axis Title Font", 150,130,100,20
       Control Add Button, hSet, %IDC_axisValueFont,"Axis Values Font", 150,155,100,20
       Control Add Button, hSet, %IDC_LabelFont,"Label Font", 150,180,100,20
    
       Control Add ComboBox, hSet, %IDC_MainTitleFontSize,,255,105,40,150,%CBS_DropDownList Or %WS_TabStop Or %WS_VScroll, %WS_Ex_ClientEdge
       ComboBox Add hSet, %IDC_MainTitleFontSize, "8"
       ComboBox Add hSet, %IDC_MainTitleFontSize, "10"
       ComboBox Add hSet, %IDC_MainTitleFontSize, "12"
       ComboBox Add hSet, %IDC_MainTitleFontSize, "14"
       ComboBox Add hSet, %IDC_MainTitleFontSize, "16"
       ComboBox Add hSet, %IDC_MainTitleFontSize, "18"
       ComboBox Add hSet, %IDC_MainTitleFontSize, "20"
       ComboBox Add hSet, %IDC_MainTitleFontSize, "22"
       ComboBox Add hSet, %IDC_MainTitleFontSize, "24"
       ComboBox Add hSet, %IDC_MainTitleFontSize, "26"
       ComboBox Add hSet, %IDC_MainTitleFontSize, "28"
       ComboBox Add hSet, %IDC_MainTitleFontSize, "36"
       ComboBox Add hSet, %IDC_MainTitleFontSize, "48"
       i = Switch(B.TitleFontSize=8,1,B.TitleFontSize=10,2,B.TitleFontSize=12,3,B.TitleFontSize=14,4,B.TitleFontSize=16,5,B.TitleFontSize=18,6,B.TitleFontSize=20,7,B.TitleFontSize=22,8, _
           B.TitleFontSize=24,9,B.TitleFontSize=26,10,B.TitleFontSize=28,11,B.TitleFontSize=36,12,B.TitleFontSize=48,13)
       ComboBox Select hSet, %IDC_MainTitleFontSize, i
    
    
       Control Add ComboBox, hSet, %IDC_AxisTitleFontSize,,255,130,40,150,%CBS_DropDownList Or %WS_TabStop Or %WS_VScroll, %WS_Ex_ClientEdge
       ComboBox Add hSet, %IDC_AxisTitleFontSize, "8"
       ComboBox Add hSet, %IDC_AxisTitleFontSize, "10"
       ComboBox Add hSet, %IDC_AxisTitleFontSize, "12"
       ComboBox Add hSet, %IDC_AxisTitleFontSize, "14"
       ComboBox Add hSet, %IDC_AxisTitleFontSize, "16"
       ComboBox Add hSet, %IDC_AxisTitleFontSize, "18"
       ComboBox Add hSet, %IDC_AxisTitleFontSize, "20"
       ComboBox Add hSet, %IDC_AxisTitleFontSize, "22"
       ComboBox Add hSet, %IDC_AxisTitleFontSize, "24"
       ComboBox Add hSet, %IDC_AxisTitleFontSize, "26"
       ComboBox Add hSet, %IDC_AxisTitleFontSize, "28"
       ComboBox Add hSet, %IDC_AxisTitleFontSize, "36"
       ComboBox Add hSet, %IDC_AxisTitleFontSize, "48"
       i = Switch(B.AxisTitleFontSize=8,1,B.AxisTitleFontSize=10,2,B.AxistitleFontSize=12,3,B.AxisTitleFontSize=14,4,B.AxisTitleFontSize=16,5,B.AxisTitleFontSize=18,6,B.AxisTitleFontSize=20,7,B.AxisTitleFontSize=22,8, _
           B.AxisTitleFontSize=24,9,B.AxisTitleFontSize=26,10,B.AxisTitleFontSize=28,11,B.AxisTitleFontSize=36,12,B.AxisTitleFontSize=48,13)
       ComboBox Select hSet, %IDC_AxisTitleFontSize, i
    
       Control Add ComboBox, hSet, %IDC_ValuesFontSize,,255,155,40,150,%CBS_DropDownList Or %WS_TabStop Or %WS_VScroll, %WS_Ex_ClientEdge
       ComboBox Add hSet, %IDC_ValuesFontSize, "8"
       ComboBox Add hSet, %IDC_ValuesFontSize, "10"
       ComboBox Add hSet, %IDC_ValuesFontSize, "12"
       ComboBox Add hSet, %IDC_ValuesFontSize, "14"
       ComboBox Add hSet, %IDC_ValuesFontSize, "16"
       ComboBox Add hSet, %IDC_ValuesFontSize, "18"
       ComboBox Add hSet, %IDC_ValuesFontSize, "20"
       ComboBox Add hSet, %IDC_ValuesFontSize, "22"
       ComboBox Add hSet, %IDC_ValuesFontSize, "24"
       ComboBox Add hSet, %IDC_ValuesFontSize, "26"
       ComboBox Add hSet, %IDC_ValuesFontSize, "28"
       ComboBox Add hSet, %IDC_ValuesFontSize, "36"
       ComboBox Add hSet, %IDC_ValuesFontSize, "48"
       i = Switch(B.AxisValueFontSize=8,1,B.AxisValueFontSize=10,2,B.AxisValueFontSize=12,3,B.AxisValueFontSize=14,4,B.AxisValueFontSize=16,5,B.AxisValueFontSize=18,6,B.AxisValueFontSize=20,7,B.AxisValueFontSize=22,8, _
           B.AxisValueFontSize=24,9,B.AxisValueFontSize=26,10,B.AxisValueFontSize=28,11,B.AxisValueFontSize=36,12,B.AxisValueFontSize=48,13)
       ComboBox Select hSet, %IDC_ValuesFontSize, i
    
       Control Add ComboBox, hSet, %IDC_LabelFontSize,,255,180,40,150,%CBS_DropDownList Or %WS_TabStop Or %WS_VScroll, %WS_Ex_ClientEdge
       ComboBox Add hSet, %IDC_LabelFontSize, "8"
       ComboBox Add hSet, %IDC_LabelFontSize, "10"
       ComboBox Add hSet, %IDC_LabelFontSize, "12"
       ComboBox Add hSet, %IDC_LabelFontSize, "14"
       ComboBox Add hSet, %IDC_LabelFontSize, "16"
       ComboBox Add hSet, %IDC_LabelFontSize, "18"
       ComboBox Add hSet, %IDC_LabelFontSize, "20"
       ComboBox Add hSet, %IDC_LabelFontSize, "22"
       ComboBox Add hSet, %IDC_LabelFontSize, "24"
       ComboBox Add hSet, %IDC_LabelFontSize, "26"
       ComboBox Add hSet, %IDC_LabelFontSize, "28"
       ComboBox Add hSet, %IDC_LabelFontSize, "36"
       ComboBox Add hSet, %IDC_LabelFontSize, "48"
       i = Switch(B.LabelFontSize=8,1,B.LabelFontSize=10,2,B.LabelFontSize=12,3,B.LabelFontSize=14,4,B.LabelFontSIze=16,5,B.LabelFontSize=18,6,B.LabelFontSize=20,7,B.LabelFontSize=22,8, _
           B.LabelFontSize=24,9,B.LabelFontSize=26,10,B.LabelFontSize=28,11,B.LabelFontSize=36,12,B.LabelFontSize=48,13)
       ComboBox Select hSet, %IDC_LabelFontSize, i
    
       'misc
       Control Add Label, hSet, %IDC_Label, "Main      XTitle     YTitle",255,210,40,100
    
       Control Add ComboBox, hSet, %IDC_MainTitleLoc,,150,205,100,150,%CBS_DropDownList Or %WS_TabStop Or %WS_VScroll, %WS_Ex_ClientEdge
       ComboBox Add hSet, %IDC_MainTitleLoc, "Left"
       ComboBox Add hSet, %IDC_MainTitleLoc, "Center"
       ComboBox Add hSet, %IDC_MainTitleLoc, "Right"
       ComboBox Select hSet, %IDC_MainTitleLoc, B.MainTitleLoc
    
       Control Add ComboBox, hSet, %IDC_XTitleLoc,,150,235,100,150,%CBS_DropDownList Or %WS_TabStop Or %WS_VScroll, %WS_Ex_ClientEdge
       ComboBox Add hSet, %IDC_XTitleLoc, "Left Inline"
       ComboBox Add hSet, %IDC_XTitleLoc, "Left"
       ComboBox Add hSet, %IDC_XTitleLoc, "Center"
       ComboBox Add hSet, %IDC_XTitleLoc, "Right"
       ComboBox Add hSet, %IDC_XTitleLoc, "RightInline"
       ComboBox Select hSet, %IDC_XTitleLoc, B.XTitleLoc
    
       Control Add ComboBox, hSet, %IDC_YTitleLoc,,150,265,100,150,%CBS_DropDownList Or %WS_TabStop Or %WS_VScroll, %WS_Ex_ClientEdge
       ComboBox Add hSet, %IDC_YTitleLoc, "Top"
       ComboBox Add hSet, %IDC_YTitleLoc, "Center"
       ComboBox Add hSet, %IDC_YTitleLoc, "Bottom"
       ComboBox Select hSet, %IDC_YTitleLoc, B.YTitleLoc
    
       Control Add CheckBox, hSet, %IDC_VertYTitle,"Vert Y Title",150,293,100,20
       Control Set Check hSet, %IDC_VertYTitle, B.VertYTitle
    
       Control Add CheckBox, hSet, %IDC_VertBarLabels,"Vert Bar Labels",150,313,110,20
       Control Set Check hSet, %IDC_VertBarLabels, B.VertBarLabels
    
       Control Add CheckBox, hSet, %IDC_AutoXCount, "Auto X Count",150,333,100,20
       Control Set Check hSet, %IDC_AutoXCount, B.AutoXCount
    
    '   'Control Add CheckBox, hSet, %IDC_MinusYAxis,"-Y Axis",285,200,100,20
    '   'Control Set Check hSet, %IDC_MinusYAxis, B.MinusYAxis
    
       'Colors
       Control Add Frame, hSet, %IDC_Frame, "Colors",310,10,150,365
    
       Control Add Label, hSet, %IDC_cBG, "", 320,30,12,12, %WS_Border Or %SS_Notify
       Control Set Color hSet, %IDC_cBG, %Black, B.cBG
    
       Control Add Label, hSet, %IDC_cTitle, "", 320,47,12,12, %WS_Border Or %SS_Notify
       Control Set Color hSet, %IDC_cTitle, %Black, B.cTitle
    
       Control Add Label, hSet, %IDC_cAxisLines, "", 320,64,12,12, %WS_Border Or %SS_Notify
       Control Set Color hSet, %IDC_cAxisLines, %Black, B.cAxisLines
    
       Control Add Label, hSet, %IDC_cAxisValues, "", 320,81,12,12, %WS_Border Or %SS_Notify
       Control Set Color hSet, %IDC_cAxisValues, %Black, B.cAxisValues
    
       Control Add Label, hSet, %IDC_cGrid, "", 320,98,12,12, %WS_Border Or %SS_Notify
       Control Set Color hSet, %IDC_cGrid, %Black, B.cGrid
    
       Control Add Label, hSet, %IDC_Label, "BkGnd    Title   AxisLines   AxisValues    Grid",340,30,70,120
    
       Control Add Label, hSet, %IDC_cPreBars1, "", 320,122,12,12, %WS_Border Or %SS_Notify
       Control Set Color hSet, %IDC_cPreBars1, %Black, B.cPreBars(1)
       Control Add Label, hSet, %IDC_cPreBars2, "", 340,122,12,12, %WS_Border Or %SS_Notify
       Control Set Color hSet, %IDC_cPreBars2, %Black, B.cPreBars(2)
       Control Add Label, hSet, %IDC_cPreBars3, "", 360,122,12,12, %WS_Border Or %SS_Notify
       Control Set Color hSet, %IDC_cPreBars3, %Black, B.cPreBars(3)
    
       Control Add Label, hSet, %IDC_cPostBars1, "", 320,139,12,12, %WS_Border Or %SS_Notify
       Control Set Color hSet, %IDC_cPostBars1, %Black, B.cPostBars(1)
       Control Add Label, hSet, %IDC_cPostBars2, "", 340,139,12,12, %WS_Border Or %SS_Notify
       Control Set Color hSet, %IDC_cPostBars2, %Black, B.cPostBars(2)
       Control Add Label, hSet, %IDC_cPostBars3, "", 360,139,12,12, %WS_Border Or %SS_Notify
       Control Set Color hSet, %IDC_cPostBars3, %Black, B.cPostBars(3)
    
       Control Add Label, hSet, %IDC_cSymbols1, "", 320,156,12,12, %WS_Border Or %SS_Notify
       Control Set Color hSet, %IDC_cSymbols1, %Black, B.cSymbols(1)
       Control Add Label, hSet, %IDC_cSymbols2, "", 340,156,12,12, %WS_Border Or %SS_Notify
       Control Set Color hSet, %IDC_cSymbols2, %Black, B.cSymbols(2)
       Control Add Label, hSet, %IDC_cSymbols3, "", 360,156,12,12, %WS_Border Or %SS_Notify
       Control Set Color hSet, %IDC_cSymbols3, %Black, B.cSymbols(3)
       Control Add Label, hSet, %IDC_Label, "PreBars PostBars Symbols",380,120,65,120
    
    
       Control Add ComboBox, hSet, %IDC_BarGradientType,,320,175,130,100,%CBS_DropDownList Or %WS_TabStop Or %WS_VScroll, %WS_Ex_ClientEdge
       ComboBox Add hSet, %IDC_BarGradientType, "No Bar Gradient"
       ComboBox Add hSet, %IDC_BarGradientType, "Dark to Color Vert"
       ComboBox Add hSet, %IDC_BarGradientType, "Light to Color Horz"
       ComboBox Add hSet, %IDC_BarGradientType, "Color to Black Horz"
       ComboBox Select hSet, %IDC_BarGradientType, B.BarGradientType
    
       Control Add ComboBox, hSet, %IDC_BarBorder,,320,205,65,150,%CBS_DropDownList Or %WS_TabStop Or %WS_VScroll, %WS_Ex_ClientEdge
       ComboBox Add hSet, %IDC_BarBorder, "None"
       ComboBox Add hSet, %IDC_BarBorder, "Black"
       ComboBox Add hSet, %IDC_BarBorder, "White"
       ComboBox Select hSet, %IDC_BarBorder, B.BarBorder
       Control Add Label, hSet, %IDC_Label, "Border                 Fade",390,205,50,60
    
       Control Add ComboBox, hSet, %IDC_Fade,,320,235,65,150,%CBS_DropDownList Or %WS_TabStop Or %WS_VScroll, %WS_Ex_ClientEdge
       For i = 0 To 255 Step 4 : ComboBox Add hSet, %IDC_Fade, Str$(i) : Next i
       ComboBox Select hSet, %IDC_Fade, B.FadeValue/4 + 1
    
       Control Add CheckBox, hSet, %IDC_GradientBG,"Gradient BG",320,265,100,20
       Control Set Check hSet, %IDC_GradientBG, B.GradientBG
    
       Control Add CheckBox, hSet, %IDC_FadeBG,"Gradient BG Fade ",320,282,120,20
       Control Set Check hSet, %IDC_FadeBG, B.FadeBG
    
    '   Control Add CheckBox, hSet, %IDC_ColorUnder,"Color Under ",320,302,120,20
    '   Control Set Check hSet, %IDC_ColorUnder, B.ColorUnder
    
       Control Add Button, hSet, %IDC_RandomColors, "Random Alt Colors", 320,302,130,20
    
       'Misc Settings
       Control Add Frame, hSet, %IDC_Frame, "Drawing Settings",470,10,150,500
       'Margins
       ReDim s(1 To 30) As String
       Array Assign s() = "10","20","30","40","50","60","70","80","90","100","110","120","130","140","150", _
                          "160","170","180","190","200","210","220","230","240","250","260","270","280","290","300"
       Control Add ComboBox, hSet, %IDC_LM, s(), 480,30,50,150,%CBS_DropDownList Or %WS_TabStop Or %WS_VScroll, %WS_Ex_ClientEdge
       ComboBox Select hSet, %IDC_LM, B.LM/10
       Control Add ComboBox, hSet, %IDC_TM, s(), 480,60,50,150,%CBS_DropDownList Or %WS_TabStop Or %WS_VScroll, %WS_Ex_ClientEdge
       ComboBox Select hSet, %IDC_TM, B.TM/10
       Control Add ComboBox, hSet, %IDC_RM, s(), 480,90,50,150,%CBS_DropDownList Or %WS_TabStop Or %WS_VScroll, %WS_Ex_ClientEdge
       ComboBox Select hSet, %IDC_RM, B.RM/10
       Control Add ComboBox, hSet, %IDC_BM, s(), 480,120,50,150,%CBS_DropDownList Or %WS_TabStop Or %WS_VScroll, %WS_Ex_ClientEdge
       ComboBox Select hSet, %IDC_BM, B.BM/10
    
       'All Else
       ReDim s(1 To 5)
       Array Assign s() = "1","2","4","5","10"
       Control Add ComboBox, hSet, %IDC_DivYCount, s(), 480,150,50,150,%CBS_DropDownList Or %WS_TabStop Or %WS_VScroll, %WS_Ex_ClientEdge
       ComboBox Select hSet, %IDC_DivYCount, Choose(B.DivYCount,1,2,2,3,4,4,4,4,4,5)
    
       ReDim s(1 To 10)
       Array Assign s() = "0.1","0.2","0.3","0.4","0.5","0.6","0.7","0.8","0.9","1.0"
       Control Add ComboBox, hSet, %IDC_Coverage, s(), 480,180,50,150,%CBS_DropDownList Or %WS_TabStop Or %WS_VScroll, %WS_Ex_ClientEdge
       ComboBox Select hSet, %IDC_Coverage, B.Coverage * 10
    
       Control Add ComboBox, hSet, %IDC_LineThickness,,480,210,50,150,%CBS_DropDownList Or %WS_TabStop Or %WS_VScroll, %WS_Ex_ClientEdge
       For i = 1 To 20 : ComboBox Add hSet, %IDC_LineThickness, Str$(i) : Next i
       ComboBox Select hSet, %IDC_LineThickness, B.LineThickness
    
       ReDim s(1 To 8) As String
       Array Assign s() = "5","10","15","20","25","30","35","40"
       Control Add ComboBox, hSet, %IDC_ThreeDX, s(), 480,240,50,150,%CBS_DropDownList Or %WS_TabStop Or %WS_VScroll, %WS_Ex_ClientEdge
       ComboBox Select hSet, %IDC_ThreeDX, B.ThreeDX/5
       Control Add ComboBox, hSet, %IDC_ThreeDY, s(), 480,270,50,150,%CBS_DropDownList Or %WS_TabStop Or %WS_VScroll, %WS_Ex_ClientEdge
       ComboBox Select hSet, %IDC_ThreeDY, B.ThreeDY/5
    
       Control Add ComboBox, hSet, %IDC_SymbolSize,,480,300,50,150,%CBS_DropDownList Or %WS_TabStop Or %WS_VScroll, %WS_Ex_ClientEdge
       For i = 1 To 20 : ComboBox Add hSet, %IDC_SymbolSize, Str$(i) : Next i
       ComboBox Select hSet, %IDC_SymbolSize, B.SymbolSize
    
    
       Control Add Label, hSet, %IDC_Label, "LM                         TM                         RM                         BM",535,30,65,240
       Control Add Label, hSet, %IDC_Label, "Y-Divisions        Coverage                  Line Thick                3D-X                      3D-Y                   Symbol Size",535,150,70,240
    
       Control Add ComboBox, hSet, %IDC_LineSymbol,,480,330,80,150,%CBS_DropDownList Or %WS_TabStop Or %WS_VScroll, %WS_Ex_ClientEdge
       ComboBox Add hSet, %IDC_LineSymbol, "Point"
       ComboBox Add hSet, %IDC_LineSymbol, "Circle"
       ComboBox Add hSet, %IDC_LineSymbol, "Triangle"
       ComboBox Add hSet, %IDC_LineSymbol, "Square"
       ComboBox Select hSet, %IDC_LineSymbol, B.LineSymbol
       Control Add Label, hSet, %IDC_Label, "Symbol",565,332,45,20
    
       Control Add CheckBox, hSet, %IDC_BGImageFit,"BG Image Fit",480,355,100,20
       Control Set Check hSet, %IDC_BGImageFit, B.BGImageFit
    
       Control Add CheckBox, hSet, %IDC_RoundedBar,"Rounded Bar",480,375,100,20
       Control Set Check hSet, %IDC_RoundedBar, B.RoundedBar
    
       Control Add ComboBox, hSet, %IDC_RoundValue,,480,395,60,150,%CBS_DropDownList Or %WS_TabStop Or %WS_VScroll, %WS_Ex_ClientEdge
       For i = 0 To 100 Step 10 : ComboBox Add hSet, %IDC_RoundValue, Str$(i) : Next i
       ComboBox Select hSet, %IDC_RoundValue, B.RoundValue\10+1
       Control Add Label, hSet, %IDC_RoundValue, "Rounding",550,400,65,20
    
       Control Add CheckBox, hSet, %IDC_LargeStamp,"Large Stamp",480,420,100,20
       Control Set Check hSet, %IDC_LargeStamp, B.LargeStamp
    
       Control Add CheckBox, hSet, %IDC_DotGrid,"Dotted Grid",480,440,100,20
       Control Set Check hSet, %IDC_DotGrid, B.DotGrid
    
       Control Add CheckBox, hSet, %IDC_UseAntiAliasing,"Anti-Aliasing",480,460,100,20
       Control Set Check hSet, %IDC_UseAntiAliasing, B.UseAntiAliasing
    
       Control Add ComboBox, hSet, %IDC_HiLoSymbol,,480,480,60,150,%CBS_DropDownList Or %WS_TabStop Or %WS_VScroll, %WS_Ex_ClientEdge
       ComboBox Add hSet, %IDC_HiLoSymbol, "Bar"
       ComboBox Add hSet, %IDC_HiLoSymbol, "Beam"
       ComboBox Add hSet, %IDC_HiLoSymbol, "Dot"
       ComboBox Select hSet, %IDC_HiLoSymbol, B.HiLoSymbol
       Control Add Label, hSet, %IDC_Label, "HiLo Symbol",542,480,75,20
    
       'Pie Settings
       Control Add Frame, hSet, %IDC_Frame, "Unique Pie Settings",630,10,150,325
    
       Control Add CheckBox, hSet, %IDC_PieCircle,"Circle",640,30,100,20
       Control Set Check hSet, %IDC_PieCircle, B.PieCircle
    
       Control Add CheckBox, hSet, %IDC_Pie3D,"3D",640,50,100,20
       Control Set Check hSet, %IDC_Pie3D, B.Pie3D
    
       Control Add CheckBox, hSet, %IDC_PieHideUnselected,"Hide Unselected",640,70,110,20
       Control Set Check hSet, %IDC_PieHideUnselected, B.PieHideUnselected
    
       Control Add CheckBox, hSet, %IDC_PiePerCent,"Inside%",640,90,100,20
       Control Set Check hSet, %IDC_PiePerCent, B.PiePerCent
    
       Control Add CheckBox, hSet, %IDC_PieLegend,"Legend",640,110,100,20
       Control Set Check hSet, %IDC_PieLegend, B.PieLegend
    
       Control Add ComboBox, hSet, %IDC_PieRotate,,640,130,60,150,%CBS_DropDownList Or %WS_TabStop Or %WS_VScroll, %WS_Ex_ClientEdge
       For i = 0 To 360 : ComboBox Add hSet, %IDC_PieRotate, Trim$(Str$(i)) : Next i
       ComboBox Select hSet, %IDC_PieRotate, B.PieRotate+1
       Control Add Label, hSet, %IDC_Label, "Rotate",705,130,65,20
    
       Control Add ComboBox, hSet, %IDC_PieRadius,,640,160,60,150,%CBS_DropDownList Or %WS_TabStop Or %WS_VScroll, %WS_Ex_ClientEdge
       For i = 25 To 100 : ComboBox Add hSet, %IDC_PieRadius, Trim$(Str$(i)) : Next i
       ComboBox Select hSet, %IDC_PieRadius, B.PieRadius - 24
       Control Add Label, hSet, %IDC_Label, "Pie Size",705,160,65,20
    
       Control Add CheckBox, hSet, %IDC_PieEject,"Explode Selected",640,190,120,20
       Control Set Check hSet, %IDC_PieEject, B.PieEject
    
       Control Add CheckBox, hSet, %IDC_PieHighlightSelected,"Highlight Selected",640,210,120,20
       Control Set Check hSet, %IDC_PieHighlightSelected, B.PieHighlightSelected
    
       Control Add CheckBox, hSet, %IDC_PieExplode,"Explode All",640,230,100,20
       Control Set Check hSet, %IDC_PieExplode, B.PieExplode
    
       Control Add ComboBox, hSet, %IDC_PieExplodeDistance,,640,255,50,150,%CBS_DropDownList Or %WS_TabStop Or %WS_VScroll, %WS_Ex_ClientEdge
       For i = 10 To 100 : ComboBox Add hSet, %IDC_PieExplodeDistance, Trim$(Str$(i)) : Next i
       ComboBox Select hSet, %IDC_PieExplodeDistance, B.PieExplodeDistance-9
       Control Add Label, hSet, %IDC_Label, "Explode Dist",695,255,75,20
    
       Control Add CheckBox, hSet, %IDC_PieGradient,"Gradient",700,285,65,20
       Control Set Check hSet, %IDC_PieGradient, B.PieGradient
    
       Control Add ComboBox, hSet, %IDC_PieGradientValue,,640,285,50,150,%CBS_DropDownList Or %WS_TabStop Or %WS_VScroll, %WS_Ex_ClientEdge
       For i = 0 To 255 Step 5 : ComboBox Add hSet, %IDC_PieGradientValue, Trim$(Str$(i)) : Next i
       ComboBox Select hSet, %IDC_PieGradientValue, B.PieGradientValue / 5 + 1
    
    '   Control Add CheckBox, hSet, %IDC_PieDonut,"Donut",640,130,100,20
    '   Control Set Check hSet, %IDC_PieDonut, B.PieDonut
    '   Control Add TextBox, hSet, %IDC_PieDonutCaption, B.PieDonutCaption(1),640,150,75,20
    '   Control Add Label, hSet, %IDC_Label, "Title",720,150,45,20
    '   Control Add CheckBox, hSet, %IDC_PieGradient,"Gradient",640,270,100,20
    '   Control Set Check hSet, %IDC_PieGradient, B.PieGradient
    
       'More Drawing
       Control Add Frame, hSet, %IDC_Frame, "More Drawing Settings",630,340,150,170
    
       Control Add CheckBox, hSet, %IDC_UseFixedYValue,"Fixed Max Y",640,360,100,20
       Control Set Check hSet, %IDC_UseFixedYValue, B.UseFixedYValue
    
       Control Add ComboBox, hSet, %IDC_FixedYValue,,640,380,85,150,%CBS_DropDownList Or %WS_TabStop Or %WS_VScroll, %WS_Ex_ClientEdge
       ComboBox Add hSet, %IDC_FixedYValue, "10"       : If B.FixedYValue = 10      Then i = 1
       ComboBox Add hSet, %IDC_FixedYValue, "25"       : If B.FixedYValue = 25      Then i = 2
       ComboBox Add hSet, %IDC_FixedYValue, "50"       : If B.FixedYValue = 50      Then i = 3
       ComboBox Add hSet, %IDC_FixedYValue, "75"       : If B.FixedYValue = 75      Then i = 4
       ComboBox Add hSet, %IDC_FixedYValue, "100"      : If B.FixedYValue = 100     Then i = 5
       ComboBox Add hSet, %IDC_FixedYValue, "250"      : If B.FixedYValue = 250     Then i = 6
       ComboBox Add hSet, %IDC_FixedYValue, "500"      : If B.FixedYValue = 500     Then i = 7
       ComboBox Add hSet, %IDC_FixedYValue, "750"      : If B.FixedYValue = 750     Then i = 8
       ComboBox Add hSet, %IDC_FixedYValue, "1000"     : If B.FixedYValue = 1000    Then i = 9
       ComboBox Add hSet, %IDC_FixedYValue, "2500"     : If B.FixedYValue = 2500    Then i = 10
       ComboBox Add hSet, %IDC_FixedYValue, "5000"     : If B.FixedYValue = 5000    Then i = 11
       ComboBox Add hSet, %IDC_FixedYValue, "7500"     : If B.FixedYValue = 7500    Then i = 12
       ComboBox Add hSet, %IDC_FixedYValue, "10000"    : If B.FixedYValue = 10000   Then i = 13
       ComboBox Add hSet, %IDC_FixedYValue, "25000"    : If B.FixedYValue = 25000   Then i = 14
       ComboBox Add hSet, %IDC_FixedYValue, "50000"    : If B.FixedYValue = 50000   Then i = 15
       ComboBox Add hSet, %IDC_FixedYValue, "75000"    : If B.FixedYValue = 75000   Then i = 16
       ComboBox Add hSet, %IDC_FixedYValue, "100000"   : If B.FixedYValue = 100000  Then i = 17
       ComboBox Add hSet, %IDC_FixedYValue, "250000"   : If B.FixedYValue = 250000  Then i = 18
       ComboBox Add hSet, %IDC_FixedYValue, "500000"   : If B.FixedYValue = 500000  Then i = 19
       ComboBox Add hSet, %IDC_FixedYValue, "750000"   : If B.FixedYValue = 750000  Then i = 20
       ComboBox Add hSet, %IDC_FixedYValue, "1000000"  : If B.FixedYValue = 1000000 Then i = 21
       ComboBox Select hSet, %IDC_FixedYValue, i
       Control Add Label, hSet, %IDC_Label, "Max Y",730,375,45,20
    
       Control Add ComboBox, hSet, %IDC_LabelType,,640,410,85,150,%CBS_DropDownList Or %WS_TabStop Or %WS_VScroll, %WS_Ex_ClientEdge
       ComboBox Add hSet, %IDC_LabelType, "Label"
       ComboBox Add hSet, %IDC_LabelType, "Value"
       ComboBox Add hSet, %IDC_LabelType, "%"
       ComboBox Add hSet, %IDC_LabelType, "Alt X Text"
       ComboBox Select hSet, %IDC_LabelType, B.LabelType
       Control Add Label, hSet, %IDC_Label, "Label",730,410,45,20
    
       Control Add CheckBox, hSet, %IDC_GridOntop,"Grid On Top",640,440,100,20
       Control Set Check hSet, %IDC_GridOntop, B.GridOnTop
    
       Control Add CheckBox, hSet, %IDC_SmoothLines,"Smooth Lines",640,460,100,20
       Control Set Check hSet, %IDC_SmoothLines, B.SmoothLines
    
       Control Add ComboBox, hSet, %IDC_LineStyle,,640,480,95,150,%CBS_DropDownList Or %WS_TabStop Or %WS_VScroll, %WS_Ex_ClientEdge
       ComboBox Add hSet, %IDC_LineStyle, "Solid"
       ComboBox Add hSet, %IDC_LineStyle, "Dash"
       ComboBox Add hSet, %IDC_LineStyle, "Dot"
       ComboBox Add hSet, %IDC_LineStyle, "DashDot"
       ComboBox Add hSet, %IDC_LineStyle, "DashDotDot"
       ComboBox Select hSet, %IDC_LineStyle, B.LineStyle + 1
       Control Add Label, hSet, %IDC_Label, "Style",740,480,30,20
    
       'Data
       Control Add Frame, hSet, %IDC_Frame, "Dataset Settings",790,10,420,390
    
       Control Add Option, hSet, %IDC_ShowV1,"DataSet 1",800,30,75,20
       Control Add TextBox, hSet, %IDC_DataSet1Title,B.DataSetTitle(1),800,55,75,20
       Control Add Option, hSet, %IDC_ShowV2,"DataSet 2",890,30,75,20
       Control Add TextBox, hSet, %IDC_DataSet2Title,B.DataSetTitle(2),890,55,75,20
       Control Add Option, hSet, %IDC_ShowV3,"DataSet 3",980,30,75,20
       Control Add TextBox, hSet, %IDC_DataSet3Title,B.DataSetTitle(3),980,55,75,20
       Control Set Option hSet, Choose(B.DataSet, %IDC_ShowV1, %IDC_ShowV2, %IDC_ShowV3), %IDC_ShowV1, %IDC_ShowV3
       Control Add Button, hSet, %IDC_TransferData, "Show Data",1100,55,100,20
    
       ReDim s(1 To UBound(D))
       For i = 1 To UBound(D) :  s(i) = Str$(i) : Next i
       Control Add ComboBox, hSet, %IDC_XMin, s(), 800,90,50,150,%CBS_DropDownList Or %WS_TabStop Or %WS_VScroll, %WS_Ex_ClientEdge
       Control Add Label, hSet, %IDC_Label, "From",855,90,30,240
    
       ComboBox Select hSet, %IDC_XMin, B.xMin
       Control Add ComboBox, hSet, %IDC_XMax, s(), 895,90,50,150,%CBS_DropDownList Or %WS_TabStop Or %WS_VScroll, %WS_Ex_ClientEdge
       ComboBox Select hSet, %IDC_XMax, B.xMax
       Control Add Label, hSet, %IDC_Label, "To",950,90,30,240
    
       Control Add ComboBox, hSet, %IDC_Pivot, s(), 980,90,50,150,%CBS_DropDownList Or %WS_TabStop Or %WS_VScroll, %WS_Ex_ClientEdge
       ComboBox Select hSet, %IDC_Pivot, B.Pivot
       Control Add Label, hSet, %IDC_Label, "Pivot",1035,90,30,240
    
       Control Add Button, hSet, %IDC_ApplyAll, "Apply All Data",1100,90,100,20
    
       Control Add Button, hSet, %IDC_ApplyDataFile, "Apply Data", 800,125,90,20
       Control Add TextBox, hSet, %IDC_UserData, B.UserData(B.DataSet), 800,150,90,205,iStyle, %WS_Ex_ClientEdge
    
       Control Add Button, hSet, %IDC_ApplyaltXText, "Apply Alt Text", 900,125,90,20
       Control Add TextBox, hSet, %IDC_altXText, B.altXText(B.DataSet), 900,150,90,205,iStyle, %WS_Ex_ClientEdge
    
       Control Add Button, hSet, %IDC_ApplyBarLabels, "Apply Labels", 1000,125,90,20
       Control Add TextBox, hSet, %IDC_BarLabels, B.labels(B.DataSet), 1000,150,90,205,iStyle, %WS_Ex_ClientEdge
    
       Control Add Button, hSet, %IDC_ApplyColors, "Apply Colors", 1100,125,100,20
       Control Add TextBox, hSet, %IDC_BarColors, B.BarColors(B.DataSet), 1100,150,100,205,iStyle, %WS_Ex_ClientEdge
    
       Control Add TextBox, hSet, %IDC_Equation, Trim$(B.Equation(B.DataSet)), 800,365,250,25
       Control Add Button, hSet, %IDC_EvalEquation, "Build Equation Data",1060,365,120,20
    
       'button actions
       Control Add Button, hSet, %IDC_Reset, "Reset", 800,410,60,20
       Control Add Button, hSet, %IDC_Resize, "Fit to BG", 800,435,60,20
    
       Control Add Button, hSet, %IDC_SaveAs, "Save As", 870,410,60,20
       Control Add Button, hSet, %IDC_Open, "Open", 870,435,60,20
    
       Control Add Button, hSet, %IDC_Copy, "Copy", 940,410,45,20
       Control Add Button, hSet, %IDC_Print, "Print", 940,435,45,20
    
       Control Add Button, hSet, %IDC_Export, "Export", 995,410,65,20
       Control Add ComboBox, hSet, %IDC_ExportFormat,,995,435,65,150,%CBS_DropDownList Or %WS_TabStop Or %WS_VScroll, %WS_Ex_ClientEdge
       ComboBox Add hSet, %IDC_ExportFormat, "bmp"
       ComboBox Add hSet, %IDC_ExportFormat, "jpg"
       ComboBox Add hSet, %IDC_ExportFormat, "gif"
       ComboBox Add hSet, %IDC_ExportFormat, "png"
       ComboBox Select hSet, %IDC_ExportFormat, B.ExportFormat
    
       Control Add Button, hSet, %IDC_SaveSettings, "Save Settings", 1070,410,90,20
       Control Add Button, hSet, %IDC_OpenSettings, "Open Settings", 1070,440,90,20
    
       Control Add ImgButton, hSet, %IDC_OnlineHelp, "xhelp", 1170,410,25,25
    
       'Images
       Control Add Frame, hSet, %IDC_Frame, "Images",10,380,450,130
    
       Control Add Graphic, hSet, %IDC_BGImagePreview,"",155,420,80,80, %WS_Border
       Control Add Graphic, hSet, %IDC_StampPreview,"",385,420,64,64, %WS_Border
    
       Control Add Label, hSet, %IDC_Label, "BG Images",20,400,80,20
       Control Add ListBox, hSet, %IDC_BGImage,, 20,420,130,85
       i = 0 : iPos = 1 : temp$ = Dir$(Exe.Path$ + "bgimages\*.*")
       While Len(temp$)
          ListBox Add hSet, %IDC_BGImage, temp$
          Incr i : If temp$ = PathName$(Namex,B.BGImage) Then iPos = i
          temp$ = Dir$(Next)
       Wend
       ListBox Select hSet, %IDC_BGImage, iPos
    
       Control Add Label, hSet, %IDC_Label, "Stamps",250,400,60,20
       Control Add Button, hSet, %IDC_EraseLastStamp, "Del Last",320,395,60,20
       Control Add Button, hSet, %IDC_EraseAllStamps, "Del All",390,395,60,20
       Control Add ListBox, hSet, %IDC_Stamp,, 250,420,130,85
       i = 0 : iPos = 1 : temp$ = Dir$(Exe.Path$ + "stamps\*.*")
       While Len(temp$)
          ListBox Add hSet, %IDC_Stamp, temp$
          Incr i : If temp$ = PathName$(Namex,B.Stamp) Then iPos = i
          temp$ = Dir$(Next)
       Wend
       ListBox Select hSet, %IDC_Stamp, iPos
    
       OldEditProc = SetWindowLong(GetDlgItem(hSet,%IDC_Title), %GWL_WndProc, CodePtr(NewEditProc))  'subclass
       OldEditProc = SetWindowLong(GetDlgItem(hSet,%IDC_XTitle), %GWL_WndProc, CodePtr(NewEditProc))  'subclass
       OldEditProc = SetWindowLong(GetDlgItem(hSet,%IDC_YTitle), %GWL_WndProc, CodePtr(NewEditProc))  'subclass
       OldEditProc = SetWindowLong(GetDlgItem(hSet,%IDC_UserData), %GWL_WndProc, CodePtr(NewEditProc))  'subclass
       OldEditProc = SetWindowLong(GetDlgItem(hSet,%IDC_altXText), %GWL_WndProc, CodePtr(NewEditProc))  'subclass
       OldEditProc = SetWindowLong(GetDlgItem(hSet,%IDC_BarLabels), %GWL_WndProc, CodePtr(NewEditProc))  'subclass
       OldEditProc = SetWindowLong(GetDlgItem(hSet,%IDC_Equation), %GWL_WndProc, CodePtr(NewEditProc))  'subclass
    
       SetFontButtonText
    
       Dialog Show Modeless hSet Call SetProc
    End Sub
    
    CallBack Function SetProc() As Long
       Local i,j,w,h As Long, s As String, x,result As Single, temp$, hDC As Dword, RR,GG,BB As Long
       Select Case Cb.Msg
          Case %WM_InitDialog
             Graphic Attach hSet, %IDC_StampPreview, ReDraw
             Graphic Get Canvas To w,h
             Graphic Get DC To hDC
             LoadStamp ((B.Stamp), 0,0,w,h,hDC, %False,-1)
             Graphic ReDraw
    
             Graphic Attach hSet, %IDC_BGImagePreview, ReDraw
             Graphic Get Canvas To w,h
             Graphic Get DC To hDC
             LoadStamp ((B.BGImage), 0,0,w,h,hDC, %False,-1)   '-1 = size to fit
             Graphic ReDraw
             Graphic Attach hDlg, %IDC_Graphic, ReDraw
          Case %WM_Destroy
             Dialog Get Loc hSet To SettingsX, SettingsY
             SettingsVisible = 0
          Case %WM_Command
             Select Case Cb.Ctl
                Case %IDC_OnlineHelp
                   If Cb.CtlMsg = %BN_Clicked Then
                      i = ShellExecute(hDlg, "Open", ("http://www.garybeene.com/sw/gbchartmaster.htm"), $Nul, $Nul, %SW_ShowNormal)
                   End If
                Case %IDC_OpenSettings : If Cb.CtlMsg = %BN_Clicked Then SelectSettingsToOpen
                Case %IDC_SaveSettings : If Cb.CtlMsg = %BN_Clicked Then SaveAsSettings
    
                Case %IDC_XMin         : If Cb.CtlMsg = %CBN_SelChange Then ComboBox Get Text hSet, %IDC_XMin To s         : B.XMin = Val(S)         : DrawChart D(), B, %True : DisplayStampList
                Case %IDC_XMax         : If Cb.CtlMsg = %CBN_SelChange Then ComboBox Get Text hSet, %IDC_XMax To s         : B.XMax = Val(S)         : DrawChart D(), B, %True : DisplayStampList
                Case %IDC_Pivot        : If Cb.CtlMsg = %CBN_SelChange Then ComboBox Get Text hSet, %IDC_Pivot To s        : B.Pivot = Val(S)        : DrawChart D(), B, %True : DisplayStampList
                Case %IDC_Fade         : If Cb.CtlMsg = %CBN_SelChange Then ComboBox Get Text hSet, %IDC_Fade To s         : B.FadeValue = Val(S)    : DrawChart D(), B, %True : DisplayStampList
                Case %IDC_DivYCount    : If Cb.CtlMsg = %CBN_SelChange Then ComboBox Get Text hSet, %IDC_DivYCount To s    : B.DivYCount = Val(S)    : DrawChart D(), B, %True : DisplayStampList
                Case %IDC_Coverage     : If Cb.CtlMsg = %CBN_SelChange Then ComboBox Get Text hSet, %IDC_Coverage To s     : B.Coverage = Val(S)     : DrawChart D(), B, %True : DisplayStampList
    
                Case %IDC_Title       : If Cb.CtlMsg = %EN_Change Then Control Get Text hSet, %IDC_Title To B.Title         : DrawChart D(), B, %True : DisplayStampList
                Case %IDC_XTitle      : If Cb.CtlMsg = %EN_Change Then Control Get Text hSet, %IDC_XTitle To B.XTitle       : DrawChart D(), B, %True : DisplayStampList
                Case %IDC_YTitle      : If Cb.CtlMsg = %EN_Change Then Control Get Text hSet, %IDC_YTitle To B.YTitle       : DrawChart D(), B, %True : DisplayStampList
                Case %IDC_AllBars     : If Cb.CtlMsg = %BN_Clicked Then Control Get Check hSet, %IDC_AllBars To B.AllBars   : DrawChart D(), B, %True : DisplayStampList
    
                Case %IDC_MainTitleLoc : If Cb.CtlMsg = %CBN_SelChange Then ComboBox Get Select hSet, %IDC_MainTitleLoc To B.MainTitleLoc : DrawChart D(), B, %True : DisplayStampList
                Case %IDC_XTitleLoc    : If Cb.CtlMsg = %CBN_SelChange Then ComboBox Get Select hSet, %IDC_XTitleLoc    To B.XTitleLoc    : DrawChart D(), B, %True : DisplayStampList
                Case %IDC_YTitleLoc    : If Cb.CtlMsg = %CBN_SelChange Then ComboBox Get Select hSet, %IDC_YTitleLoc    To B.YTitleLoc    : DrawChart D(), B, %True : DisplayStampList
    
                Case %IDC_DataSet1Title : If Cb.CtlMsg = %EN_Change Then Control Get Text hSet, %IDC_DataSet1Title To B.DataSetTitle(1)   : DrawChart D(), B, %True : DisplayStampList
                Case %IDC_DataSet2Title : If Cb.CtlMsg = %EN_Change Then Control Get Text hSet, %IDC_DataSet2Title To B.DataSetTitle(2)   : DrawChart D(), B, %True : DisplayStampList
                Case %IDC_DataSet3Title : If Cb.CtlMsg = %EN_Change Then Control Get Text hSet, %IDC_DataSet3Title To B.DataSetTitle(3)   : DrawChart D(), B, %True : DisplayStampList
    
                Case %IDC_ShowHGrid         : If Cb.CtlMsg = %BN_Clicked Then Control Get Check hSet, %IDC_ShowHGrid To B.ShowHGrid                 : DrawChart D(), B, %True : DisplayStampList
                Case %IDC_ShowVGrid         : If Cb.CtlMsg = %BN_Clicked Then Control Get Check hSet, %IDC_ShowVGrid To B.ShowVGrid                 : DrawChart D(), B, %True : DisplayStampList
                Case %IDC_ShowMargins       : If Cb.CtlMsg = %BN_Clicked Then Control Get Check hSet, %IDC_ShowMargins To B.ShowMargins             : DrawChart D(), B, %True : DisplayStampList
    
                Case %IDC_SpeedTest
                   If Cb.CtlMsg = %BN_Clicked Then Control Get Check hSet, %IDC_SpeedTest To B.SpeedTest
                   If B.SpeedTest = 0 Then Dialog Set Text hDlg, "gbChartMaster    v" + $Ver + "    " + CFN
                   DrawChart D(), B, %True : DisplayStampList
    
                Case %IDC_Instructions      : If Cb.CtlMsg = %BN_Clicked Then Control Get Check hSet, %IDC_Instructions To B.Instructions           : DrawChart D(), B, %True : DisplayStampList
                Case %IDC_UseAntiAliasing   : If Cb.CtlMsg = %BN_Clicked Then Control Get Check hSet, %IDC_UseAntialiasing To B.UseAntiAliasing     : DrawChart D(), B, %True : DisplayStampList
                Case %IDC_ShowMainTitle     : If Cb.CtlMsg = %BN_Clicked Then Control Get Check hSet, %IDC_ShowMainTitle To B.ShowMainTitle         : DrawChart D(), B, %True : DisplayStampList
                Case %IDC_ShowAxisTitles    : If Cb.CtlMsg = %BN_Clicked Then Control Get Check hSet, %IDC_ShowAxisTitles To B.ShowAxisTitles       : DrawChart D(), B, %True : DisplayStampList
                Case %IDC_ShowAxisValues    : If Cb.CtlMsg = %BN_Clicked Then Control Get Check hSet, %IDC_ShowAxisValues To B.ShowAxisValues       : DrawChart D(), B, %True : DisplayStampList
                Case %IDC_ShowBarLabel      : If Cb.CtlMsg = %BN_Clicked Then Control Get Check hSet, %IDC_ShowBarLabel To B.ShowBarLabel           : DrawChart D(), B, %True : DisplayStampList
                Case %IDC_Annotation        : If Cb.CtlMsg = %BN_Clicked Then Control Get Check hSet, %IDC_Annotation To B.Annotation               : DrawChart D(), B, %True : DisplayStampList
                Case %IDC_ShowDataSetTitles : If Cb.CtlMsg = %BN_Clicked Then Control Get Check hSet, %IDC_ShowDataSetTitles To B.ShowDataSetTitles : DrawChart D(), B, %True : DisplayStampList
    
                Case %IDC_EraseAllStamps  : B.StampList = "" : DrawChart D(), B, %True : DisplayStampList
                Case %IDC_EraseLastStamp
                   w = ParseCount(B.StampList,";;;")
                   For i = 1 To w-1 : temp$ += ";;;" + Parse$(B.StampList,";;;",i) : Next i
                   B.StampList = temp$
                   DrawChart D(), B, %True : DisplayStampList
    
                Case %IDC_BGImage
                   If Cb.CtlMsg = %LBN_SelChange Then
                      ListBox Get Text hSet, %IDC_BGImage To B.BGImage
                      B.BGImage = Exe.Path$ + "bgimages\" + B.BGImage
                      Graphic Attach hSet, %IDC_BGImagePreview, ReDraw
                      Graphic Get Canvas To w,h
                      Graphic Clear
                      Graphic Get DC To hDC
                      LoadStamp ((B.BGImage), 0,0,w,h,hDC, %False,-1)   '-1 = size to fit
                      Graphic ReDraw
                      Graphic Attach hDlg, %IDC_Graphic, ReDraw
                      LoadBGImage ((B.BGImage), B.hBGImage)  'Graphic Bitmap Load B.BGimage, 0, 0 To B.hBGImage
                      DrawChart D(), B, %True : DisplayStampList
                   End If
                Case %IDC_Stamp
                   If Cb.CtlMsg = %LBN_SelChange Then
                      ListBox Get Text hSet, %IDC_Stamp To B.Stamp
                      B.Stamp = Exe.Path$ + "stamps\" + B.Stamp
                      Graphic Attach hSet, %IDC_StampPreview, ReDraw
                      Graphic Get Canvas To w,h
                      Graphic Clear
                      Graphic Get DC To hDC
                      LoadStamp ((B.Stamp), 0,0,w,h,hDC, %False,-1)
                      Graphic ReDraw
                      Graphic Attach hDlg, %IDC_Graphic, ReDraw
                   End If
    
                Case %IDC_VertYTitle    : If Cb.CtlMsg = %BN_Clicked Then Control Get Check hSet, %IDC_VertYTitle To B.VertYTitle           : DrawChart D(), B, %True : DisplayStampList
                Case %IDC_VertBarLabels : If Cb.CtlMsg = %BN_Clicked Then Control Get Check hSet, %IDC_VertBarLabels To B.VertBarLabels     : DrawChart D(), B, %True : DisplayStampList
                Case %IDC_RoundedBar    : If Cb.CtlMsg = %BN_Clicked Then Control Get Check hSet, %IDC_RoundedBar To B.RoundedBar           : DrawChart D(), B, %True : DisplayStampList
                Case %IDC_LargeStamp    : If Cb.CtlMsg = %BN_Clicked Then Control Get Check hSet, %IDC_LargeStamp To B.LargeStamp
                Case %IDC_DotGrid       : If Cb.CtlMsg = %BN_Clicked Then Control Get Check hSet, %IDC_DotGrid To B.DotGrid                 : DrawChart D(), B, %True : DisplayStampList
                Case %IDC_AutoXCount    : If Cb.CtlMsg = %BN_Clicked Then Control Get Check hSet, %IDC_AutoXCount To B.AutoXCount           : DrawChart D(), B, %True : DisplayStampList
                Case %IDC_ShowBGImage   : If Cb.CtlMsg = %BN_Clicked Then Control Get Check hSet, %IDC_ShowBGImage To B.ShowBGImage         : DrawChart D(), B, %True : DisplayStampList
                Case %IDC_BGImageFit    : If Cb.CtlMsg = %BN_Clicked Then Control Get Check hSet, %IDC_BGImageFit To B.BGImageFit           : DrawChart D(), B, %True : DisplayStampList
                Case %IDC_UseFixedYValue
                   If Cb.CtlMsg = %BN_Clicked Then
                      Control Get Check hSet, %IDC_UseFixedYValue To B.UseFixedYValue
                      ComboBox Get Text hSet, %IDC_FixedYValue To temp$ : B.FixedYValue = Val(temp$)
                      DrawChart D(), B, %True : DisplayStampList
                   End If
    
                Case %IDC_GraphType
                   If Cb.CtlMsg = %CBN_SelChange Then
                      ComboBox Get Select hSet, %IDC_GraphType To B.GraphType         : DrawChart D(), B, %True : DisplayStampList : SetFontButtonText
                      Statusbar Set Text hDlg, %IDC_StatusBar, 4, 0, Choose$(B.GraphType," 2D Bar", " 3D Bar", " Symbols", " Line", " 2-Line", " 3-Line", " 2-Bar Stacked", " 3-Bar Stacked", " Bar Group", " Pie", " 2-Pie", " 3-Pie", " HiLo") + " Chart"
                   End If
                Case %IDC_RoundValue      : If Cb.CtlMsg = %CBN_SelChange Then ComboBox Get Text hSet, %IDC_RoundValue To s : B.RoundValue = Val(s) : DrawChart D(), B, %True : DisplayStampList
                Case %IDC_HiLoSymbol      : If Cb.CtlMsg = %CBN_SelChange Then ComboBox Get Select hSet, %IDC_HiLoSymbol To B.HiLoSymbol       : DrawChart D(), B, %True : DisplayStampList
                Case %IDC_LineSymbol      : If Cb.CtlMsg = %CBN_SelChange Then ComboBox Get Select hSet, %IDC_LineSymbol To B.LineSymbol       : DrawChart D(), B, %True : DisplayStampList
                Case %IDC_LineThickness   : If Cb.CtlMsg = %CBN_SelChange Then ComboBox Get Select hSet, %IDC_LineThickness To B.LineThickness : DrawChart D(), B, %True : DisplayStampList
                Case %IDC_SymbolSize      : If Cb.CtlMsg = %CBN_SelChange Then ComboBox Get Select hSet, %IDC_SymbolSize To B.SymbolSize       : DrawChart D(), B, %True : DisplayStampList
                Case %IDC_FixedYValue     : If Cb.CtlMsg = %CBN_SelChange Then ComboBox Get Text hSet, %IDC_FixedYValue To s : B.FixedYValue = Val(S) : DrawChart D(), B, %True : DisplayStampList
                Case %IDC_ExportFormat    : If Cb.CtlMsg = %CBN_SelChange Then ComboBox Get Select hSet, %IDC_ExportFormat To B.ExportFormat          : DrawChart D(), B, %True : DisplayStampList
                Case %IDC_LineStyle       : If Cb.CtlMsg = %CBN_SelChange Then ComboBox Get Select hSet, %IDC_LineStyle To B.LineStyle : Decr B.LineStyle  : DrawChart D(), B, %True : DisplayStampList
                Case %IDC_LabelType       : If Cb.CtlMsg = %CBN_SelChange Then ComboBox Get Select hSet, %IDC_LabelType To B.LabelType                     : DrawChart D(), B, %True : DisplayStampList
    
                Case %IDC_GridOnTop       : If Cb.CtlMsg = %BN_Clicked Then Control Get Check hSet, %IDC_GridOnTop To B.GridOnTop     : DrawChart D(), B, %True : DisplayStampList
                Case %IDC_SmoothLines     : If Cb.CtlMsg = %BN_Clicked Then Control Get Check hSet, %IDC_SmoothLines To B.SmoothLines : DrawChart D(), B, %True : DisplayStampList
    
                Case %IDC_BarBorder       : If Cb.CtlMsg = %CBN_SelChange Then ComboBox Get Select hSet, %IDC_BarBorder To B.BarBorder         : DrawChart D(), B, %True : DisplayStampList
                Case %IDC_BarGradientType : If Cb.CtlMsg = %CBN_SelChange Then ComboBox Get Select hSet, %IDC_BarGradientType To B.BarGradientType : DrawChart D(), B, %True : DisplayStampList
    
                Case %IDC_ThreeDX     : If Cb.CtlMsg = %CBN_SelChange Then ComboBox Get Text hSet, %IDC_ThreeDX To s : B.ThreeDX = Val(S) : DrawChart D(), B, %True : DisplayStampList
                Case %IDC_ThreeDY     : If Cb.CtlMsg = %CBN_SelChange Then ComboBox Get Text hSet, %IDC_ThreeDY To s : B.ThreeDY = Val(S) : DrawChart D(), B, %True : DisplayStampList
    
    
                Case %IDC_PieCircle   : If Cb.CtlMsg = %BN_Clicked Then Control Get Check hSet, %IDC_PieCircle To B.PieCircle             : DrawChart D(), B, %True : DisplayStampList
                Case %IDC_PieExplode  : If Cb.CtlMsg = %BN_Clicked Then Control Get Check hSet, %IDC_PieExplode To B.PieExplode           : DrawChart D(), B, %True : DisplayStampList
                Case %IDC_PieEject    : If Cb.CtlMsg = %BN_Clicked Then Control Get Check hSet, %IDC_PieEject To B.PieEject               : DrawChart D(), B, %True : DisplayStampList
                Case %IDC_PiePerCent  : If Cb.CtlMsg = %BN_Clicked Then Control Get Check hSet, %IDC_PiePerCent To B.PiePercent           : DrawChart D(), B, %True : DisplayStampList
                Case %IDC_PieLegend   : If Cb.CtlMsg = %BN_Clicked Then Control Get Check hSet, %IDC_PieLegend To B.PieLegend             : DrawChart D(), B, %True : DisplayStampList
                Case %IDC_PieDonut    : If Cb.CtlMsg = %BN_Clicked Then Control Get Check hSet, %IDC_PieDonut To B.PieDonut               : DrawChart D(), B, %True : DisplayStampList
                Case %IDC_PieDonutCaption : If Cb.CtlMsg = %EN_Change Then Control Get Text hSet, %IDC_PieDonutCaption To B.PieDonutCaption(B.DataSet) : DrawChart D(), B, %True : DisplayStampList
                Case %IDC_PieRotate   : If Cb.CtlMsg = %CBN_SelChange Then ComboBox Get Text hSet, %IDC_PieRotate To s    : B.PieRotate = Val(S)       : DrawChart D(), B, %True : DisplayStampList
                Case %IDC_PieRadius   : If Cb.CtlMsg = %CBN_SelChange Then ComboBox Get Text hSet, %IDC_PieRadius To s    : B.PieRadius = Val(S)       : DrawChart D(), B, %True : DisplayStampList
                Case %IDC_PieExplodeDistance : If Cb.CtlMsg = %CBN_SelChange Then ComboBox Get Text hSet, %IDC_PieExplodeDistance To s : B.PieExplodeDistance = Val(S) : DrawChart D(), B, %True : DisplayStampList
                Case %IDC_Pie3D       : If Cb.CtlMsg = %BN_Clicked Then Control Get Check hSet, %IDC_Pie3D To B.Pie3D                                  : DrawChart D(), B, %True : DisplayStampList
                Case %IDC_PieGradient : If Cb.CtlMsg = %BN_Clicked Then Control Get Check hSet, %IDC_PieGradient To B.PieGradient                      : DrawChart D(), B, %True : DisplayStampList
                Case %IDC_PieGradientValue : If Cb.CtlMsg = %CBN_SelChange Then ComboBox Get Text hSet, %IDC_PieGradientValue To s    : B.PieGradientValue = Val(S)       : DrawChart D(), B, %True : DisplayStampList
    
                Case %IDC_PieHideUnSelected : If Cb.CtlMsg = %BN_Clicked Then Control Get Check hSet, %IDC_PieHideUnselected To B.PieHideUnselected    : DrawChart D(), B, %True : DisplayStampList
                Case %IDC_PieHighlightSelected : If Cb.CtlMsg = %BN_Clicked Then Control Get Check hSet, %IDC_PieHighlightSelected To B.PieHighlightSelected   : DrawChart D(), B, %True : DisplayStampList
                Case %IDC_PieGradient : If Cb.CtlMsg = %BN_Clicked Then Control Get Check hSet, %IDC_PieGradient To B.PieGradient    : DrawChart D(), B, %True : DisplayStampList
    
                Case %IDC_UseAltColors: If Cb.CtlMsg = %BN_Clicked Then Control Get Check hSet, %IDC_UseAltColors To B.UseAltColors : DrawChart D(), B, %True : DisplayStampList
                Case %IDC_UsealtXText  : If Cb.CtlMsg = %BN_Clicked Then Control Get Check hSet, %IDC_UsealtXText To B.UsealtXText     : DrawChart D(), B, %True : DisplayStampList
                Case %IDC_GradientBG  : If Cb.CtlMsg = %BN_Clicked Then Control Get Check hSet, %IDC_GradientBG To B.GradientBG     : DrawChart D(), B, %True : DisplayStampList
                Case %IDC_FadeBG      : If Cb.CtlMsg = %BN_Clicked Then Control Get Check hSet, %IDC_FadeBG To B.FadeBG             : DrawChart D(), B, %True : DisplayStampList
                Case %IDC_ColorUnder  : If Cb.CtlMsg = %BN_Clicked Then Control Get Check hSet, %IDC_ColorUnder To B.ColorUnder     : DrawChart D(), B, %True : DisplayStampList
    
                Case %IDC_cBG
                   If Cb.CtlMsg = %STN_Clicked Then B.cBG = SelectColor(hDlg, B.cBG)                 : DrawChart D(), B, %True : DisplayStampList : Control Set Color hSet, %IDC_cBG, %Black, B.cBG : Control ReDraw hSet, %IDC_cBG
                Case %IDC_cTitle
                   If Cb.CtlMsg = %STN_Clicked Then B.cTitle = SelectColor(hDlg, B.cTitle)           : DrawChart D(), B, %True : DisplayStampList : Control Set Color hSet, %IDC_cTitle, %Black, B.cTitle : Control ReDraw hSet, %IDC_cTitle
                Case %IDC_cAxisLines
                   If Cb.CtlMsg = %STN_Clicked Then B.cAxisLines = SelectColor(hDlg, B.cAxisLines)   : DrawChart D(), B, %True : DisplayStampList : Control Set Color hSet, %IDC_cAxisLines, %Black, B.cAxisLines : Control ReDraw hSet, %IDC_cAxisLines
                Case %IDC_cAxisValues
                   If Cb.CtlMsg = %STN_Clicked Then B.cAxisValues = SelectColor(hDlg, B.cAxisValues) : DrawChart D(), B, %True : DisplayStampList : Control Set Color hSet, %IDC_cAxisValues, %Black, B.cAxisValues : Control ReDraw hSet, %IDC_cAxisValues
                Case %IDC_cGrid
                   If Cb.CtlMsg = %STN_Clicked Then B.cGrid = SelectColor(hDlg, B.cGrid)             : DrawChart D(), B, %True : DisplayStampList : Control Set Color hSet, %IDC_cAxisValues, %Black, B.cAxisValues : Control ReDraw hSet, %IDC_cGrid
    
                Case %IDC_cPreBars1
                   If Cb.CtlMsg = %STN_Clicked Then B.cPreBars(1) = SelectColor(hDlg, B.cPreBars(1))       : DrawChart D(), B, %True : DisplayStampList : Control Set Color hSet, %IDC_cPreBars1, %Black, B.cPreBars(1) : Control ReDraw hSet, %IDC_cPreBars1
                Case %IDC_cPreBars2
                   If Cb.CtlMsg = %STN_Clicked Then B.cPreBars(2) = SelectColor(hDlg, B.cPreBars(2))       : DrawChart D(), B, %True : DisplayStampList : Control Set Color hSet, %IDC_cPreBars2, %Black, B.cPreBars(2) : Control ReDraw hSet, %IDC_cPreBars2
                Case %IDC_cPreBars3
                   If Cb.CtlMsg = %STN_Clicked Then B.cPreBars(3) = SelectColor(hDlg, B.cPreBars(3))       : DrawChart D(), B, %True : DisplayStampList : Control Set Color hSet, %IDC_cPreBars3, %Black, B.cPreBars(3) : Control ReDraw hSet, %IDC_cPreBars3
    
                Case %IDC_cPostBars1
                   If Cb.CtlMsg = %STN_Clicked Then B.cPostBars(1) = SelectColor(hDlg, B.cPostBars(1))     : DrawChart D(), B, %True : DisplayStampList : Control Set Color hSet, %IDC_cPostBars1, %Black, B.cPostBars(1) : Control ReDraw hSet, %IDC_cPostBars1
                Case %IDC_cPostBars2
                   If Cb.CtlMsg = %STN_Clicked Then B.cPostBars(2) = SelectColor(hDlg, B.cPostBars(2))     : DrawChart D(), B, %True : DisplayStampList : Control Set Color hSet, %IDC_cPostBars2, %Black, B.cPostBars(2) : Control ReDraw hSet, %IDC_cPostBars2
                Case %IDC_cPostBars3
                   If Cb.CtlMsg = %STN_Clicked Then B.cPostBars(3) = SelectColor(hDlg, B.cPostBars(3))     : DrawChart D(), B, %True : DisplayStampList : Control Set Color hSet, %IDC_cPostBars3, %Black, B.cPostBars(3) : Control ReDraw hSet, %IDC_cPostBars3
    
                Case %IDC_cSymbols1
                   If Cb.CtlMsg = %STN_Clicked Then B.cSymbols(1) = SelectColor(hDlg, B.cSymbols(1))       : DrawChart D(), B, %True : DisplayStampList : Control Set Color hSet, %IDC_cSymbols1, %Black, B.cSymbols(1) : Control ReDraw hSet, %IDC_cSymbols1
                Case %IDC_cSymbols2
                   If Cb.CtlMsg = %STN_Clicked Then B.cSymbols(2) = SelectColor(hDlg, B.cSymbols(2))       : DrawChart D(), B, %True : DisplayStampList : Control Set Color hSet, %IDC_cSymbols2, %Black, B.cSymbols(2) : Control ReDraw hSet, %IDC_cSymbols2
                Case %IDC_cSymbols3
                   If Cb.CtlMsg = %STN_Clicked Then B.cSymbols(3) = SelectColor(hDlg, B.cSymbols(3))       : DrawChart D(), B, %True : DisplayStampList : Control Set Color hSet, %IDC_cSymbols3, %Black, B.cSymbols(3) : Control ReDraw hSet, %IDC_cSymbols3
    
                Case %IDC_LM          : If Cb.CtlMsg = %CBN_SelChange Then ComboBox Get Text hSet, %IDC_LM To s : B.LM = Val(S) : DrawChart D(), B, %True : DisplayStampList
                Case %IDC_RM          : If Cb.CtlMsg = %CBN_SelChange Then ComboBox Get Text hSet, %IDC_RM To s : B.RM = Val(S) : DrawChart D(), B, %True : DisplayStampList
                Case %IDC_TM          : If Cb.CtlMsg = %CBN_SelChange Then ComboBox Get Text hSet, %IDC_TM To s : B.TM = Val(S) : DrawChart D(), B, %True : DisplayStampList
                Case %IDC_BM          : If Cb.CtlMsg = %CBN_SelChange Then ComboBox Get Text hSet, %IDC_BM To s : B.BM = Val(S) : DrawChart D(), B, %True : DisplayStampList
    
                Case %IDC_MainTitleFontSize : If Cb.CtlMsg = %CBN_SelChange Then ComboBox Get Text hSet, %IDC_MainTitleFontSize To s : B.titleFontSize = Val(S)     : CreateFonts : DrawChart D(), B, %True : DisplayStampList
                Case %IDC_AxisTitleFontSize : If Cb.CtlMsg = %CBN_SelChange Then ComboBox Get Text hSet, %IDC_AxisTitleFontSize To s : B.AxisTitleFontSize = Val(S) : CreateFonts : DrawChart D(), B, %True : DisplayStampList
                Case %IDC_ValuesFontSize    : If Cb.CtlMsg = %CBN_SelChange Then ComboBox Get Text hSet, %IDC_ValuesFontSize To s    : B.AxisValueFontSize = Val(S) : CreateFonts : DrawChart D(), B, %True : DisplayStampList
                Case %IDC_LabelFontSize     : If Cb.CtlMsg = %CBN_SelChange Then ComboBox Get Text hSet, %IDC_LabelFontSize To s     : B.LabelFontSize = Val(S)     : CreateFonts : DrawChart D(), B, %True : DisplayStampList
    
                Case %IDC_TitleFont
                   If Cb.CtlMsg = %BN_Clicked Then
                      SelectMainFont(B.TitleFontName,B.TitleFontSize,B.TitleFontBold,B.TitleFont)
                      CreateFonts   'rebuild the set of fonts needed by the Graphic control
                      DrawChart D(), B, %True : DisplayStampList
                   End If
                Case %IDC_AxisTitleFont
                   If Cb.CtlMsg = %BN_Clicked Then
                      SelectMainFont(B.AxisTitleFontName,B.AxisTitleFontSize,B.AxisTitleFontBold,B.AxisTitleFont)
                      CreateFonts   'rebuild the set of fonts needed by the Graphic control
                      DrawChart D(), B, %True : DisplayStampList
                   End If
                Case %IDC_AxisValueFont
                   If Cb.CtlMsg = %BN_Clicked Then
                      SelectMainFont(B.AxisValueFontName,B.AxisValueFontSize,B.AxisValueFontBold,B.AxisValueFont)
                      CreateFonts   'rebuild the set of fonts needed by the Graphic control
                      DrawChart D(), B, %True : DisplayStampList
                   End If
                Case %IDC_LabelFont
                   If Cb.CtlMsg = %BN_Clicked Then
                      SelectMainFont(B.LabelFontName,B.LabelFontSize,B.LabelFontBold,B.LabelFont)
                      CreateFonts   'rebuild the set of fonts needed by the Graphic control
                      DrawChart D(), B, %True : DisplayStampList
                   End If
                Case %IDC_SaveAs : SaveChartAs
                Case %IDC_Open   : SelectChartToOpen
                Case %IDC_Resize
                   Graphic Get Canvas To w,h
                   GetImageSize ((B.BGImage),i,j)
                   Dialog Set Client hDlg, w, w*j/i+20   '20 is height of statusbar
    
                Case %IDC_Reset
                   If Cb.CtlMsg = %BN_Clicked Then
                      CreateFakeData
                      InitializeChart hDlg, %IDC_Graphic
                      B.Xmax = 60 : B.Xmin = 10 : B.Pivot = 40
                      DrawChart D(), B, %True : DisplayStampList
                      Statusbar Set Text hDlg, %IDC_StatusBar, 2, 0, ""
                      Statusbar Set Text hDlg, %IDC_StatusBar, 3, 0, ""
                      Dialog End hSet
                      ShowSettingsDialog
                   End If
                Case %IDC_Copy          : If Cb.CtlMsg = %BN_Clicked Then Clipboard Reset : Clipboard Set Bitmap B.hGraphic : sndPlaySound("xcamera", %SND_Async Or %SND_Resource)
                Case %IDC_Print         : If Cb.CtlMsg = %BN_Clicked Then PrintChart
                Case %IDC_Export
                   If Cb.CtlMsg = %BN_Clicked Then
                      GDIPlus_SaveImage B.hGraphicDC, Choose$(B.ExportFormat,"bmp","jpg","gif","png"), Exe.Path$ + "tempfiles\gbchartmaster." + Choose$(B.ExportFormat,"bmp","jpg","gif","png")
                      temp$ = Exe.Path$ + "tempfiles"
                      i = ShellExecute(hDlg, "Open", (temp$), $Nul, $Nul, %SW_ShowNormal)
                   End If
    
                Case %IDC_RandomColors
                   If Cb.CtlMsg = %BN_Clicked Then
                     For w = 1 To UBound(D)
                        D(w).altColor(B.DataSet) = RGB(Rnd(0,255),Rnd(0,255),Rnd(0,255))
                     Next w
                     DrawChart D(), B, %True : DisplayStampList
                   End If
    
                Case %IDC_ShowV1
                   If Cb.CtlMsg = %BN_Clicked Then
                      B.DataSet = 1 : DrawChart D(), B, %True : DisplayStampList
                      Control Set Text hSet, %IDC_UserData, B.UserData(B.DataSet)
                      Control Set Text hSet, %IDC_altXText,  B.altXText(B.DataSet)
                      Control Set Text hSet, %IDC_BarLabels, B.labels(B.DataSet)
                      Control Set Text hSet, %IDC_Equation, B.Equation(B.DataSet)
                      Control Set Text hSet, %IDC_BarColors, B.BarColors(B.DataSet)
                   End If
                Case %IDC_ShowV2
                   If Cb.CtlMsg = %BN_Clicked Then
                      B.DataSet = 2 : DrawChart D(), B, %True : DisplayStampList
                      Control Set Text hSet, %IDC_UserData, B.UserData(B.DataSet)
                      Control Set Text hSet, %IDC_altXText,  B.altXText(B.DataSet)
                      Control Set Text hSet, %IDC_BarLabels, B.labels(B.DataSet)
                      Control Set Text hSet, %IDC_Equation, B.Equation(B.DataSet)
                      Control Set Text hSet, %IDC_BarColors, B.BarColors(B.DataSet)
                   End If
                Case %IDC_ShowV3
                   If Cb.CtlMsg = %BN_Clicked Then
                      B.DataSet = 3 : DrawChart D(), B, %True : DisplayStampList
                      Control Set Text hSet, %IDC_UserData, B.UserData(B.DataSet)
                      Control Set Text hSet, %IDC_altXText,  B.altXText(B.DataSet)
                      Control Set Text hSet, %IDC_BarLabels, B.labels(B.DataSet)
                      Control Set Text hSet, %IDC_Equation, B.Equation(B.DataSet)
                      Control Set Text hSet, %IDC_BarColors, B.BarColors(B.DataSet)
                   End If
    
                Case %IDC_UserData      : If Cb.CtlMsg = %EN_Change Then Control Get Text hSet, %IDC_UserData  To B.UserData(B.DataSet)
                Case %IDC_altXText       : If Cb.CtlMsg = %EN_Change Then Control Get Text hSet, %IDC_altXText   To B.altXText(B.DataSet)
                Case %IDC_BarLabels     : If Cb.CtlMsg = %EN_Change Then Control Get Text hSet, %IDC_BarLabels To B.labels(B.DataSet)
    
                Case %IDC_ApplyDataFile
                   If Cb.CtlMsg = %BN_Clicked Then
                      Control Get Text hSet, %IDC_UserData To B.UserData(B.DataSet)
                      w = ParseCount(B.UserData(B.DataSet),$CrLf)
                      ReDim Preserve D(1 To w)
                      For i = 1 To w : D(i).v(B.DataSet) = Val(Parse$(B.UserData(B.DataSet),$CrLf,i)) : Next i
                      B.XMin = 1          : ComboBox Select hSet, %IDC_XMin,  B.xMin
                      B.Xmax = UBound(D)  : ComboBox Select hSet, %IDC_XMax,  B.xMax
                      B.Pivot = UBound(D) : ComboBox Select hSet, %IDC_Pivot, B.Pivot
                      DrawChart D(), B, %True : DisplayStampList
                      Statusbar Set Text hDlg, %IDC_StatusBar, 2, 0, ""
                      Statusbar Set Text hDlg, %IDC_StatusBar, 3, 0, ""
                   End If
                   If SettingsVisible Then Dialog End hSet : ShowSettingsDialog
    
                Case %IDC_ApplyaltXText
                   If Cb.CtlMsg = %BN_Clicked Then
                      Control Get Text hSet, %IDC_altXText To B.altXText(B.DataSet)
                      w = Min(ParseCount(B.altXText(B.DataSet),$CrLf), UBound(D))
                      For i = 1 To w : D(i).altXText(B.DataSet) = Parse$(B.altXText(B.DataSet),$CrLf,i) : Next i
                      DrawChart D(), B, %True : DisplayStampList
                      Statusbar Set Text hDlg, %IDC_StatusBar, 2, 0, ""
                      Statusbar Set Text hDlg, %IDC_StatusBar, 3, 0, ""
                   End If
    
                Case %IDC_ApplyBarLabels
                   If Cb.CtlMsg = %BN_Clicked Then
                      Control Get Text hSet, %IDC_BarLabels To B.labels(B.DataSet)
                      w = Min(ParseCount(B.labels(B.DataSet),$CrLf), UBound(D))
                      For i = 1 To w : D(i).label(B.DataSet) = Parse$(B.labels(B.DataSet),$CrLf,i) : Next i
                      DrawChart D(), B, %True : DisplayStampList
                      Statusbar Set Text hDlg, %IDC_StatusBar, 2, 0, ""
                      Statusbar Set Text hDlg, %IDC_StatusBar, 3, 0, ""
                   End If
    
                Case %IDC_ApplyColors
                   If Cb.CtlMsg = %BN_Clicked Then
                      Control Get Text hSet, %IDC_BarColors To B.BarColors(B.DataSet)
                      w = Min(ParseCount(B.BarColors(B.DataSet),$CrLf), UBound(D))
                      For i = 1 To w
                         temp$ = Parse$(B.BarColors(B.DataSet),$CrLf,i)
                         D(i).altColor(B.DataSet) = RGB(Val(Parse$(temp$,$Spc,1)),Val(Parse$(temp$,$Spc,2)),Val(Parse$(temp$,$Spc,3)))
                      Next i
                      DrawChart D(), B, %True : DisplayStampList
                      Statusbar Set Text hDlg, %IDC_StatusBar, 2, 0, ""
                      Statusbar Set Text hDlg, %IDC_StatusBar, 3, 0, ""
                   End If
    
                Case %IDC_ApplyAll
                   'data
                   Control Get Text hSet, %IDC_UserData To B.UserData(B.Dataset)
                   w = ParseCount(B.UserData(B.Dataset),$CrLf)
                   ReDim Preserve D(1 To w)
                   For i = 1 To w : D(i).v(B.Dataset) = Val(Parse$(B.UserData(B.Dataset),$CrLf,i)) : Next i
                   B.XMin = 1          : ComboBox Select hSet, %IDC_XMin,  B.xMin
                   B.Xmax = UBound(D)  : ComboBox Select hSet, %IDC_XMax,  B.xMax
                   B.Pivot = UBound(D) : ComboBox Select hSet, %IDC_Pivot, B.Pivot
                   'alt text
                   Control Get Text hSet, %IDC_altXText To B.altXText(B.Dataset)
                   w = Min(ParseCount(B.altXText(B.Dataset),$CrLf), UBound(D))
                   For i = 1 To w : D(i).altXText(B.Dataset) = Parse$(B.altXText(B.Dataset),$CrLf,i) : Next i
                   'bar labels
                   Control Get Text hSet, %IDC_BarLabels To B.labels(B.Dataset)
                   w = Min(ParseCount(B.labels(B.Dataset),$CrLf), UBound(D))
                   For i = 1 To w : D(i).label(B.Dataset) = Parse$(B.labels(B.Dataset),$CrLf,i) : Next i
                   'colors
                   Control Get Text hSet, %IDC_BarColors To B.BarColors(B.Dataset)
                   w = Min(ParseCount(B.BarColors(B.Dataset),$CrLf), UBound(D))
                   For i = 1 To w
                      temp$ = Parse$(B.BarColors(B.Dataset),$CrLf,i)
                      D(i).altColor(B.Dataset) = RGB(Val(Parse$(temp$,$Spc,1)),Val(Parse$(temp$,$Spc,2)),Val(Parse$(temp$,$Spc,3)))
                   Next i
                   DrawChart D(), B, %True : DisplayStampList
                   Statusbar Set Text hDlg, %IDC_StatusBar, 2, 0, ""
                   Statusbar Set Text hDlg, %IDC_StatusBar, 3, 0, ""
    
                Case %IDC_TransferData
                   temp$ = ""
                   For i = 1 To UBound(D)
                      temp$ += Trim$(Str$(D(i).v(B.DataSet))) + $CrLf
                   Next i
                   Control Set Text hSet, %IDC_UserData, RTrim$(temp$,$CrLf)
    
                   temp$ = ""
                   For i = 1 To UBound(D)
                      temp$ += D(i).altXText(B.DataSet) + $CrLf
                   Next i
                   Control Set Text hSet, %IDC_altXText, RTrim$(temp$,$CrLf)
    
                   temp$ = ""
                   For i = 1 To UBound(D)
                      temp$ += D(i).label(B.DataSet) + $CrLf
                   Next i
                   Control Set Text hSet, %IDC_barLabels, RTrim$(temp$,$CrLf)
    
                   temp$ = ""
                   For i = 1 To UBound(D)
                      RR = GetRValue(D(i).altColor(B.DataSet))
                      GG = GetGValue(D(i).altColor(B.DataSet))
                      BB = GetBValue(D(i).altColor(B.DataSet))
                      temp$ += Trim$(Str$(RR)) + Str$(GG) + Str$(BB) + $CrLf
                   Next i
                   Control Set Text hSet, %IDC_barColors, RTrim$(temp$,$CrLf)
    
    
    
                Case %IDC_EvalEquation
                   If Cb.CtlMsg = %BN_Clicked Then
                      B.UserData(B.DataSet) = ""
                      Control Get Text hSet, %IDC_Equation To s
                      For i = Val(Parse$(s,":",1)) To Val(Parse$(s,":",2))       'From To
                         x = Val(Parse$(s,":",3)) + (i-1) * Val(Parse$(s,":",4)) 'x starting value + x increment
                         temp$ = Parse$(s,":",5)                                 'temp$ = equation
                         Replace "x"     With "(" + Str$(x) + ")" In temp$
                         Replace "X"     With "(" + Str$(x) + ")" In temp$
                         result = EvaluateEquation(temp$)
                         B.UserData(B.DataSet) += Str$(result) + $CrLf
                      Next x
                      B.UserData(B.DataSet) = Trim$(B.UserData(B.DataSet), $CrLf)
                      Control Set Text hSet, %IDC_UserData, B.UserData(B.DataSet)
                      Statusbar Set Text hDlg, %IDC_StatusBar, 2, 0, ""
                      Statusbar Set Text hDlg, %IDC_StatusBar, 3, 0, ""
                   End If
             End Select
       End Select
    End Function
    
    Sub Settings_INI(Task$)
       Local x,y As Long
       Local xResult, yResult, INIFileName, temp As WStringZ * %Max_Path
       'defines file name (any file name will work)
       INIFileName = Exe.Path$ + Exe.Name$ + ".ini"
       If Task$ = "get" Then
          'get dialog top/left from INI file and use to set Dialog location
          Getprivateprofilestring "All", "Left", "300", xResult, %Max_Path, INIFileName
          Getprivateprofilestring "All", "Top", "150", yResult, %Max_Path, INIFileName
          Dialog Set Loc hDlg, Val(xResult), Val(yResult)   'left/top
          'get dialog width/height from INI file and use to set Dialog size
          GetPrivateProfileString "All", "Width", "720", xResult, %Max_Path, INIFileName
          GetPrivateProfileString "All", "Height", "350", yResult, %Max_Path, INIFileName
          Dialog Set Size hDlg,Val(xResult), Val(yResult)   'width/height
          'get value for numeric variables
          Getprivateprofilestring "All", "SettingsX", "150", temp, %Max_Path, INIFileName  : SettingsX = Val(temp)
          Getprivateprofilestring "All", "SettingsY", "250", temp, %Max_Path, INIFileName  : SettingsY = Val(temp)
          Getprivateprofilestring "All", "SettingsVisible", "0", temp, %Max_Path, INIFileName : SettingsVisible = Val(temp)
          'get value for string variable
          Getprivateprofilestring "All", "CFN", "", CFN, %Max_Path, INIFileName
          'custom colors
          For x = 0 To 15
             Getprivateprofilestring "All", "CustomColorC" + Format$(x,"00"), "", temp, %Max_Path, INIFileName
             CustomColorList.c(x) = Val(temp)
          Next x
       End If
       If Task$ = "save" Then
          'save dialog size/location unless minimized or maximized
          If IsFalse(IsIconic(hDlg) Or IsZoomed(hDlg)) Then
             Dialog Get Loc hDlg To x,y
             WritePrivateProfileString "All", "Left", Str$(x), INIFileName
             WritePrivateProfileString "All", "Top", Str$(y), INIFileName
             Dialog Get Size hDlg To x,y
             WritePrivateProfileString "All", "Width", Str$(x), INIFileName
             WritePrivateProfileString "All", "Height", Str$(y), INIFileName
          End If
          'save string variables
          WritePrivateProfileString "All", "CFN", CFN, INIFileName
          'save numeric variable
          WritePrivateProfileString "All", "SettingsX", Str$(SettingsX), INIFileName
          WritePrivateProfileString "All", "SettingsY", Str$(SettingsY), INIFileName
          WritePrivateProfileString "All", "SettingsVisible", Str$(SettingsVisible), INIFileName
          'custom colors
          For x = 0 To 15
             temp = Str$(CustomColorList.c(x))
             WritePrivateProfileString "All", "CustomColorC" + Format$(x,"00"), temp, INIFileName
          Next x
       End If
    End Sub
    
    Sub PrintChart
       On Error GoTo CancelPrint
       Local w,h,x,y,wNew,hNew,wImg,hImg As Long
       XPrint Attach Choose
       XPrint Get Client To w,h
       Graphic Get Client To wImg,hImg
       wNew = wImg / Max(wImg / w, hImg / h)
       hNew = hImg / Max(wImg / w, hImg / h)
       x = (w-wNew)/2 : y = (h-hNew)/2               'upper/left position so resized image is centered
       XPrint Stretch hGraphic, 0, (0,0)-(wImg-1,hImg-1) To (x,y)-(x+wNew-1,y+hNew-1), %Mix_CopySrc, %HalfTone   'copy (resized) from memory bitmap to visible image
       XPrint Close
    CancelPrint:
    End Sub
    
    Function NewGraphicProc(ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
       Local x,y As Long, pt As Point
       Select Case Msg
          Case %WM_LButtonDown
             If B.annotation Then SetCapture hWnd    'start capturing, so can detect LButtonUp when it occurs
          Case %WM_MouseMove
             If GetCapture() = hWnd Then
                GetCursorPos pt
                ScreenToClient hGraphic, pt
                If LastX = -1 Then LastX = pt.x : LastY = pt.y
                Graphic Width 4
                Graphic Line (LastX,LastY)-(pt.x,pt.y), %Red
                Graphic Width 1
                LastX = pt.x : LastY = pt.y
                Graphic ReDraw
             End If
          Case %WM_LButtonUp
             ReleaseCapture
             LastX = -1
       End Select
       Function = CallWindowProc(OldGraphicProc, hWnd, Msg, wParam, lParam)
    End Function
    
    Function EvaluateEquation(ByVal Equation$) As Single      'Extended
       Local    lOpenParentheseStart, lOpenParentheseCounter, lCloseParentheseCounter As Long
       Local    lCurrentPos, lI, lPosOperator, lLeftOperandStart As Long
       Local    lleftOperandEnd, lRightOperandStart, lRightOperandEnd As Long
       Local    lEval, lLeftOperand, lRightOperand As Single         'Extended
    
       Equation$ = UCase$(Trim$(Equation$))
    
       Replace "LOG10" With "LOGTEN"            In Equation$
       Replace "LOG2"  With "LOGTWO"            In Equation$
       Replace "EXP10" With "EXPTEN"            In Equation$
       Replace "EXP2"  With "EXPTWO"            In Equation$
       Replace "PI"    With "3.14159"           In Equation$
       Replace "-"     With "_"                 In Equation$  ' to avoid any confusion with a negative value
    
        Do
            lOpenParentheseCounter  = 0 : lCloseParentheseCounter = 0   'reset the parentheses counters
            lOpenParentheseStart = InStr(Equation$, "(")              'search for a open parenthese "(" in the expression
            If lOpenParentheseStart <> 0 Then                           'only if we find a open parenthese "(" in the expression
                lOpenParentheseCounter = 1                              'initialize the open parenthese counter to 1
                lCurrentPos = lOpenParentheseStart                      'we start at the open parenthese
                Do
                    Incr lCurrentPos                                    'increment the current position
                    If Mid$(Equation$, lCurrentPos, 1) = ")" Then Incr lCloseParentheseCounter    ' to count the number of parentheses
                    If Mid$(Equation$, lCurrentPos, 1) = "(" Then Incr lOpenParentheseCounter
                Loop Until lOpenParentheseCounter = lCloseParentheseCounter
    
                Equation$ = Left$(Equation$,lOpenParentheseStart-1)+ _    'recursive call to EvalExpNum
                              Format$(EvaluateEquation(Mid$(Equation$,lOpenParentheseStart+1,lCurrentPos-lOpenParentheseStart-1)))+ _
                              Right$(Equation$,-lCurrentPos)
            Else
                Data "ATN", "COS", "SIN", "TAN", "LOGTEN", "LOGTWO", "LOG", "EXPTEN"
                Data "EXPTWO", "EXP", "SQR", "ABS", "^", "*", "/", "\", "MOD", "_", "+"
                For lI = 1 To DataCount                ' check all the Operators/Functions that could be used in the numerical expression
                     Do                                ' examines all the occurences of the operator/function
                         lPosOperator = InStr(Equation$,Read$(lI))
                         If lPosOperator <> 0 Then               ' only if we find the Operator/Function
                             lLeftOperandEnd = lPosOperator-1    ' search the start/end of the left operand
                             lCurrentPos     = lPosOperator
                             Do
                                Decr lCurrentPos                     ' decrement current pos
                                If   lCurrentPos < 1 Then Exit Loop  ' if we are out of the string
                            Loop Until InStr(" 0123456789.-",Mid$(Equation$, lCurrentPos, 1)) = 0
                            lLeftOperandStart = lCurrentPos+1
    
                            lRightOperandStart = lPosOperator+Len(Read$(lI))    ' search the start/end of the right operand
                            lCurrentPos          = lPosOperator+Len(Read$(lI))-1
                            Do
                                Incr lCurrentPos                                     ' decrement current pos
                                If   lCurrentPos > Len(Equation$) Then Exit Loop   ' if we are out of the string
                            Loop Until InStr(" 0123456789.-",Mid$(Equation$, lCurrentPos, 1)) = 0
                            lRightOperandEnd = lCurrentPos - 1
    
                            lLeftOperand  = Val(Trim$(Mid$(Equation$,lLeftOperandStart ,lLeftOperandEnd -lLeftOperandStart +1))) ' extract the operands removing spaces
                            lRightOperand = Val(Trim$(Mid$(Equation$,lRightOperandStart,lRightOperandEnd-lRightOperandStart+1))) ' extract the operands removing spaces
    
                            Select Case Read$(lI)                     ' depending of the Operator/Function
                                Case "ATN"     :  lEval = Atn(lRightOperand)
                                Case "COS"     :  lEval = Cos(lRightOperand)
                                Case "SIN"     :  lEval = Sin(lRightOperand)
                                Case "TAN"     :  lEval = Tan(lRightOperand)
                                Case "LOGTEN"  :  lEval = Log10(lRightOperand)
                                Case "LOGTWO"  :  lEval = Log2(lRightOperand)
                                Case "LOG"     :  lEval = Log(lRightOperand)
                                Case "EXPTEN"  :  lEval = Exp10(lRightOperand)
                                Case "EXPTWO"  :  lEval = Exp2(lRightOperand)
                                Case "EXP"     :  lEval = Exp(lRightOperand)
                                Case "SQR"     :  lEval = Sqr(lRightOperand)
                                Case "ABS"     :  lEval = Abs(lRightOperand)
                                Case "^"       :  lEval = lLeftOperand ^ lRightOperand
                                Case "*"       :  lEval = lLeftOperand * lRightOperand
                                Case "/"       :  lEval = lLeftOperand / lRightOperand
                                Case "\"       :  lEval = lLeftOperand \ lRightOperand
                                Case "MOD"     :  lEval = lLeftOperand Mod lRightOperand
                                Case "_"       :  lEval = lLeftOperand - lRightOperand
                                Case "+"       :  lEval = lLeftOperand + lRightOperand
                            End Select
                            lEval = Round(lEval, 2)  'round the evaluation to 6 decimal places to avoid scientific notation (E-)
                            Equation$ = Left$(Equation$,lLeftOperandStart-1)+Format$(lEval)+Right$(Equation$,-lRightOperandEnd) 'place the result of the evaluation in the string
                        End If
                     Loop Until lPosOperator = 0
                 Next lI
                Function = Val(Equation$)  'to evaluate the final expression
            End If
        Loop Until lOpenParentheseStart = 0
    
    End Function
    
    Sub GDIPlus_SaveImage(hGraphicDC As Dword, imgFormat As String, fName As WStringZ)
    
       'initialize GDIPlus
       Local token As Dword, StartupInput As GdiplusStartupInput, sMimeType As String
       StartupInput.GdiplusVersion = 1
       GdiplusStartup(token, StartupInput, ByVal %NULL)
    
       'Select Mime Type
       Select Case imgFormat
          Case "bmp" :  sMimeType = "image/bmp"
          Case "jpg" :  sMimeType = "image/jpeg"
          Case "gif" :  sMimeType = "image/gif"
          Case "png" :  sMimeType = "image/png"
       End Select
    
       'save the image
       Local s As String, sEncoderClsid As Guid, pImage, hBitmap, pGraphics As Dword
       s = GDIPlusGetEncoderClsid((sMimeType))
       sEncoderClsid = Guid$(s)
    
       hBitmap = GetCurrentObject(hGraphicDC, %OBJ_Bitmap)              'from graphic target
       GDIpCreateBitmapFromHBITMAP( hBitmap, ByVal %Null, pImage)       'create GDI+ image (pImage)
       GdipCreateFromHDC hGraphicDC, pGraphics                          'create graphic object containing Graphic Control
       GdipDrawImageRect pGraphics, pImage, 0, 0, 140, 110              'use (0,0)-(140,110)
       GdipSaveImageToFile pImage,(fName), sEncoderClsid, ByVal %Null   'save to file
    
       If pImage Then GdipDisposeImage(pImage)                          'cleanup
       If pGraphics Then GdipDeleteGraphics(pGraphics)   'GDIP cleanup
    
       'shut down GDI+
        GdiplusShutdown token
    End Sub
    
    Sub LoadBGImage(wFileName As WStringZ * %Max_Path, hBMP As Dword)
       'load JPG/GIF/PNG image to memory bitmap from file
       Local pImage,pGraphics,token,hDC As Dword, StartupInput As GdiplusStartupInput, imgW, imgH As Long
    
       'initialize GDIPlus
       StartupInput.GdiplusVersion = 1
       GdiplusStartup(token, StartupInput, ByVal %NULL)
    
       'load image/get properties
       GdipLoadImageFromFile((wFileName), pImage)          'pImage - image object
       GdipGetImageWidth(pImage,imgW)                      'get width
       GdipGetImageHeight(pImage,imgH)                     'get height
    
       'put in Graphic Memory Bitmap
       Graphic Bitmap New imgW,imgH To B.hBGImage
       Graphic Attach B.hBGImage,0
       Graphic Get DC To hDC                               'hDC is for memory bitmap
    
       GdipCreateFromHDC(hDC, pGraphics)                   'create graphic object
       GdipDrawImageRect(pGraphics, pImage, 0,0,imgW,imgH) 'draw image at 0,0
    
       'cleanup
       If pImage Then GdipDisposeImage(pImage)             'GDIP cleanup
       If pGraphics Then GdipDeleteGraphics(pGraphics)     'GDIP cleanup
       GdiplusShutdown token                               'Shutdown GDI+
    End Sub
    
    Sub LoadStamp(wFileName As WStringZ * %Max_Path, x As Long, y As Long, wCont As Long, hCont As Long, hDC As Dword, Centered As Long, Zoom As Long)
       'load JPG/GIF/PNG image to DC from file. Zoom=-1 means fit to size
       Local pImage,pGraphics,token As Dword, StartupInput As GdiplusStartupInput, imgW, imgH, wNew, hNew As Long
    
       'initialize GDIPlus
       StartupInput.GdiplusVersion = 1                     'startup
       GdiplusStartup(token, StartupInput, ByVal %NULL)    'startup
    
       'load image/get properties
       GdipLoadImageFromFile((wFileName), pImage)          'pImage - image object
       GdipGetImageWidth(pImage,imgW)                      'get width
       GdipGetImageHeight(pImage,imgH)                     'get height
    
       GdipCreateFromHDC(hDC, pGraphics)                   'create graphic object
       If Zoom = -1 Then
          wNew = imgW / Max(imgW / wCont, imgH / hCont)
          hNew = imgH / Max(imgW / wCont, imgH / hCont)
          x = (wCont-wNew)/2 : y = (hCont-hNew)/2
       Else
          wNew = imgW/Zoom : hNew = imgH/Zoom
          If Centered Then x = x-wNew/2 : y = y-hNew/2
       End If
       GdipDrawImageRect(pGraphics, pImage, x,y,wNew,hNew) 'draw image at 0,0
    
       'cleanup
       If pImage Then GdipDisposeImage(pImage)             'GDIP cleanup
       If pGraphics Then GdipDeleteGraphics(pGraphics)     'GDIP cleanup
       GdiplusShutdown token                               'Shutdown GDI+
    End Sub
    
    Sub DisplayStampList
       Local i,iCount,x,y,iLargeStamp As Long, fName$, temp$
       iCount = ParseCount(B.StampList,";;;")
       For i = 1 To iCount
          temp$ = Parse$(B.StampList,";;;",i)
          If Len(Trim$(temp$)) = 0 Then Iterate For
          x      = Val(Parse$(temp$,",",1))
          y      = Val(Parse$(temp$,",",2))
          fName$ = Parse$(temp$,",",3)
          iLargeStamp  = Val(Parse$(temp$,",",4))
          LoadStamp ((fName$), x, y, 0, 0, B.hGraphicDC, %True,iLargeStamp)   '%True = centered at point
       Next i
       Graphic ReDraw
    End Sub
    
    Sub SaveChartFile(fName$)
       Local i As Long
       Open fName$ For Binary As #1
       Put #1,,B
       i = UBound(D)
       Put #1,,i
       Put #1,,D()
       Close #1
    End Sub
    
    Sub OpenChartFile(fName$)
       Local i As Long
       Open fName$ For Binary As #1
       Get #1,, B
       Get #1,, i
       ReDim D(1 To i)
       Get #1,, D()
       Close #1
    
       B.hParent       = hDlg
       B.cID           = %IDC_Graphic
       B.hGraphic      = hGraphic
    
       Graphic Attach hDlg, %IDC_Graphic, ReDraw
       Graphic Clear
       Graphic Get DC To B.hGraphicDC
    
       LoadBGImage ((B.BGImage), B.hBGImage)
    
       CreateFonts
    
       Statusbar Set Text hDlg, %IDC_StatusBar, 4, 0, Choose$(B.GraphType," 2D Bar", " 3D Bar", " Symbols", " Line", " 2-Line", " 3-Line", " 2-Bar Stacked", " 3-Bar Stacked", " Bar Group", " Pie", " 2-Pie", " 3-Pie", " HiLo") + " Chart"
    
    End Sub
    
    Function SaveChartAs() As Long
        Local title$, startfolder$, filter$, startfile$, defaultext$, flags&, filevar$, countvar&
        title$       = ""                                   'caption title. if "", then "Save As" is displayed
        startfolder$ = IIf$(IsFile(CFN), CFN, Exe.Path$ + "charts")           'initial folder to be displayed
        filter$      = "Chart Files" + $Nul + "*.gbc" + $Nul
        startfile$   = IIf$(IsFile(CFN), CFN, "")           'name of currently opened file
        defaultext$  = "gbc"                                'default extension to append to selection if user does not enter it
        flags& = %OFN_PathMustExist Or %OFN_Explorer Or %OFN_OverWritePrompt
        Display Savefile hDlg, 100, 100, title$, startfolder$, filter$, startfile$, defaultext$, flags& To filevar$, countvar&
        If Len(filevar$) Then
           CFN = filevar$
           Dialog Set Text hDlg, "gbChartMaster    v" + $Ver + "    " + CFN
           SaveChartFile((CFN))
           Function = 1
        End If
    End Function
    
    Sub SelectChartToOpen
        Local title$, startfolder$, filter$, startfile$, defaultext$, flags&, filevar$, countvar&
        title$       = ""                                                    'caption title. if "", then "Save As" is displayed
        startfolder$ = IIf$(IsFile(CFN), CFN, Exe.Path$ + "charts")       'initial folder to be displayed
        filter$      = "Chart Files" + $Nul + "*.gbc" + $Nul
        startfile$   = IIf$(IsFile(CFN), CFN, "")                            'name of currently opened file
        defaultext$  = "gbc"                                                 'default extension to append to selection if user does not enter it
        flags& = %OFN_PathMustExist Or %OFN_Explorer Or %OFN_OverWritePrompt
        Display Openfile hDlg, 100, 100, title$, startfolder$, filter$, startfile$, defaultext$, flags& To filevar$, countvar&
        If Len(filevar$) Then
           CFN = filevar$
           Dialog Set Text hDlg, "gbChartMaster    v" + $Ver + "    " + CFN
           OpenChartFile((CFN))
           DrawChart D(), B, %True : DisplayStampList
        End If
    End Sub
    
    Sub EraseLastStamp
       Local i,iCount As Long, temp$
       iCount = ParseCount(B.StampList,";;;")
       For i = 1 To iCount-1 : temp$ += ";;;" + Parse$(B.StampList,";;;",i) : Next i
       B.StampList = temp$
       DrawChart D(), B, %True : DisplayStampList
    End Sub
    
    Sub CreateContextMenu
      Menu New PopUp To hContext
      Menu Add String, hContext, "Cut",  %IDM_Cut,  %MF_Enabled
      Menu Add String, hContext, "Copy", %IDM_Copy, %MF_Enabled
      Menu Add String, hContext, "Paste",  %IDM_Paste,  %MF_Enabled
      Menu Add String, hContext, "Delete", %IDM_Delete,  %MF_Enabled
    End Sub
    
    Function NewEditProc(ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
       Local x As Long, y As Long
       Select Case Msg
          Case %WM_ContextMenu
             x = Lo(Word,lParam) : y = Hi(Word, lParam)    'WM_ContextMenu returns xy coordinates of mouse
             TrackPopupMenu hContext, %TPM_LeftAlign, x, y, 0, hDlg, ByVal 0   'put context menu where mouse is
             Function = 0 : Exit Function
       End Select
       Function = CallWindowProc(OldEditProc, hWnd, Msg, wParam, lParam)
    End Function
    
    Sub GetImageSize(wFileName As WStringZ * %Max_Path, w As Long, h As Long)
       'load JPG/GIF/PNG image to DC from file. Zoom=-1 means fit to size
       Local pImage,token As Dword, StartupInput As GdiplusStartupInput
    
       'initialize GDIPlus
       StartupInput.GdiplusVersion = 1                     'startup
       GdiplusStartup(token, StartupInput, ByVal %NULL)    'startup
    
       'load image/get properties
       GdipLoadImageFromFile((wFileName), pImage)          'pImage - image object
       GdipGetImageWidth(pImage,w)                         'get width
       GdipGetImageHeight(pImage,h)                        'get height
    
       'cleanup
       If pImage Then GdipDisposeImage(pImage)             'GDIP cleanup
       GdiplusShutdown token                               'Shutdown GDI+
    End Sub
    
    Function NextFile(CurrentFile$, Mask$) As String
       Local temp$, FilePath$
       Function = CurrentFile$
       If IsFalse IsFile(CurrentFile$) Then Exit Function
       FilePath$ = PathName$(Path,CurrentFile$)
       temp$ = Dir$(FilePath$ + Mask$)
       While Len(temp$)
          If LCase$(FilePath$ + temp$) = LCase$(CurrentFile$) Then
             temp$ = Dir$(Next)
             Function = FilePath$ + IIf$(Len(temp$), temp$, Dir$(FilePath$ + Mask$)) : Exit Function
          End If
          temp$ = Dir$(Next)
       Wend
    End Function
    
    Sub SetRC(rc As Rect, i As Long)
       Select Case B.GraphType
          Case %Chart_2D, %Chart_3D
             rc = D(i).rc(B.DataSet)
          Case %Chart_2Stack
             rc = D(i).rc(2)
             rc.nTop    += D(i).rc(1).Top - D(i).rc(1).Bottom
             rc.nBottom = D(i).rc(1).Bottom
          Case %Chart_3Stack
             rc = D(i).rc(3)
             rc.nTop    += D(i).rc(1).Top - D(i).rc(1).Bottom + D(i).rc(2).top - D(i).rc(2).bottom
             rc.nBottom = D(i).rc(1).Bottom
          Case %Chart_HiLo
             rc.left   = D(i).rc(3).left
             rc.top    = D(i).rc(3).Top
             rc.bottom = D(i).rc(2).Bottom
             rc.right  = D(i).rc(2).right
       End Select
    End Sub
    
    Function SaveAsSettings() As Long
        Local title$, startfolder$, filter$, startfile$, defaultext$, flags&, filevar$, countvar&
        title$       = ""                                   'caption title. if "", then "Save As" is displayed
        startfolder$ = IIf$(IsFile(CFNS), CFNS, Exe.Path$ + "settings")           'initial folder to be displayed
        filter$      = "Chart Settings" + $Nul + "*.gbt" + $Nul
        startfile$   = IIf$(IsFile(CFNS), CFNS, "")           'name of currently opened file
        defaultext$  = "gbt"                                  'default extension to append to selection if user does not enter it
        flags& = %OFN_PathMustExist Or %OFN_Explorer Or %OFN_OverWritePrompt
        Display Savefile hDlg, 100, 100, title$, startfolder$, filter$, startfile$, defaultext$, flags& To filevar$, countvar&
        If Len(filevar$) Then
           CFNS = filevar$
           Open CFNS For Binary As #1
           Put #1,,B
           Close #1
           Function = 1
        End If
    End Function
    
    Sub SelectSettingsToOpen
        Local title$, startfolder$, filter$, startfile$, defaultext$, flags&, filevar$, countvar&
        title$       = ""                                                    'caption title. if "", then "Save As" is displayed
        startfolder$ = IIf$(IsFile(CFNS), CFNS, Exe.Path$ + "settings")       'initial folder to be displayed
        filter$      = "Chart Settings" + $Nul + "*.gbt" + $Nul
        startfile$   = IIf$(IsFile(CFNS), CFNS, "")                            'name of currently opened file
        defaultext$  = "gbt"                                                 'default extension to append to selection if user does not enter it
        flags& = %OFN_PathMustExist Or %OFN_Explorer Or %OFN_OverWritePrompt
        Display Openfile hDlg, 100, 100, title$, startfolder$, filter$, startfile$, defaultext$, flags& To filevar$, countvar&
        If Len(filevar$) Then
           CFNS = filevar$
           OpenSettings((CFNS))
           DrawChart D(), B, %True : DisplayStampList
           If SettingsVisible Then Dialog End hSet : ShowSettingsDialog
        End If
    End Sub
    
    Sub OpenSettings(fName$)
       Open fName$ For Binary As #1
       Get #1,, B
       Close #1
    
       B.hParent       = hDlg
       B.cID           = %IDC_Graphic
       B.hGraphic      = hGraphic
    
       Graphic Attach hDlg, %IDC_Graphic, ReDraw
       Graphic Clear
       Graphic Get DC To B.hGraphicDC
    
       LoadBGImage ((B.BGImage), B.hBGImage)
       CreateFonts
       'Statusbar Set Text hDlg, %IDC_StatusBar, 4, 0, Choose$(B.GraphType," 2D Bar", " 3D Bar", " Symbols", " Line", " 2-Line", " 3-Line", " 2-Bar Stacked", " 3-Bar Stacked", " HiLo") + " Chart"
    End Sub
    
    Function PtInEllipse(rc As Rect, pt As Point, ArcStart As Single, ArcEnd As Single) As Long
       Local xCenter, yCenter, rx,ry As Long, r As Single
       rx = (rc.Right - rc.nLeft ) / 2    :    xCenter = rc.nLeft + rx
       ry = (rc.nBottom - rc.nTop ) / 2   :    yCenter = rc.nTop + ry
       Graphic Ellipse (xCenter-2,yCenter-2)-(xCenter+2,yCenter+2),%Red
       If ((pt.x - xCenter) ^ 2) / (rx^2) + ((pt.y - yCenter) ^2 ) / (ry^2) >= 1 Then Exit Function
       r = Atn( (pt.y-yCenter) / (pt.x-xCenter) )
       r = 6.28313 - r - Switch(pt.x < xCenter, 3.14159, pt.y < yCenter, 6.28318)
       If r >= ArcStart And r <= ArcEnd Then Function = 1
    End Function
    
    Sub SetFontButtonText
       Select Case B.GraphType
          Case %Chart_2D,%Chart_3D,%Chart_2Stack,%Chart_3Stack,%Chart_HiLo,%Chart_Horz2D,%Chart_Horz2Stack,%Chart_Horz3Stack,%Chart_VertBarGroup,%Chart_HorzBarGroup,%Chart_Symbols,%Chart_Line,%Chart_2Line,%Chart_3Line
             Control Set Text hSet, %IDC_TitleFont, "Chart Title Font"
             Control Set Text hSet, %IDC_axisTitleFont, "Axis Title Font"
             Control Set Text hSet, %IDC_axisValueFont, "Axis Values Font"
             Control Set Text hSet, %IDC_LabelFont, "Label Font"
          Case %Chart_Pie,%Chart_2Pie,%Chart_3Pie
             Control Set Text hSet, %IDC_TitleFont, "Chart Title Font"
             Control Set Text hSet, %IDC_axisTitleFont, "Legend Font"
             Control Set Text hSet, %IDC_axisValueFont, "Wedge% Font"
             Control Set Text hSet, %IDC_LabelFont, "Label Font"
       End Select
    End Sub
    And the include file code is here:
    Code:
    Enum ChartEquates Singular
       Chart_2D        = 1
       Chart_3D
       Chart_Symbols
       Chart_Line
       Chart_2Line
       Chart_3Line
       Chart_2Stack
       Chart_3Stack
       Chart_HiLo
       Chart_Pie
       Chart_2Pie
       Chart_3Pie
       Chart_Horz2D
       Chart_Horz2Stack
       Chart_Horz3Stack
       Chart_VertBarGroup
       Chart_HorzBarGroup
    
       Gradient_None                   = 1
       Gradient_DarkBottomToTop
       Gradient_LightCenterToDarkSide
       Gradient_ColorCentertoBlackSide
       Gradient_Background
    
       Symbol_Point = 1
       Symbol_Circle
       Symbol_Triangle
       Symbol_Square
    
       MainTitle_Left = 1
       MainTitle_Center
       MainTitle_Right
    
       YTitle_Top = 1
       YTitle_Center
       YTitle_Bottom
    
       XTitle_LeftInLine = 1
       XTitle_Left
       XTitle_Center
       XTitle_Right
       XTitle_RightInLine
    
       HiLo_Bar = 1
       HiLo_Beam
       HiLo_Dot
    
       Line_Solid = 0
       Line_Dash
       Line_Dot
       Line_DashDot
       Line_DashDotDot
    
       Label_Label = 1
       Label_Value
       Label_PerCent
       Label_AltXText
    End Enum
    
    Type ChartData
       v(3)        As Long
       rc(3)       As Rect
       pt(3)       As Point
       Visible(3)  As Long
       altColor(3) As Long
    
       RR          As Long  'temp values variables created for convenience
       GG          As Long
       BB          As Long
       FadedColor  As Long
       DarkFadedColor As Long
       BorderColor As Long
    
       selected(3) As Long
       altXText(3) As StringZ * 50
       Label(3)    As StringZ * 50
       arcEnd(3)   As Single
       arcStart(3) As Single
       unusedA(3)  As Long
       unusedB(3)  As Long
       unusedC(3)  As StringZ * 50
       unusedD(3)  As StringZ * 50
    
       unusedE As Long
       unusedF As Long
       unusedG As StringZ * 50
       unusedH As StringZ * 50
    End Type
    
    Type ChartPolyPoints
       Count As Long
       x1 As Single
       y1 As Single
       x2 As Single
       y2 As Single
       x3 As Single
       y3 As Single
       x4 As Single
       y4 As Single
       x5 As Single
       y5 As Single
       x6 As Single
       y6 As Single
    End Type
    
    Type ChartSettings
       hParent        As Dword
       cID            As Long
       hGraphic       As Dword
       hGraphicDC     As Dword
       hBGImage       As Dword
       LM             As Long
       RM             As Long
       TM             As Long
       BM             As Long
       Title          As StringZ * 100
       XTitle         As StringZ * 100
       YTitle         As StringZ * 100
       MainTitleLoc   As Long
       XTitleLoc      As Long
       YTitleLoc      As Long
       DivYCount      As Long
       XMax           As Long
       XMin           As Long
       maxYvalue      As Long
       usefixedYvalue As Long
       fixedYValue    As Long
       coverage       As Single
       Pivot          As Long
       FadeValue      As Long
       AllBars        As Long
       ShowHGrid      As Long
       ShowVGrid      As Long
       ShowMainTitle  As Long
       DotGrid        As Long
       ShowMargins    As Long
       SpeedTest      As Long
       Instructions   As Long
       ShowAxisTitles As Long
       ShowAxisValues As Long
       UseAntiAliasing  As Long
       HoverTips      As Long
    
       DataSetTitle(3) As StringZ * 100
    
       UserData(3)   As StringZ * 5000
       altXText(3)   As StringZ * 5000
       Labels(3)  As StringZ * 5000
       BarColors(3)  As StringZ * 5000
    
       StampList     As StringZ * 5000   'approximately 16 stamps  x,y,filename:::x,y,filename:::   filename must be in \stamps
    
       GraphType     As Long
       BarGradientType  As Long  '1=flat  2=dark color bottom to color on top 3=lightcolor center, fade to color on each side 4=color center, fade to black on each side
    
       ThreeDX       As Long
       ThreeDY       As Long
    
       BezierTension As Single
       BezierDT      As Single
    
       PieRadius     As Long   'size of Pie radius
       PieCircle     As Long
       PieEject      As Long   'explode only selected section
       PieExplode    As Long   'explode all sections
       PieExplodeDistance As Long
       PieRotate     As Long   'use PieAngle
       PieAngle      As Single 'rotation of pie
       PieLegend     As Long   ' color with label/value
       PiePerCent    As Long   'show % inside pie
       PieDonut      As Long   'open center = 33% of radius
       PieDonutCaption(3) As StringZ * 100
       Pie3D         As Long
       Pie3DThickness As Long
       PieBeveled    As Long
       PieGradient   As Long
       PieGradientValue  As Long
       PieHideUnSelected As Long
       PieHighlightSelected As Long
    
       InstructFont     As Dword
       InstructFontName As StringZ * 100
       InstructFontSize As Dword
       InstructFontBold As Dword
    
       titleFont     As Dword
       titleFontName As StringZ * 100
       titleFontSize As Long
       titleFontBold As Long
    
       axisTitleFont As Dword
       axisTitleFontR As Dword
       axisTitleFontName As StringZ * 100
       axisTitleFontSize As Long
       axisTitleFontBold As Long
    
       axisValueFont As Dword
       axisValueFontR As Dword
       axisValueFontName As StringZ * 100
       axisValueFontSize As Long
       axisValueFontBold As Long
    
       LabelFont     As Dword
       LabelFontR    As Dword
       LabelFontName As StringZ * 100
       LabelFontSize As Long
       LabelFontBold As Long
    
       useAltColors  As Long
       usealtXText    As Long
       gradientBG    As Long
       fadeBG        As Long
       colorUnder    As Long
    
       cGrid         As Long
       cBG           As Long
       cTitle        As Long
       cAxisLines    As Long
       cAxisValues   As Long
       cPreBars(3)   As Long
       cPostBars(3)  As Long
       cSymbols(3)   As Long
    
       BarBorder     As Long
       ShowBarLabel  As Long
       Annotation    As Long
       ShowDataSetTitles As Long
       VertBarLabels As Long
       RoundedBar    As Long
       RoundValue    As Long
       MinusYAxis    As Long
       VertYTitle    As Long
       AutoXCount    As Long
       ExportFormat  As Long
       Equation(3)   As StringZ * 100
       EquationAnimate As Long
       Stamp         As StringZ * 256
       LargeStamp    As Long
       ShowBGImage   As Long
       BGImage       As StringZ * 256
       BGImageFit    As Long
       LineSymbol    As Long
       HiLoSymbol    As Long
       LineThickness As Long
       SymbolSize    As Long
       Interval      As Long
       DataSet       As Long
    
       GridOnTop     As Long
       SmoothLines   As Long
       LineStyle     As Long
       LabelType     As Long
    
       unusedA As Long
       unusedB As Long
       unusedC As Long
       unusedD As Long
       unusedE As Long
    
       unusedF As StringZ * 100
       unusedG As StringZ * 100
       unusedH As StringZ * 256
       unusedI As StringZ * 256
       unusedJ As StringZ * 5000
    
    End Type
    
    Sub DrawChart(BCD() As ChartData, BC As ChartSettings, EraseChart As Long)       'DataSet = 1,2,3 which is v, v2, v3 from data TYPE
       Local i,j,iDataSet,x1,iSymbol,bgW,bgH,txtW, txtH, gW, gH, BarWidth, BarCount,MaxXTextWidth As Long, temp$, oldrc,oldrc2,oldrc3, rc As Rect
       Local tW, tH, iStep, iCount, DivYValue As Long, iColor As Long
       Local tempBCLM, tempBCTM, tempBCRM, tempBCBM As Long
       Local qFreq, qStart, qStop As Quad
       Dim DataTotal(3) As Long
    
       'Call
       Select Case BC.GraphType
          Case %Chart_Pie
             DrawPieChart(BCD(), BC,1,1,1,BC.DataSet,1) : Exit Sub
          Case %Chart_2Pie
             DrawPieChart(BCD(), BC,1,2,1,1,0)
             DrawPieChart(BCD(), BC,2,2,0,2,1) : Exit Sub
          Case %Chart_3Pie
             DrawPieChart(BCD(), BC,1,3,1,1,0)
             DrawPieChart(BCD(), BC,2,3,0,2,0)
             DrawPieChart(BCD(), BC,3,3,0,3,1) : Exit Sub
       End Select
    
       If BC.SpeedTest Then QueryPerformanceFrequency qFreq : QueryPerformanceCounter qStart
    
       'Clear the Graphic control
       Graphic Attach BC.hGraphic, 0, ReDraw
       If EraseChart Then Graphic Clear BC.cBG
       Graphic Get Client To gW,gH
       Graphic Width 1
       Graphic Set Overlap
    
       'Draw Background - gradient or image
       If BC.ShowBGImage Then
          If BC.BGImageFit Then
             Graphic Attach BC.hBGImage, 0
             Graphic Get Canvas To bgW, bgH
             Graphic Attach BC.hGraphic, 0, ReDraw
             Graphic Stretch BC.hBGImage, 0, (0,0)-(bgW-1,bgH-1) To (0,0)-(gW-1,gH-1), %Mix_CopySrc, %HalfTone
          Else
             Graphic Copy BC.hBGImage, 0
          End If
       ElseIf BC.GradientBG Then
          Graphic Get Canvas To rc.nRight,rc.nBottom
          i = BC.BarGradientType
          BC.BarGradientType = %Gradient_Background
          DrawOneBar BCD(), rc, BC, BC.cBG, 0, oldRC
          BC.BarGradientType = i
       End If
    
       'Determine maximum Y value in DataSet
       BC.maxYvalue = 0
       Select Case BC.GraphType
          Case %Chart_2D,%Chart_3D,%Chart_Symbols,%Chart_Line
             For i = BC.Xmin To BC.XMax
                BC.maxYvalue = Max(BC.maxYvalue,BCD(i).v(BC.DataSet))
             Next i
          Case %Chart_2Line
             For i = BC.Xmin To BC.XMax
                BC.maxYvalue = Max(BC.maxYvalue,BCD(i).v(1))
                BC.maxYvalue = Max(BC.maxYvalue,BCD(i).v(2))
             Next i
          Case %Chart_3Line, %Chart_HiLo
             For i = BC.Xmin To BC.XMax
                BC.maxYvalue = Max(BC.maxYvalue,BCD(i).v(1))
                BC.maxYvalue = Max(BC.maxYvalue,BCD(i).v(2))
                BC.maxYvalue = Max(BC.maxYvalue,BCD(i).v(3))
             Next i
          Case %Chart_2Stack
             For i = BC.Xmin To BC.XMax
                BC.maxYvalue = Max(BC.maxYvalue,BCD(i).v(1)+BCD(i).v(2))
             Next i
          Case %Chart_3Stack
             For i = BC.Xmin To BC.XMax
                BC.maxYvalue = Max(BC.maxYvalue,BCD(i).v(1)+BCD(i).v(2)+BCD(i).v(3))
             Next i
       End Select
       'Round up actual max value or use fixed setting
       If BC.UseFixedYValue Then
          BC.MaxYValue = BC.FixedYValue
       Else
          Select Case BC.MaxYValue
             Case <= 10       : BC.MaxYValue = 10
             Case <= 25       : BC.MaxYValue = 25
             Case <= 50       : BC.MaxYValue = 50
             Case <= 75       : BC.MaxYValue = 75
             Case <= 100      : BC.MaxYValue = 100
             Case <= 250      : BC.MaxYValue = 250
             Case <= 500      : BC.MaxYValue = 500
             Case <= 750      : BC.MaxYValue = 750
             Case <= 1000     : BC.MaxYValue = 1000
             Case <= 2500     : BC.MaxYValue = 2500
             Case <= 5000     : BC.MaxYValue = 5000
             Case <= 7500     : BC.MaxYValue = 7500
             Case <= 10000    : BC.MaxYValue = 10000
             Case <= 25000    : BC.MaxYValue = 25000
             Case <= 50000    : BC.MaxYValue = 50000
             Case <= 75000    : BC.MaxYValue = 75000
             Case <= 100000   : BC.MaxYValue = 100000
             Case <= 250000   : BC.MaxYValue = 250000
             Case <= 500000   : BC.MaxYValue = 500000
             Case <= 750000   : BC.MaxYValue = 750000
             Case <= 1000000  : BC.MaxYValue = 1000000
             Case <= 2500000  : BC.MaxYValue = 2500000
             Case <= 5000000  : BC.MaxYValue = 5000000
             Case <= 7500000  : BC.MaxYValue = 7500000
             Case <= 10000000 : BC.MaxYValue = 10000000
          End Select
       End If
    
       'Adjust Margins so the Titles will fit
       tempBCLM = BC.LM : tempBCRM = BC.RM : tempBCTM = BC.TM : tempBCBM = BC.BM
       If BC.ShowAxisTitles Then
          Select Case BC.XTitleLoc
             Case %XTitle_Left, %XTitle_Center, %XTitle_Right
                Graphic Set Font BC.axisValueFont
                Graphic Text Size "88" To i,j
                Graphic Set Font BC.axisTitleFont
                Graphic Text Size BC.XTitle To txtW, txtH
                BC.BM = Max(BC.BM, 10 + j + txtH)
             Case %XTitle_RightInline
                Graphic Set Font BC.axisTitleFont
                Graphic Text Size BC.XTitle To txtW, txtH
                BC.RM = Max(BC.RM, 40 + txtW)
             Case %XTitle_LeftInline
                Graphic Set Font BC.axisTitleFont
                Graphic Text Size BC.XTitle To txtW, txtH
                BC.LM = Max(BC.LM, 40 + txtW)
          End Select
    
          If BC.VertYTitle Then
             Graphic Set Font BC.axisTitleFontR
             Graphic Text Size BC.YTitle To txtW, txtH
             BC.LM = Max(BC.LM, 40 + txtH + Graphic(Text.Size.Y,Str$(BC.MaxYValue)))
          Else
             Graphic Set Font BC.axisTitleFont
             Graphic Text Size BC.YTitle To txtW, txtH
             BC.LM = Max(BC.LM, 40 + txtW + Graphic(Text.Size.X,Str$(BC.MaxYValue)))
          End If
    
          If BC.ShowDataSetTitles Then
                Graphic Set Font BC.axisTitleFont
                Graphic Text Size BC.DataSetTitle(1) To txtW, txtH
                BC.RM = Max(BC.RM, 40 + txtW)
                Graphic Text Size BC.DataSetTitle(2) To txtW, txtH
                BC.RM = Max(BC.RM, 40 + txtW)
                Graphic Text Size BC.DataSetTitle(3) To txtW, txtH
                BC.RM = Max(BC.RM, 40 + txtW)
          End If
    
       End If
    
       'Draw Axis Lines
       Graphic Color BC.cAxisLines, BC.cAxisLines
       If BC.MinusYAxis Then
          Graphic Line (BC.LM,BC.TM-5)-(BC.LM,gH-10), BC.cGrid    'both vertical axis
       Else
          Graphic Line (BC.LM,gH-BC.BM)-(BC.LM,BC.TM-5), BC.cGrid  'vertical axis
       End If
       Graphic Line (BC.LM,gH-BC.BM)-(gW-BC.RM,gH-BC.BM), BC.cGrid 'horizontal axis
    
       'Draw Instructions
       If BC.Instructions Then
          Graphic Set Font BC.InstructFont
          Graphic Width 1
          Graphic Style 2
          Graphic Color BC.cTitle, -2  'BC.cBG
          Graphic Box (0,0)-(20,20),,%Red, -2         'top left
          Graphic Box (gW-1,0)-(gW-21,20),,%Red, -2     'top right
          Graphic Box (0,gH-1)-(20,gH-21),,%Red, -2     'bottom left
          Graphic Box (gW-1,gH-1)-(gW-21,gH-21),,%Red, -2 'bottom right
          Graphic Style 0
          Graphic Width BC.LineThickness
    
          Graphic Set Font BC.axisValueFont
    '      Graphic Color BC.cTitle, -2  'BC.cBG
          'upper left
          Graphic Set Pos (25,10) : Graphic Print "Clk - Erase last symbol, DblClk - Erase all"
          'upper right
          temp$ = "DblClk - Remove Selections"
          Graphic Set Pos (gW - 25 - Graphic(Text.Size.X,temp$),10) : Graphic Print temp$
          'lower left
          Graphic Set Pos (25, gH - 2*Graphic(Text.Size.X,"C")) : Graphic Print "DblClk - Settings Dialog Repositioned"
          'lower right
          Graphic Set Pos (gW - 25 - Graphic(Text.Size.X,"DblClk - Settings"), gH - 2*Graphic(Text.Size.X,"C")) : Graphic Print "DblClk - Settings"
          'midleft
          Graphic Set Pos (10, gH/2 - 30)                              : Graphic Print "DblClk - Stamp"
          Graphic Set Pos (10, gH/2 - 30 + Graphic(Text.Size.Y,"C"))   : Graphic Print "RClick Bar - Select"
          Graphic Set Pos (10, gH/2 - 30 + 2*Graphic(Text.Size.Y,"C")) : Graphic Print "RClick - Settings"
       End If
    
       'Draw Top Title
       If BC.ShowMainTitle Then
          Graphic Color BC.cTitle, -2  'BC.cBG
          Graphic Set Font BC.titleFont
          BC.TM = Graphic(Text.Size.Y,BC.Title) * 2
          Graphic Text Size BC.Title To txtW, txtH
          Select Case BC.MainTitleLoc
             Case %MainTitle_Left   : Graphic Set Pos (BC.LM,BC.TM-1.5*txtH)
             Case %MainTitle_Center : Graphic Set Pos (BC.LM + (gW-BC.LM-BC.RM-txtW)/2, BC.TM - 1.5*txtH)
             Case %MainTitle_Right  : Graphic Set Pos (gW - BC.RM - txtW, BC.TM - 1.5*txtH)
          End Select
          Graphic Print BC.Title
       End If
    
       'Show Margins
       If BC.ShowMargins Then
          Graphic Color %Red
          Graphic Style 2
          Graphic Line (BC.LM,0)-(BC.LM,gH)
          Graphic Line (0,BC.TM)-(gW,BC.TM)
          Graphic Line (gW-BC.RM,0)-(gW-BC.RM,gH)
          Graphic Line (0,gH-BC.BM)-(gW,gH-BC.BM)
          Graphic Style 0
       End If
    
       'Draw X Axis Title
       If BC.ShowAxisTitles Then
          Graphic Set Font BC.axisValueFont
          Graphic Text Size "99" To i,j
          Graphic Color BC.cTitle, -2  'BC.cBG
          Graphic Set Font BC.axisTitleFont
          Graphic Text Size BC.XTitle To txtW, txtH
          Select Case BC.XTitleLoc
             Case %XTitle_LeftInline   : Graphic Set Pos (BC.LM-txtW-20,                   gH-BC.BM+10)
             Case %XTitle_Left         : Graphic Set Pos (BC.LM,                           gH-BC.BM+10+j)
             Case %XTitle_Center       : Graphic Set Pos (BC.LM + (gW-BC.LM-BC.RM-txtW)/2, gH-BC.BM+10+j)
             Case %XTitle_Right        : Graphic Set Pos (gW-BC.RM-txtW,                   gH-BC.BM+10+j)
             Case %XTitle_RightInLine  : Graphic Set Pos (gW-BC.RM+10,                     gH-BC.BM+10)
          End Select
          Graphic Print BC.XTitle
       End If
    
       'Draw Horizontal Grid
       If BC.GridOnTop = 0 Then
          For i = 1 To BC.DivYCount
             If BC.ShowHGrid And BC.DotGrid Then Graphic Style 2
             Graphic Line (BC.LM-2 ,gH-BC.BM-i*(gH-BC.TM-BC.BM) / BC.DivYCount) -(IIf(BC.ShowHGrid,gW-BC.RM,BC.LM+2),gH-BC.BM-i*(gH-BC.TM-BC.BM) / BC.DivYCount), BC.cGrid
             Graphic Style 0
          Next i
       End If
    
       'Draw Y Axis Values
       Graphic Set Font BC.axisValueFont
       Graphic Color BC.cAxisValues, -2
       DivYValue = BC.maxYValue/BC.DivYCount
       For i = 1 To BC.DivYCount
          temp$ = Format$(i * DivYValue, "##,###,##0")
          Graphic Set Pos (BC.LM - Graphic(Text.Size.X, temp$) - 5,gH-BC.BM-i*(gH-BC.TM-BC.BM) / BC.DivYCount-Graphic(Text.Size.Y,temp$)/2)
          Graphic Print temp$
       Next i
    
       'Draw Y Axis Title
       If BC.ShowAxisTitles Then
          Graphic Color BC.cTitle, -2  'BC.cBG
          If BC.VertYTitle Then
             Graphic Set Font BC.axisTitleFontR
             Graphic Text Size BC.YTitle To txtW, txtH
             Select Case BC.YTitleLoc
                Case %YTitle_Top    : Graphic Set Pos  (BC.LM-txtH-Graphic(Text.Size.X,Str$(BC.MaxYValue)), BC.TM + txtW)
                Case %YTitle_Center : Graphic Set Pos  (BC.LM-txtH-Graphic(Text.Size.X,Str$(BC.MaxYValue)), BC.TM + (gH-BC.TM-BC.BM+txtW)/2)
                Case %YTitle_Bottom : Graphic Set Pos  (BC.LM-txtH-Graphic(Text.Size.X,Str$(BC.MaxYValue)), gH - BC.BM)
             End Select
          Else
             Graphic Set Font BC.axisTitleFont
             Graphic Text Size BC.YTitle To txtW, txtH
             Select Case BC.YTitleLoc
                Case %YTitle_Top    : Graphic Set Pos  (BC.LM-20-txtW-Graphic(Text.Size.X,Trim$(Str$(BC.MaxYValue))), BC.TM - txtH/2)
                Case %YTitle_Center : Graphic Set Pos  (BC.LM-20-txtW-Graphic(Text.Size.X,Trim$(Str$(BC.MaxYValue))), BC.TM + (gH-BC.TM-BC.BM-txtH)/2)
                Case %YTitle_Bottom : Graphic Set Pos  (BC.LM-20-txtW-Graphic(Text.Size.X,Trim$(Str$(BC.MaxYValue))), gH - BC.BM - txtH)
             End Select
          End If
          Graphic Print BC.YTitle
       End If
    
       'Initialize Bar Settings
       For i = 1 To UBound(BCD)
          Reset BCD(i).rc(1)      , BCD(i).rc(2)      , BCD(i).rc(3)
          Reset BCD(i).visible(1) , BCD(i).visible(2) , BCD(i).visible(3)
          DataTotal(1) += BCD(i).v(1)
          DataTotal(2) += BCD(i).v(2)
          DataTotal(3) += BCD(i).v(3)
       Next i   'reset all of the previous bar rectangles
       iStep = 1
    
       'get maximum width of X-data - take into account largest value and alt-Text)
       If BC.UsealtXText Then
          For i = BC.Xmin To BC.XMax
             MaxXTextWidth = Max(MaxXTextWidth, Graphic(Text.Size.X,BCD(i).altXText(BC.DataSet)))
             If BC.GraphType = %Chart_2D Or BC.GraphType = %Chart_2Line Then
                MaxXTextWidth = Max(MaxXTextWidth, Graphic(Text.Size.X,BCD(i).altXText(1)))
                MaxXTextWidth = Max(MaxXTextWidth, Graphic(Text.Size.X,BCD(i).altXText(2)))
             ElseIf BC.GraphType = %Chart_3D Or BC.GraphType = %Chart_3Line Or BC.GraphType = %Chart_HiLo Then
                MaxXTextWidth = Max(MaxXTextWidth, Graphic(Text.Size.X,BCD(i).altXText(1)))
                MaxXTextWidth = Max(MaxXTextWidth, Graphic(Text.Size.X,BCD(i).altXText(2)))
                MaxXTextWidth = Max(MaxXTextWidth, Graphic(Text.Size.X,BCD(i).altXText(3)))
             End If
          Next i
       Else
          MaxXTextWidth = Graphic(Text.Size.X,LTrim$(Str$(BC.XMax)))
       End If
       'take into account width of BarLabel
       If BC.ShowBarLabel Then
          For i = BC.Xmin To BC.XMax
             Select Case BC.LabelType
                Case %Label_Value    : temp$ = Format$(BCD(i).v(BC.DataSet), "###,###,##0")
                Case %Label_Label    : temp$ = BCD(i).label(BC.DataSet)
                Case %Label_PerCent  : temp$ = Format$(BCD(i).v(BC.DataSet) / DataTotal(BC.DataSet) * 100, "#0.0") + "%"
                Case %Label_AltXText : temp$ = BCD(i).altXText(BC.DataSet)
             End Select
             MaxXTextWidth = Max(MaxXTextWidth, Graphic(Text.Size.X,temp$))
             If BC.GraphType = %Chart_2D Or BC.GraphType = %Chart_2Line Then
                MaxXTextWidth = Max(MaxXTextWidth, Graphic(Text.Size.X,BCD(i).label(1)))
                MaxXTextWidth = Max(MaxXTextWidth, Graphic(Text.Size.X,BCD(i).label(2)))
             ElseIf BC.GraphType = %Chart_3D Or BC.GraphType = %Chart_3Line Or BC.GraphType = %Chart_HiLo Then
                MaxXTextWidth = Max(MaxXTextWidth, Graphic(Text.Size.X,BCD(i).label(1)))
                MaxXTextWidth = Max(MaxXTextWidth, Graphic(Text.Size.X,BCD(i).label(2)))
                MaxXTextWidth = Max(MaxXTextWidth, Graphic(Text.Size.X,BCD(i).label(3)))
             End If
          Next i
       End If
    
       'Set BarWidth so that largest X text will fit in it
       If BC.AutoXCount Then
          If BC.AllBars Then
             BarWidth = (gW-BC.LM-BC.RM)/(BC.Xmax-BC.Xmin+1)
             If iStep*BarWidth < 1.1* MaxXTextWidth Then iStep = 2
             If iStep*BarWidth < 1.1* MaxXTextWidth Then iStep = 3
             If iStep*BarWidth < 1.1* MaxXTextWidth Then iStep = 4
             If iStep*BarWidth < 1.1* MaxXTextWidth Then iStep = 5
             If iStep*BarWidth < 1.1* MaxXTextWidth Then iStep = 6
             If iStep*BarWidth < 1.1* MaxXTextWidth Then iStep = 7
          Else
             BarWidth = (gW-BC.LM-BC.RM)/(BC.Xmax-BC.Xmin+1)
             If BarWidth < 1.1* MaxXTextWidth Then iStep = 2 : BarWidth = 2 * (gW-BC.LM-BC.RM)/(BC.Xmax-BC.Xmin+1)
             If BarWidth < 1.1* MaxXTextWidth Then iStep = 3 : BarWidth = 3 * (gW-BC.LM-BC.RM)/(BC.Xmax-BC.Xmin+1)
             If BarWidth < 1.1* MaxXTextWidth Then iStep = 4 : BarWidth = 4 * (gW-BC.LM-BC.RM)/(BC.Xmax-BC.Xmin+1)
             If BarWidth < 1.1* MaxXTextWidth Then iStep = 5 : BarWidth = 5 * (gW-BC.LM-BC.RM)/(BC.Xmax-BC.Xmin+1)
             If BarWidth < 1.1* MaxXTextWidth Then iStep = 6 : BarWidth = 6 * (gW-BC.LM-BC.RM)/(BC.Xmax-BC.Xmin+1)
             If BarWidth < 1.1* MaxXTextWidth Then iStep = 7 : BarWidth = 7 * (gW-BC.LM-BC.RM)/(BC.Xmax-BC.Xmin+1)
          End If
       End If
    
       For i = BC.Xmin To BC.Xmax
          If BC.AllBars Or (BC.AllBars = 0 And i Mod iStep = 0) Then Incr BarCount : BCD(i).visible(BC.DataSet) = 1 Else BCD(i).Visible(BC.DataSet) = 0
       Next i
       BarWidth = BC.coverage * (gW-BC.LM-BC.RM) / BarCount
    
       'Set Bar dimensions and Draw the Bars
       iCount = 0 : Reset oldRC, oldRC2, oldRC3
       For i = BC.Xmin To BC.Xmax
          If BCD(i).visible(BC.DataSet) = 0 Then Iterate For
          BCD(i).rc(1).left    = BC.LM + iCount * (gW-BC.LM-BC.RM)/BarCount
          BCD(i).rc(1).bottom  = gH-BC.BM
          BCD(i).rc(1).right   = BCD(i).rc(1).left + BarWidth
          BCD(i).rc(1).top     = BCD(i).rc(1).bottom - (BCD(i).v(1) * (gH-BC.TM-BC.BM) / DivYValue) / BC.DivYCount
          BCD(i).pt(1).x       = (BCD(i).rc(1).Right + BCD(i).rc(1).Left)/2
          BCD(i).pt(1).y       = BCD(i).rc(1).Top
    
          BCD(i).rc(2).left    = BCD(i).rc(1).left
          BCD(i).rc(2).bottom  = BCD(i).rc(1).bottom
          BCD(i).rc(2).right   = BCD(i).rc(1).right
          BCD(i).rc(2).top     = BCD(i).rc(2).bottom - (BCD(i).v(2) * (gH-BC.TM-BC.BM) / DivYValue) / BC.DivYCount
          BCD(i).pt(2).x       = (BCD(i).rc(2).Right + BCD(i).rc(2).Left)/2
          BCD(i).pt(2).y       = BCD(i).rc(2).Top
    
          BCD(i).rc(3).left    = BCD(i).rc(1).left
          BCD(i).rc(3).bottom  = BCD(i).rc(1).bottom
          BCD(i).rc(3).right   = BCD(i).rc(1).right
          BCD(i).rc(3).top     = BCD(i).rc(3).bottom - (BCD(i).v(3) * (gH-BC.TM-BC.BM) / DivYValue) / BC.DivYCount
          BCD(i).pt(3).x       = (BCD(i).rc(3).Right + BCD(i).rc(3).Left)/2
          BCD(i).pt(3).y       = BCD(i).rc(3).Top
    
          'now draw the Vert Grid lines
          If BC.GridOnTop = 0 Then
             If BC.ShowVGrid And i Mod iStep = 0 Then
                If BC.ShowHGrid And BC.DotGrid Then Graphic Style 2
                x1 = (BCD(i).rc(BC.DataSet).left + BCD(i).rc(BC.DataSet).right ) / 2
                Graphic Line (x1, gH-BC.BM+2)-(x1,BC.TM-2), BC.cGrid
                Graphic Style 0
             End If
          End If
          'now Draw the bars
          If BC.GraphType = %Chart_2Stack Then      '2 stacked bars  v1 and v2
             iColor = IIf(i > BC.Pivot,BC.cPostBars(1), BC.cPreBars(1))
             iColor = IIf(BC.UseAltColors,BCD(i).altColor(1),iColor)
             rc = BCD(i).rc(1)
             DrawOneBar BCD(), rc, BC, iColor, BCD(i).selected(1), oldRC, %False
             oldRC = RC
    
             iColor = IIf(i > BC.Pivot,BC.cPostBars(2), BC.cPreBars(2))
             iColor = IIf(BC.UseAltColors,BCD(i).altColor(2),iColor)
             rc = BCD(i).rc(2)
             rc.nTop    += oldRC.Top - oldRC.Bottom
             rc.nBottom += oldRC.Top - oldRC.Bottom
             DrawOneBar BCD(), rc, BC, iColor, BCD(i).selected(2), oldRC2, %True
             oldRC2 = RC
    
          ElseIf BC.GraphType = %Chart_3Stack Then  '3 stacked bars  v1 and v2 and v2
             iColor = IIf(i > BC.Pivot,BC.cPostBars(1), BC.cPreBars(1))
             iColor = IIf(BC.UseAltColors,BCD(i).altColor(1),iColor)
             rc = BCD(i).rc(1)
             DrawOneBar BCD(), rc, BC, iColor, BCD(i).selected(1), oldRC, %False
             oldRC = RC
    
             iColor = IIf(i > BC.Pivot,BC.cPostBars(2), BC.cPreBars(2))
             iColor = IIf(BC.UseAltColors,BCD(i).altColor(2),iColor)
             rc = BCD(i).rc(2)
             rc.nTop    += oldRC.Top - oldRC.Bottom
             rc.nBottom += oldRC.Top - oldRC.Bottom
             DrawOneBar BCD(), rc, BC, iColor, BCD(i).selected(2), oldRC2, %False
             oldRC2 = RC
    
             iColor = IIf(i > BC.Pivot,BC.cPostBars(3), BC.cPreBars(3))
             iColor = IIf(BC.UseAltColors,BCD(i).altColor(3),iColor)
             rc = BCD(i).rc(3)
             rc.nTop    += oldRC.Top - oldRC.Bottom + oldRC2.top - oldRC2.bottom
             rc.nBottom += oldRC.Top - oldRC.Bottom + oldRC2.top - oldRC2.bottom
             DrawOneBar BCD(), rc, BC, iColor, BCD(i).selected(3), oldRC2, %True
             oldRC2 = RC
    
          ElseIf BC.GraphType = %Chart_2Line Then   '2 lines v1 and v2
             iDataSet = BC.DataSet : iSymbol = BC.LineSymbol
             BC.DataSet = 1 : BC.LineSymbol = %Symbol_Circle
             iColor = IIf(i > BC.Pivot,BC.cPostBars(1), BC.cPreBars(1))
             rc = BCD(i).rc(1)  : DrawOneBar BCD(), rc, BC, iColor, BCD(i).selected(1), oldRC  : oldRC  = RC
             BC.DataSet = 2 : BC.LineSymbol = %Symbol_Square
             iColor = IIf(i > BC.Pivot,BC.cPostBars(2), BC.cPreBars(2))
             rc = BCD(i).rc(2) : DrawOneBar BCD(), rc, BC, iColor, BCD(i).selected(2), oldRC2 : oldRC2 = RC
             BC.DataSet = iDataSet : BC.LineSymbol = iSymBol
    
          ElseIf BC.GraphType = %Chart_3Line Then   '3 lines v1 and v2 and v3
             iDataSet = BC.DataSet : iSymbol = BC.LineSymbol
             BC.DataSet = 1 : BC.LineSymbol = %Symbol_Circle
             iColor = IIf(i > BC.Pivot,BC.cPostBars(1), BC.cPreBars(1))
             rc = BCD(i).rc(1)  : DrawOneBar BCD(), rc, BC, iColor, BCD(i).selected(1), oldRC  : oldRC  = RC
             BC.DataSet = 2 : BC.LineSymbol = %Symbol_Square
             iColor = IIf(i > BC.Pivot,BC.cPostBars(2), BC.cPreBars(2))
             rc = BCD(i).rc(2) : DrawOneBar BCD(), rc, BC, iColor, BCD(i).selected(2), oldRC2 : oldRC2 = RC
             BC.DataSet = 3 : BC.LineSymbol = %Symbol_Triangle
             iColor = IIf(i > BC.Pivot,BC.cPostBars(3), BC.cPreBars(3))
             rc = BCD(i).rc(3) : DrawOneBar BCD(), rc, BC, iColor, BCD(i).selected(3), oldRC3 : oldRC3 = RC
             BC.DataSet = iDataSet : iSymbol = BC.LineSymbol
    
          ElseIf BC.GraphType = %Chart_HiLo Then
             iColor = IIf(i > BC.Pivot,BC.cPostBars(BC.DataSet), BC.cPreBars(BC.DataSet))
             iColor = IIf(BC.UseAltColors,BCD(i).altColor(3),iColor)
             rc.nTop  = BCD(i).rc(3).nTop  : rc.nBottom = BCD(i).rc(2).nTop
             rc.nLeft = BCD(i).rc(3).nLeft : rc.nRight  = BCD(i).rc(2).nRight
             DrawOneBar BCD(), rc, BC, iColor, BCD(i).selected(1), oldRC
             oldRC = RC
    
          Else
             iColor = IIf(i > BC.Pivot,BC.cPostBars(BC.DataSet), BC.cPreBars(BC.DataSet))
             iColor = IIf(BC.UseAltColors,BCD(i).altColor(BC.DataSet),iColor)
             rc = BCD(i).rc(BC.DataSet)
             'If BC.SmoothLines = 0 And BC.GraphType <> %Chart_Line Then DrawOneBar BCD(), rc, BC, iColor, BCD(i).selected(1), oldRC
             DrawOneBar BCD(), rc, BC, iColor, BCD(i).selected(1), oldRC
             oldRC = RC
          End If
          iCount += 1
       Next i
    
       'Ensure that smooth lines are behind the symbols
       If BC.SmoothLines And (BC.GraphType=%Chart_Line Or BC.GraphType=%Chart_2Line Or BC.GraphType=%Chart_3Line) Then
          Select Case BC.GraphType
             Case %Chart_Line
                DrawCurves BCD(), BC, BC.BezierDT, BC.BezierTension, BC.DataSet,BC.cPreBars(BC.DataSet)
             Case %Chart_2Line
                DrawCurves BCD(), BC, BC.BezierDT, BC.BezierTension, 1, BC.cPreBars(1)
                DrawCurves BCD(), BC, BC.BezierDT, BC.BezierTension, 2, BC.cPreBars(2)
             Case %Chart_3Line
                DrawCurves BCD(), BC, BC.BezierDT, BC.BezierTension, 1, BC.cPreBars(1)
                DrawCurves BCD(), BC, BC.BezierDT, BC.BezierTension, 2, BC.cPreBars(2)
                DrawCurves BCD(), BC, BC.BezierDT, BC.BezierTension, 3, BC.cPreBars(3)
          End Select
          For i = BC.XMin To BC.XMax
             iDataSet = BC.DataSet : iSymbol = BC.LineSymbol
             Select Case BC.GraphType
                Case %Chart_Line
                   iColor = IIf(i > BC.Pivot,BC.cPostBars(BC.DataSet), BC.cPreBars(BC.DataSet))
                   rc = BCD(i).rc(BC.DataSet) : oldRC = RC
                   DrawOneBar BCD(), rc, BC, iColor, BCD(i).selected(1), oldRC
                Case %Chart_2Line
                   iDataSet = BC.DataSet : iSymbol = BC.LineSymbol
                   BC.DataSet = 1 : BC.LineSymbol = %Symbol_Circle
                   iColor = IIf(i > BC.Pivot,BC.cPostBars(1), BC.cPreBars(1))
                   rc = BCD(i).rc(1)  : DrawOneBar BCD(), rc, BC, iColor, BCD(i).selected(1), oldRC  : oldRC  = RC
                   BC.DataSet = 2 : BC.LineSymbol = %Symbol_Square
                   iColor = IIf(i > BC.Pivot,BC.cPostBars(2), BC.cPreBars(2))
                   rc = BCD(i).rc(2) : DrawOneBar BCD(), rc, BC, iColor, BCD(i).selected(2), oldRC2 : oldRC2 = RC
                   BC.DataSet = iDataSet : BC.LineSymbol = iSymBol
                Case %Chart_3Line
                   BC.DataSet = 1 : BC.LineSymbol = %Symbol_Circle
                   iColor = IIf(i > BC.Pivot,BC.cPostBars(1), BC.cPreBars(1))
                   rc = BCD(i).rc(1)  : DrawOneBar BCD(), rc, BC, iColor, BCD(i).selected(1), oldRC  : oldRC  = RC
                   BC.DataSet = 2 : BC.LineSymbol = %Symbol_Square
                   iColor = IIf(i > BC.Pivot,BC.cPostBars(2), BC.cPreBars(2))
                   rc = BCD(i).rc(2) : DrawOneBar BCD(), rc, BC, iColor, BCD(i).selected(2), oldRC2 : oldRC2 = RC
                   BC.DataSet = 3 : BC.LineSymbol = %Symbol_Triangle
                   iColor = IIf(i > BC.Pivot,BC.cPostBars(3), BC.cPreBars(3))
                   rc = BCD(i).rc(3) : DrawOneBar BCD(), rc, BC, iColor, BCD(i).selected(3), oldRC3 : oldRC3 = RC
                   BC.DataSet = iDataSet : iSymbol = BC.LineSymbol
             End Select
          Next i
       End If
    
       'Draw Horizontal Grid
       If BC.GridOnTop Then
          For i = 1 To BC.DivYCount
             If BC.ShowHGrid And BC.DotGrid Then Graphic Style 2
             Graphic Line (BC.LM-2 ,gH-BC.BM-i*(gH-BC.TM-BC.BM) / BC.DivYCount) -(IIf(BC.ShowHGrid,gW-BC.RM,BC.LM+2),gH-BC.BM-i*(gH-BC.TM-BC.BM) / BC.DivYCount), BC.cGrid
             Graphic Style 0
          Next i
       End If
    
       'Draw Vertical Grid
       If BC.GridOnTop Then
          For i = BC.Xmin To BC.XMax
             If BC.ShowVGrid And i Mod iStep = 0 Then
                If BC.ShowHGrid And BC.DotGrid Then Graphic Style 2
                x1 = (BCD(i).rc(BC.DataSet).left + BCD(i).rc(BC.DataSet).right ) / 2
                Graphic Line (x1, gH-BC.BM+2)-(x1,BC.TM-2), BC.cGrid
             End If
          Next i
       End If
       Graphic Style 0
    
       'Draw X Axis Values (values or alt-text) and Vertical Lines
       If BC.ShowAxisValues Then
          Graphic Color BC.cAxisValues, -2
          Graphic Set Font BC.axisValueFont
          Graphic Text Size LTrim$(Str$(BC.XMax)) To tW, tH
          For i = BC.Xmin To BC.Xmax
             If i Mod iStep Then Iterate For
             If BC.usealtXText Then
                Graphic Set Pos (BCD(i).rc(BC.DataSet).left+(BarWidth-Graphic(Text.Size.X,BCD(i).altXText(BC.DataSet)))/2,BCD(i).rc(BC.DataSet).bottom+10)
                Graphic Print BCD(i).altXText(BC.DataSet)
             Else
                Graphic Set Pos (BCD(i).rc(1).left+(BarWidth-Graphic(Text.Size.X,Trim$(Str$(i))))/2,BCD(i).rc(1).bottom+10)
                Graphic Print Format$(i,"#0")
             End If
          Next i
       End If
    
       'Draw Bar Labels
       If BC.ShowBarLabel Then
          Graphic Color BC.cAxisValues, -2
          Graphic Set Font IIf(BC.VertBarLabels, BC.LabelFontR, BC.LabelFont)
          For i = BC.XMin To BC.XMax
             If i Mod iStep Then Iterate For
             Select Case BC.GraphType
                Case %Chart_2Line
                   temp$ = ThisLabel(BCD(), BC, i, 1, DataTotal(1))   'iPos  ThisDataSet
                   Graphic Set Pos (BCD(i).rc(1).nLeft + (BarWidth-Graphic(Text.Size.X,temp$))/2, BCD(i).rc(1).Top - BC.SymbolSize - 1.5 * Graphic(Text.Size.Y,temp$))
                   Graphic Print temp$
                   temp$ = ThisLabel(BCD(), BC, i, 2, DataTotal(2))   'iPos  ThisDataSet
                   Graphic Set Pos (BCD(i).rc(2).nLeft + (BarWidth-Graphic(Text.Size.X,temp$))/2, BCD(i).rc(2).Top - BC.SymbolSize - 1.5 * Graphic(Text.Size.Y,temp$))
                   Graphic Print temp$
                Case %Chart_3Line
                   temp$ = ThisLabel(BCD(), BC, i, 1, DataTotal(1))
                   Graphic Set Pos (BCD(i).rc(1).nLeft + (BarWidth-Graphic(Text.Size.X,temp$))/2, BCD(i).rc(1).Top - BC.SymbolSize - 1.5 * Graphic(Text.Size.Y,temp$))
                   Graphic Print temp$
                   temp$ = ThisLabel(BCD(), BC, i, 2, DataTotal(2))
                   Graphic Set Pos (BCD(i).rc(1).nLeft + (BarWidth-Graphic(Text.Size.X,temp$))/2, BCD(i).rc(2).Top - BC.SymbolSize - 1.5 * Graphic(Text.Size.Y,temp$))
                   Graphic Print temp$
                   temp$ = ThisLabel(BCD(), BC, i, 3, DataTotal(3))
                   Graphic Set Pos (BCD(i).rc(1).nLeft + (BarWidth-Graphic(Text.Size.X,temp$))/2, BCD(i).rc(3).Top - BC.SymbolSize - 1.5 * Graphic(Text.Size.Y,temp$))
                   Graphic Print temp$
                Case %Chart_2Stack
                   temp$ = ThisLabel(BCD(), BC, i, 2, DataTotal(2))
                   Graphic Set Pos (BCD(i).rc(1).nLeft + (BarWidth-Graphic(Text.Size.X,temp$))/2, BCD(i).rc(1).Top + BCD(i).rc(2).Top - BCD(i).rc(2).Bottom - 1.5 * Graphic(Text.Size.Y,temp$))
                   Graphic Print temp$
                Case %Chart_3Stack
                   temp$ = ThisLabel(BCD(), BC, i, 3, DataTotal(3))
                   Graphic Set Pos (BCD(i).rc(1).nLeft+(BarWidth-Graphic(Text.Size.X,temp$))/2,  BCD(i).rc(1).Top+BCD(i).rc(2).Top-BCD(i).rc(2).Bottom+BCD(i).rc(3).Top-BCD(i).rc(3).Bottom-1.5 * Graphic(Text.Size.Y,temp$))
                   Graphic Print temp$
                Case %Chart_HiLo
                   'top value
                   temp$ = ThisLabel(BCD(), BC, i, 3, DataTotal(3))
                   Graphic Set Pos (BCD(i).rc(1).nLeft+(BarWidth-Graphic(Text.Size.X,temp$))/2, BCD(i).rc(3).Top - 1.5 * Graphic(Text.Size.Y,temp$))
                   Graphic Print temp$
                   temp$ = ThisLabel(BCD(), BC, i, 2, DataTotal(2))
                   Graphic Set Pos (BCD(i).rc(1).nLeft+(BarWidth-Graphic(Text.Size.X,temp$))/2, BCD(i).rc(2).Top + 0.5 * Graphic(Text.Size.Y,temp$))
                   Graphic Print temp$
                Case %Chart_3D
                   temp$ = ThisLabel(BCD(), BC, i, BC.DataSet, DataTotal(BC.DataSet))
                   Graphic Set Pos (BCD(i).rc(1).nLeft + (BarWidth-Graphic(Text.Size.X,temp$))/2, BCD(i).rc(BC.DataSet).Top - BC.ThreeDY - 1.5 * Graphic(Text.Size.Y,temp$))
                   Graphic Print temp$
                Case %Chart_Symbols, %Chart_Line
                   temp$ = ThisLabel(BCD(), BC, i, BC.DataSet, DataTotal(BC.DataSet))
                   Graphic Set Pos (BCD(i).rc(1).nLeft + (BarWidth-Graphic(Text.Size.X,temp$))/2, BCD(i).rc(BC.DataSet).Top - BC.SymbolSize - 1.5 * Graphic(Text.Size.Y,temp$))
                   Graphic Print temp$
                Case %Chart_2D
                   temp$ = ThisLabel(BCD(), BC, i, BC.DataSet, DataTotal(BC.DataSet))
                   Graphic Set Pos (BCD(i).rc(1).nLeft + (BarWidth-Graphic(Text.Size.X,temp$))/2, BCD(i).rc(BC.DataSet).Top - 1.5 * Graphic(Text.Size.Y,temp$))
                   Graphic Print temp$
             End Select
          Next i
       End If
    
       'DrawDataSetTitles
       If BC.ShowDataSetTitles Then
          Graphic Color BC.cAxisValues, -2
          Graphic Set Font BC.axisTitleFont
          Select Case BC.GraphType
             Case %Chart_2D, %Chart_3D, %Chart_Line, %Chart_Symbols
                Graphic Set Pos (gW-BC.RM+20,gH-BC.BM - 3 * Graphic(Text.Size.Y,BC.DataSetTitle(BC.DataSet)))
                Graphic Print BC.DataSetTitle(BC.DataSet)
             Case %Chart_2Line
                Graphic Ellipse (-12+gW-BC.RM+20,2+gH-BC.BM - 3 * Graphic(Text.Size.Y,BC.DataSetTitle(1))) - (-4+gW-BC.RM+20,10+gH-BC.BM - 3 * Graphic(Text.Size.Y,BC.DataSetTitle(1))),%Black, BC.cSymbols(1)
                Graphic Set Pos (gW-BC.RM+20,gH-BC.BM - 3 * Graphic(Text.Size.Y,BC.DataSetTitle(1)))
                Graphic Print BC.DataSetTitle(1)
                Graphic Box (-12+gW-BC.RM+20,2+gH-BC.BM - 2 * Graphic(Text.Size.Y,BC.DataSetTitle(2))) - (-4+gW-BC.RM+20,10+gH-BC.BM - 2 * Graphic(Text.Size.Y,BC.DataSetTitle(2))),,%Black, BC.cSymbols(2)
                Graphic Set Pos (gW-BC.RM+20,gH-BC.BM - 2 * Graphic(Text.Size.Y,BC.DataSetTitle(2)))
                Graphic Print BC.DataSetTitle(2)
             Case %Chart_2Stack
                Graphic Set Pos (gW-BC.RM+20,gH-BC.BM - 3 * Graphic(Text.Size.Y,BC.DataSetTitle(2)))
                Graphic Print BC.DataSetTitle(2)
                Graphic Set Pos (gW-BC.RM+20,gH-BC.BM - 2 * Graphic(Text.Size.Y,BC.DataSetTitle(1)))
                Graphic Print BC.DataSetTitle(1)
             Case %Chart_3Line
                Graphic Ellipse (-12+gW-BC.RM+20,2+gH-BC.BM - 3 * Graphic(Text.Size.Y,BC.DataSetTitle(1))) - (-4+gW-BC.RM+20,10+gH-BC.BM - 3 * Graphic(Text.Size.Y,BC.DataSetTitle(1))),%Black, BC.cSymbols(1)
                Graphic Set Pos (gW-BC.RM+20,gH-BC.BM - 3 * Graphic(Text.Size.Y,BC.DataSetTitle(1)))
                Graphic Print BC.DataSetTitle(1)
                Graphic Box (-12+gW-BC.RM+20,2+gH-BC.BM - 2 * Graphic(Text.Size.Y,BC.DataSetTitle(2))) - (-4+gW-BC.RM+20,10+gH-BC.BM - 2 * Graphic(Text.Size.Y,BC.DataSetTitle(2))),, %Black, BC.cSymbols(2)
                Graphic Set Pos (gW-BC.RM+20,gH-BC.BM - 2 * Graphic(Text.Size.Y,BC.DataSetTitle(2)))
                Graphic Print BC.DataSetTitle(2)
                Graphic Line (-8+gW-BC.RM+20,2+gH-BC.BM - 1 * Graphic(Text.Size.Y,BC.DataSetTitle(3))) - (-12+gW-BC.RM+20,10+gH-BC.BM - 1 * Graphic(Text.Size.Y,BC.DataSetTitle(3))), %Black
                Graphic Line (-8+gW-BC.RM+20,2+gH-BC.BM - 1 * Graphic(Text.Size.Y,BC.DataSetTitle(3))) - (-4+gW-BC.RM+20,10+gH-BC.BM - 1 * Graphic(Text.Size.Y,BC.DataSetTitle(3))), %Black
                Graphic Line (-12+gW-BC.RM+20,10+gH-BC.BM - 1 * Graphic(Text.Size.Y,BC.DataSetTitle(3))) - (-4+gW-BC.RM+20,10+gH-BC.BM - 1 * Graphic(Text.Size.Y,BC.DataSetTitle(3))), %Black
                Graphic Paint (-10+gW-BC.RM+20,8+gH-BC.BM - 1 * Graphic(Text.Size.Y,BC.DataSetTitle(3))), BC.cSymbols(3), %Black
                Graphic Set Pos (gW-BC.RM+20,gH-BC.BM - 1 * Graphic(Text.Size.Y,BC.DataSetTitle(3)))
                Graphic Print BC.DataSetTitle(3)
             Case %Chart_3Stack
                Graphic Set Pos (gW-BC.RM+20,gH-BC.BM - 3 * Graphic(Text.Size.Y,BC.DataSetTitle(3)))
                Graphic Print BC.DataSetTitle(3)
                Graphic Set Pos (gW-BC.RM+20,gH-BC.BM - 2 * Graphic(Text.Size.Y,BC.DataSetTitle(2)))
                Graphic Print BC.DataSetTitle(2)
                Graphic Set Pos (gW-BC.RM+20,gH-BC.BM - 1 * Graphic(Text.Size.Y,BC.DataSetTitle(1)))
                Graphic Print BC.DataSetTitle(1)
             Case %Chart_HiLo
                Graphic Set Pos (gW-BC.RM+20,gH-BC.BM - 3 * Graphic(Text.Size.Y,BC.DataSetTitle(3)))
                Graphic Print BC.DataSetTitle(3)
                Graphic Set Pos (gW-BC.RM+20,gH-BC.BM - 2 * Graphic(Text.Size.Y,BC.DataSetTitle(2)))
                Graphic Print BC.DataSetTitle(2)
          End Select
       End If
       Graphic ReDraw
       BC.LM = tempBCLM : BC.TM = tempBCTM : BC.RM = tempBCRM : BC.BM = tempBCBM
    
       If BC.SpeedTest Then
          QueryPerformanceCounter qStop
          Dialog Set Text BC.hParent, Format$((qStop-qStart)/qFreq,"###.000") & " seconds"
       End If
    
    End Sub
    
    Sub DrawOneBar(BCD() As ChartData, rc As Rect,BC As ChartSettings, ByVal TheColor As Long, iSelected As Long, oldRC As Rect, Optional RoundFlag As Long)
       Local p As ChartPolyPoints, x,y,w,h,RR,GG,BB,iCount,BorderColor,FadedColor,DarkFadedColor, gH,gW As Long
    
       Graphic Get Client To gW,gH
       RR = GetRValue(TheColor)
       GG = GetGValue(TheColor)
       BB = GetBValue(TheColor)
    
       FadedColor     = RGB(Min(255,BC.FadeValue+RR),Min(255,BC.FadeValue+GG),Min(255,BC.FadeValue+BB))
       DarkFadedColor = RGB(Min(255,BC.FadeValue+0.8*RR),Min(255,BC.FadeValue+0.8*GG),Min(255,BC.FadeValue+0.8*BB))
    
       Select Case BC.BarBorder
          Case 1 : BorderColor = FadedColor
          Case 2 : BorderColor = %Black
          Case 3 : BorderColor = %White
       End Select
    
       If iSelected Then Graphic Width 3
       Select Case BC.GraphType
          Case %Chart_2D
             If BC.RoundedBar And BC.RoundValue Then
                DrawTombstone rc, BC, BorderColor, FadedColor
             Else
                Graphic Box (rc.nLeft,rc.nTop)-(rc.nRight,rc.nBottom),,BorderColor, FadedColor
             End If
          Case %Chart_2Stack
             If BC.RoundedBar And BC.RoundValue And (RoundFlag = %True) Then
                DrawTombstone rc, BC, BorderColor, FadedColor
             Else
                Graphic Box (rc.nLeft,rc.nTop)-(rc.nRight,rc.nBottom),,BorderColor, FadedColor
             End If
          Case %Chart_3Stack
             If BC.RoundedBar And BC.RoundValue And (RoundFlag = %True) Then
                DrawTombstone rc, BC, BorderColor, FadedColor
             Else
                Graphic Box (rc.nLeft,rc.nTop)-(rc.nRight,rc.nBottom),,BorderColor, FadedColor
             End If
          Case %Chart_HiLo
             Select Case BC.HiLoSymbol
                Case %HiLo_Bar
                   Graphic Box (rc.nLeft,rc.nTop)-(rc.nRight,rc.nBottom),IIf(BC.RoundedBar, BC.RoundValue, 0),BorderColor, FadedColor
                Case %HiLo_Beam
                   Graphic Width BC.Linethickness
                   x = rc.nLeft+(rc.nRight-rc.nLeft)/2
                   Graphic Line (x-BC.LineThickness-2,rc.nTop)   - (x+BC.LineThickness+2,rc.nTop),BorderColor
                   Graphic Line (x-BC.LineThickness-2,rc.nBottom)- (x+BC.LineThickness+2,rc.nBottom), BorderColor
                   Graphic Line (x,rc.nTop)-(x,rc.nBottom),BorderColor
                   Graphic Width 1
                Case %HiLo_Dot
                   Graphic Width BC.Linethickness
                   x = rc.nLeft+(rc.nRight-rc.nLeft)/2
                   Graphic Line (x-BC.LineThickness-2,rc.nTop)   - (x+BC.LineThickness+2,rc.nTop),BorderColor
                   Graphic Line (x-BC.LineThickness-2,rc.nBottom)- (x+BC.LineThickness+2,rc.nBottom), BorderColor
                   Graphic Line (x,rc.nTop)-(x,rc.nBottom),BorderColor
                   Graphic Width 1
                   Graphic Ellipse (x-BC.SymbolSize, rc.nTop + (rc.nBottom-rc.nTop)/2-BC.SymbolSize) - (x+BC.SymbolSize,rc.nTop + (rc.nBottom-rc.nTop)/2+BC.SymbolSize),BorderColor,BC.cSymbols(BC.DataSet)
             End Select
    
          Case %Chart_3D
             Graphic Box (rc.nLeft,rc.nTop)-(rc.nRight,rc.nBottom),,BorderColor, FadedColor
             p.count = 6
             p.x1 = rc.nLeft             : p.y1 = rc.nTop
             p.x2 = rc.nLeft+BC.ThreeDX  : p.y2 = rc.nTop-BC.ThreeDY
             p.x3 = rc.nRight+BC.ThreeDX : p.y3 = rc.nTop-BC.ThreeDY
             p.x4 = rc.nRight+BC.ThreeDX : p.y4 = rc.nBottom-BC.ThreeDY
             p.x5 = rc.nRight            : p.y5 = rc.nBottom
             p.x6 = rc.nRight            : p.y6 = rc.nTop
             Graphic Polygon p, BorderColor, DarkFadedColor
             Graphic Line (rc.nRight,rc.nTop)-(rc.nRight+BC.ThreeDX,rc.nTop-BC.ThreeDY),BorderColor
    
          Case %Chart_Line, %Chart_Symbols, %Chart_2Line, %Chart_3Line
             If BC.GraphType <> %Chart_Symbols Then Graphic Style BC.LineStyle
             Graphic Width BC.LineThickNess
             If BC.SmoothLines Then
                'Bezier curves
                'DrawCurves BCD(), BC, 0.01, 0.5
             ElseIf BC.UseAntiAliasing Then
                If BC.ColorUnder Then
                   If (BC.GraphType=%Chart_Line Or BC.GraphType=%Chart_2Line Or BC.GraphType = %Chart_3Line) And oldrc.nTop Then Graphic Box ((oldrc.nLeft + oldrc.nRight)/2,oldrc.nTop) - ((rc.nLeft + rc.nRight)/2,gH-BC.BM-1),, TheColor, TheColor
                Else
                   If (BC.GraphType=%Chart_Line Or BC.GraphType=%Chart_2Line Or BC.GraphType = %Chart_3Line) And oldrc.nTop Then GraphicLineAA BC.hGraphicDC, (oldrc.nLeft + oldrc.nRight)/2,oldrc.nTop, (rc.nLeft + rc.nRight)/2,rc.nTop , TheColor
                End If
             Else
                If BC.ColorUnder Then
                   If (BC.GraphType=%Chart_Line Or BC.GraphType=%Chart_2Line Or BC.GraphType = %Chart_3Line) And oldrc.nTop Then Graphic Box ((oldrc.nLeft + oldrc.nRight)/2,oldrc.nTop)-((rc.nLeft + rc.nRight)/2,gH-BC.BM-1),, TheColor, TheColor
                Else
                   If (BC.GraphType=%Chart_Line Or BC.GraphType=%Chart_2Line Or BC.GraphType = %Chart_3Line) And oldrc.nTop Then Graphic Line ((oldrc.nLeft + oldrc.nRight)/2,oldrc.nTop)-((rc.nLeft + rc.nRight)/2,rc.nTop), TheColor
                End If
             End If
             Graphic Style 0
             Graphic Width BC.SymbolSize
             x = (rc.nLeft + rc.nRight)/2 : y = rc.nTop
             Select Case BC.linesymbol
                Case %Symbol_Point
                   Graphic Set Pixel (x,y), TheColor
                Case %Symbol_Circle 'circle (dot)
                   Graphic Ellipse (x-BC.SymbolSize-2,y-BC.SymbolSize-2)-(x+BC.SymbolSize+2,y+BC.SymbolSize+2),BorderColor,BC.cSymbols(BC.DataSet)
                   If oldRC.nTop Then
                      x = (oldrc.nLeft + oldrc.nRight)/2 : y = oldrc.nTop
                      Graphic Ellipse (x-BC.SymbolSize-2,y-BC.SymbolSize-2)-(x+BC.SymbolSize+2,y+BC.SymbolSize+2),BorderColor,BC.cSymbols(BC.DataSet)
                   End If
                Case %Symbol_Triangle
                   p.count = 6
                   p.x1 = x                    : p.y1 = rc.nTop-BC.SymbolSize-4
                   p.x2 = x+BC.SymbolSize+4    : p.y2 = rc.nTop+BC.SymbolSize+4
                   p.x3 = x-BC.SymbolSize-4    : p.y3 = rc.nTop+BC.SymbolSize+4
                   p.x4 = p.x3 : p.x5 = p.x3 : p.x6 = p.x3 : p.y4 = p.y3 : p.y5 = p.y3 : p.y6 = p.y3
                   Graphic Polygon p, BorderColor, BC.cSymbols(BC.DataSet)
                   If oldRc.nTop Then
                      x = (oldrc.nLeft + oldrc.nRight)/2 : y = oldrc.nTop
                      p.x1 = x                   : p.y1 = oldrc.nTop-BC.SymbolSize-4
                      p.x2 = x+BC.SymbolSize+4   : p.y2 = oldrc.nTop+BC.SymbolSize+4
                      p.x3 = x-BC.SymbolSize-4   : p.y3 = oldrc.nTop+BC.SymbolSize+4
                      p.x4 = p.x3 : p.x5 = p.x3 : p.x6 = p.x3 : p.y4 = p.y3 : p.y5 = p.y3 : p.y6 = p.y3
                      Graphic Polygon p, BorderColor, BC.cSymbols(BC.DataSet)
                   End If
                Case %Symbol_Square
                   Graphic Box (x-BC.SymbolSize-2,y-BC.SymbolSize-2)-(x+BC.SymbolSize+2,y+BC.SymbolSize+2),,BorderColor, BC.cSymbols(BC.DataSet)
                   If oldrc.nTop Then
                      x = (oldrc.nLeft + oldrc.nRight)/2 : y = oldrc.nTop
                      Graphic Box (x-BC.SymbolSize-2,y-BC.SymbolSize-2)-(x+BC.SymbolSize+2,y+BC.SymbolSize+2),,BorderColor, BC.cSymbols(BC.DataSet)
                   End If
             End Select
             Graphic Width 1
       End Select
       If iSelected Then Graphic Width 1
    
       If BC.GraphType = %Chart_2D Or BC.GraphType = %Chart_3D Or BC.GraphType = %Chart_2Stack Or BC.GraphType = %Chart_3D Or BC.GraphType = %Chart_HiLo Then
          Select Case BC.BarGradientType
             Case %Gradient_DarkBottomToTop  'darkcolor bottom to color on top
                h = rc.nBottom - rc.nTop - 2
                For y = rc.nBottom-1 To rc.nTop+1 Step -1
                   Graphic Line (rc.nLeft+1,y)-(rc.nRight-1,y), RGB(Min(255,BC.FadeValue+RR*iCount/h), Min(255,BC.FadeValue+GG*iCount/h), Min(255,BC.FadeValue+ BB*iCount/h))
                   Incr iCount
                Next y
             Case %Gradient_LightCenterToDarkSide  'lightcolor center, fade to color on each side
                w = (rc.nRight - rc.nLeft - 2)/2
                For x = rc.nLeft+1 To (rc.nLeft+rc.nRight+2)/2
                   Graphic Line (x,rc.nTop+1)-(x,rc.nBottom-1), RGB(Min(255,BC.FadeValue+RR+(240-RR)*iCount/w),Min(255,BC.FadeValue+GG+(240-GG)*iCount/w),Min(255,BC.FadeValue+BB+(240-BB)*iCount/w))
                   Incr iCount
                Next x
                iCount = 0
                For x = rc.nRight-1 To (rc.nLeft+rc.nRight+2)/2 Step -1
                   Graphic Line (x,rc.nTop+1)-(x,rc.nBottom-1), RGB(Min(255,BC.FadeValue+RR+(240-RR)*iCount/w),Min(255,BC.FadeValue+GG+(240-GG)*iCount/w),Min(255,BC.FadeValue+BB+(240-BB)*iCount/w))
                   Incr iCount
                Next x
                iCount = 0
             Case %Gradient_ColorCenterToBlackSide
                w = (rc.nRight - rc.nLeft - 2)/2
                For x = rc.nLeft+1 To (rc.nLeft+rc.nRight+2)/2
                   Graphic Line (x,rc.nTop+1)-(x,rc.nBottom-1), RGB(Min(255,BC.FadeValue+RR*iCount/w),Min(255,BC.FadeValue+GG*iCount/w),Min(255,BC.FadeValue+BB*iCount/w))
                   Incr iCount
                Next x
                iCount = 0
                For x = rc.nRight-1 To (rc.nLeft+rc.nRight+2)/2 Step -1
                   Graphic Line (x,rc.nTop+1)-(x,rc.nBottom-1), RGB(Min(255,BC.FadeValue+RR*iCount/w),Min(255,BC.FadeValue+GG*iCount/w),Min(255,BC.FadeValue+BB*iCount/w))
                   Incr iCount
                Next x
                iCount = 0
          End Select
       End If
    
       If BC.BarGradientType = %Gradient_Background Then 'color bottom to white on top (used for gradient background
          h = rc.nBottom - 2
          For y = rc.nBottom To rc.nTop Step -1
             If BC.FadeBG Then
                Graphic Line (rc.nLeft,y)-(rc.nRight,y), RGB(Min(255,BC.FadeValue+RR+(240-RR)*iCount/h),Min(255,BC.FadeValue+GG+(240-GG)*iCount/h),Min(255,BC.FadeValue+BB+(240-BB)*iCount/h))
             Else
                Graphic Line (rc.nLeft,y)-(rc.nRight,y), RGB(RR+(240-RR)*iCount/h,GG+(240-GG)*iCount/h,BB+(240-BB)*iCount/h)
             End If
             Incr iCount
          Next y
       End If
    
       oldrc = rc
    
    
    End Sub
    
    Sub DrawTombStone(ByVal rc As Rect, BC As ChartSettings, BorderColor As Long, FadedColor As Long)
       Local gW,gH,w,r,h As Long
       If IsRectEmpty(rc) Then Exit Sub
       Graphic Get Client To gW,gH
       w = rc.nRight - rc.nLeft + 1
       h = rc.nBottom - rc.nTop + 1
       R =  w * BC.RoundValue / 200
       If R > h Then R = h
       Graphic Pie (rc.nLeft,rc.nTop)-(rc.nRight+1,rc.nTop+2*(R-1)+1),0.001!,3.14059,BorderColor, FadedColor
       If (rc.nTop + R < rc.nBottom) Then
          Graphic Box (rc.nLeft,rc.nTop+R)-(rc.nRight,rc.nBottom),,BorderColor, Fadedcolor
          Graphic Line (rc.nLeft+1,rc.nTop+R)-(rc.nRight-1,rc.nTop+R), FadedColor
          Graphic Line (rc.nLeft+1,rc.nTop+R-1)-(rc.nRight-1,rc.nTop+R-1), FadedColor
       End If
    End Sub
    
    Sub GraphicLineAA(hdc As Long, x1 As Long, y1 As Long, x2 As Long, y2 As Long, AColor As Long)
        Dim deltax As Integer, deltay As Integer, loopc As Integer
        Dim start As Integer, finish As Integer
        Dim dx As Single, dy As Single, dydx As Single
        Dim LR As Byte, LG As Byte, LB As Byte
    
        deltax = Abs(x2 - x1) ' Calculate deltax and deltay for initialisation
        deltay = Abs(y2 - y1)
        If (deltax <> 0) And (deltay <> 0) Then  ' it is not a horizontal or a vertical line
            LR = (AColor And &HFF&)
            LG = (AColor And &HFF00&) / &H100&
            LB = (AColor And &HFF0000) / &H10000
            If deltax > deltay Then  ' horizontal or vertical
                If y2 > y1 Then ' determine rise and run
                    dydx = -(deltay / deltax)
                Else
                    dydx = deltay / deltax
                End If
                If x2 < x1 Then
                    start = x2 ' right to left
                    finish = x1
                    dy = y2
                Else
                    start = x1 ' left to right
                    finish = x2
                    dy = y1
                    dydx = -dydx ' inverse slope
                End If
                For loopc = start To finish
                    AlphaBlendPixel hdc, loopc, CInt(dy - 0.5), LR, LG, LB, _
                    1 - FracPart(dy)
                    AlphaBlendPixel hdc, loopc, CInt(dy - 0.5) + 1, LR, LG, _
                    LB, FracPart(dy)
                    dy = dy + dydx ' next point
                Next loopc
            Else
                If x2 > x1 Then ' determine rise and run
                    dydx = -(deltax / deltay)
                Else
                    dydx = deltax / deltay
                End If
                If y2 < y1 Then
                    start = y2 ' right to left
                    finish = y1
                    dx = x2
                Else
                    start = y1 ' left to right
                    finish = y2
                    dx = x1
                    dydx = -dydx ' inverse slope
                End If
                For loopc = start To finish
                    AlphaBlendPixel hdc, CInt(dx - 0.5), loopc, LR, LG, LB, _
                    1 - FracPart(dx)
                    AlphaBlendPixel hdc, CInt(dx - 0.5) + 1, loopc, LR, LG, _
                    LB, FracPart(dx)
                    dx = dx + dydx ' next point
                Next loopc
            End If
        Else
           Graphic Set Pos (x1,y1)
           Graphic Line (x1,y1)-(x2,y2), AColor
        End If
    End Sub
    
    ' blend a pixel with the current colour and a specified colour
    Sub AlphaBlendPixel(ByVal hdc As Long, ByVal x As Integer, _
                        ByVal y As Integer, ByVal R As Byte, ByVal g As Byte, ByVal b As Byte, _
                        ByVal ARatio As Double)
        Dim LMinusRatio As Double
        Dim nr As Byte, ng As Byte, nb As Byte
        Dim dstc As Long, dr As Byte, dg As Byte, Ddb As Byte
    
        LMinusRatio = 1 - ARatio
        dstc = GetPixel(hdc, x, y)
        dr = (dstc And &HFF&)
        dg = (dstc And &HFF00&) / &H100&
        Ddb = (dstc And &HFF0000) / &H10000
    
        nb = Round(b * ARatio + Ddb * LMinusRatio, 0)
        ng = Round(g * ARatio + dg * LMinusRatio, 0)
        nr = Round(R * ARatio + dr * LMinusRatio, 0)
    
        Graphic Set Pixel (x, y), RGB(nr, ng, nb)
    End Sub
    
    ' Returns the fractional part of a double
    Function FracPart(ByVal a As Double) As Double
        Dim b As Double
        b = CLng(a - 0.5)
        FracPart = a - b
    End Function
    
    Sub DrawPieChart(BCD() As ChartData, BC As ChartSettings, PieChartPos As Long, PieChartCount As Long, EraseChart As Long, ThisDataSet As Long, PieRedraw As Long)
       Local j,x,y,x0,y0,distance As Long, temp$, RC As Rect, BMP$
       Local r,w,h,tW,tH,iCount,PieTotal,rHorz,rVert As Long, tn,theta, ArcRotate, ArcStart, ArcEnd, ThisArc,ca As Single
    
       Local i As Long
       Local gW,gH,bgW,bgH As Long
       Local qFreq, qStart, qStop As Quad
    
       If BC.SpeedTest Then QueryPerformanceFrequency qFreq : QueryPerformanceCounter qStart
    
       'Clear the Graphic control
       Graphic Attach BC.hGraphic, 0, ReDraw
       If EraseChart Then Graphic Clear BC.cBG
       Graphic Get Client To gW,gH
       Graphic Width 1
       Graphic Set Overlap
    
       'Get various reusable values
       For i = BC.XMin To BC.XMax
          BCD(i).ArcStart(ThisDataSet) = 0
          BCD(i).ArcEnd(ThisDataSet)   = 0
          PieTotal += BCD(i).v(ThisDataSet)
          BCD(i).RR = GetRValue(BCD(i).altColor(ThisDataSet))
          BCD(i).GG = GetGValue(BCD(i).altColor(ThisDataSet))
          BCD(i).BB = GetBValue(BCD(i).altColor(ThisDataSet))
          BCD(i).FadedColor     = RGB(Min(255,BC.FadeValue+BCD(i).RR),Min(255,BC.FadeValue+BCD(i).GG),Min(255,BC.FadeValue+BCD(i).BB))
          BCD(i).DarkFadedColor = RGB(Min(255,BC.FadeValue+0.8*BCD(i).RR),Min(255,BC.FadeValue+0.8*BCD(i).GG),Min(255,BC.FadeValue+0.8*BCD(i).BB))
          BCD(i).BorderColor    = Choose(BC.BarBorder, BCD(i).FadedColor, %Black, %White)
       Next i
    
       'Set pie enclosing rectangle
       w = (gW-BC.LM-BC.RM)/PieChartCount        'width of area available for pie
       h = (gH-BC.TM-BC.BM)                      'height of area available for pie
       x = BC.LM + (PieChartPos - 1) * w  + w/2  'center of available area   PieChartPos is 1,2,3
       y = BC.TM + h/2                           'center of available area
       If BC.PieCircle Then w = Min(w,h) * 0.9 : h = w   'use smallest w or h as circle diameter
       RC.nLeft   = x - w/2 * BC.PieRadius / 100  'Resize pie according to the PieRadis (% of available space
       RC.nRight  = x + w/2 * BC.PieRadius / 100  'Resize pie according to the PieRadis (% of available space
       RC.nTop    = y - h/2 * BC.PieRadius / 100  'Resize pie according to the PieRadis (% of available space
       RC.nBottom = y + h/2 * BC.PieRadius / 100  'Resize pie according to the PieRadis (% of available space
       For i = BC.XMin To BC.XMax : BCD(i).rc(ThisDataSet) = RC : Next i
    
       'Set pie radii  ra/rb
       rHorz = (rc.nRight  - rc.nLeft)/2   'ra = x-radius
       rVert = (rc.nBottom - rc.nTop)/2    'rb = y-radius
       x0 = (rc.nRight  + rc.nLeft)/2   'center of radius x-value
       y0 = (rc.nTop    + rc.nBottom)/2 'center of radius y-value
    
       'Draw Background - gradient or image
       If BC.ShowBGImage And (BC.GraphType = %Chart_Pie Or (BC.GraphType = %Chart_2Pie And ThisDataSet=1) Or (BC.GraphType = %Chart_3Pie And ThisDataSet=1)) Then
           If BC.BGImageFit Then
             Graphic Attach BC.hBGImage, 0
             Graphic Get Canvas To bgW, bgH
             Graphic Attach BC.hGraphic, 0, ReDraw
             Graphic Stretch BC.hBGImage, 0, (0,0)-(bgW-1,bgH-1) To (0,0)-(gW-1,gH-1), %Mix_CopySrc, %HalfTone
          Else
             Graphic Copy BC.hBGImage, 0
          End If
       ElseIf BC.GradientBG Then
          If EraseChart Then
             h = RC.nBottom - 2
             For y = gH-1 To 0 Step -1
                If BC.FadeBG Then
                   Graphic Line (0,y)-(gW-1,y), _
                   RGB(Min(255,BC.FadeValue+GetRValue(BC.cBG)+(240-GetRValue(BC.cBG))*iCount/h),Min(255,BC.FadeValue+GetGValue(BC.cBG)+(240-GetGValue(BC.cBG))*iCount/h),Min(255,BC.FadeValue+GetBValue(BC.cBG)+(240-GetBValue(BC.cBG))*iCount/h))
                Else
                   Graphic Line (0,y)-(gW-1,y), RGB(GetRValue(BC.cBG)+(240-GetRValue(BC.cBG))*iCount/h,GetGValue(BC.cBG)+(240-GetGValue(BC.cBG))*iCount/h,GetBValue(BC.cBG)+(240-GetBValue(BC.cBG))*iCount/h)
                End If
                Incr iCount
             Next y
          End If
       End If
    
       'Draw Instructions
       If BC.Instructions Then
          Graphic Set Font BC.InstructFont
          Graphic Width 1
          Graphic Style 2
          Graphic Box (0,0)-(20,20),,%Red, -2         'top left
          Graphic Box (gW-1,0)-(gW-21,20),,%Red, -2     'top right
          Graphic Box (0,gH-1)-(20,gH-21),,%Red, -2     'bottom left
          Graphic Box (gW-1,gH-1)-(gW-21,gH-21),,%Red, -2 'bottom right
          Graphic Style 0
          Graphic Width BC.LineThickness
    
          Graphic Set Font BC.axisValueFont
          Graphic Color BC.cTitle, -2  'BC.cBG
          'upper left
          Graphic Set Pos (25,10) : Graphic Print "Clk - Erase last symbol, DblClk - Erase all"
          'upper right
          temp$ = "DblClk - Remove Selections"
          Graphic Set Pos (gW - 25 - Graphic(Text.Size.X,temp$),10) : Graphic Print temp$
          'lower left
          Graphic Set Pos (25, gH - 2*Graphic(Text.Size.X,"C")) : Graphic Print "DblClk - Settings Dialog Repositioned"
          'lower right
          Graphic Set Pos (gW - 25 - Graphic(Text.Size.X,"DblClk - Settings"), gH - 2*Graphic(Text.Size.X,"C")) : Graphic Print "DblClk - Settings"
          'midleft
          Graphic Set Pos (10, gH/2 - 30)                              : Graphic Print "DblClk - Stamp"
          Graphic Set Pos (10, gH/2 - 30 + Graphic(Text.Size.Y,"C"))   : Graphic Print "RClick Bar - Select"
          Graphic Set Pos (10, gH/2 - 30 + 2*Graphic(Text.Size.Y,"C")) : Graphic Print "RClick - Settings"
       End If
    
       'Draw Top Title
       Graphic Color BC.cTitle, -2  'BC.cBG
       If BC.ShowMainTitle Then
          Graphic Set Font BC.TitleFont
          BC.TM = Graphic(Text.Size.Y,BC.Title) * 2
          Select Case BC.MainTitleLoc
             Case %MainTitle_Left   : Graphic Set Pos (BC.LM,BC.TM-1.5*Graphic(Text.Size.Y,BC.Title))
             Case %MainTitle_Center : Graphic Set Pos (BC.LM + (gW-BC.LM-BC.RM-Graphic(Text.Size.X,BC.Title))/2, BC.TM - 1.5*Graphic(Text.Size.Y,BC.Title))
             Case %MainTitle_Right  : Graphic Set Pos (gW - BC.RM - Graphic(Text.Size.X,BC.Title), BC.TM - 1.5*Graphic(Text.Size.Y,BC.Title))
          End Select
          Graphic Print BC.Title
       End If
    
       'Show Margins
       If BC.ShowMargins Then
          Graphic Color %Red
          Graphic Style 2
          Graphic Line (BC.LM,0)-(BC.LM,gH)
          Graphic Line (0,BC.TM)-(gW,BC.TM)
          Graphic Line (gW-BC.RM,0)-(gW-BC.RM,gH)
          Graphic Line (0,gH-BC.BM)-(gW,gH-BC.BM)
          Graphic Box (RC.nLeft,RC.nTop)-(RC.nRight,RC.nBottom),,%Red
          Graphic Style 0
       End If
    
       'Draw Pie Sections
       ArcRotate = BC.PieRotate * 0.017453   'BC.PieRotate is in degrees.  ArcXXX values are in radians
       Graphic Width BC.LineThickness
       If BC.Pie3D And (BC.PieCircle = 0) And rVert/rHorz < 0.9 Then
          'draw the 3D bottom parts of the pie - also calculates the .arcStart and .artEnd values
          BC.Pie3DThickness = 0.1 * (RC.nBottom - RC.nTop)
          For j = BC.Pie3DThickness-1 To 1 Step -1
             'Pies in 3D stack
             ArcStart = 0 : ArcEnd = 0
             For i = BC.XMin To BC.XMax
                'If BCD(i).Selected(ThisDataSet) Then Graphic Width BC.LineThickness + BC.PieHighLightSelected * 3 Else Graphic Width BC.LineThickness
                ArcEnd += BCD(i).v(ThisDataSet)/PieTotal * 6.28318
                Graphic Pie (RC.nLeft,RC.nTop+j)-(RC.nRight,RC.nBottom+j), ArcRotate + ArcStart, ArcRotate + ArcEnd, BCD(i).FadedColor, BCD(i).FadedColor
                BCD(i).ArcStart(ThisDataSet) = ArcStart + ArcRotate
                BCD(i).ArcEnd(ThisDataSet) = ArcEnd + ArcRotate
                ArcStart = ArcEnd
             Next i
          Next j
          'draw the vertical lines in the 3D edge
          Graphic Width BC.LineThickness
          For i = BC.XMin To BC.XMax
             'If BCD(i).Selected(ThisDataSet) Then Graphic Width BC.LineThickness + BC.PieHighLightSelected * 3
             tn = Tan(-BCD(i).ArcStart(ThisDataSet))
             x = rVert * rHorz      / ((rVert*rVert + rHorz*rHorz*tn*tn)^0.5)
             y = rVert * rHorz * tn / ((rVert*rVert + rHorz*rHorz*tn*tn)^0.5)
             If BCD(i).ArcStart(ThisDataSet) Mod 6.28318 > 3.14159/2 And BCD(i).ArcStart(ThisDataSet) Mod 6.28318 < 1.5*3.14159 Then x = -1 * x : y = -1 * y
             x = x0 + x
             y = y0 + y
             Graphic Line (x,y)-(x,y+BC.Pie3DThickness-1), BCD(i).BorderColor
          Next i
          'Graphic Width BC.LineThickness
          Graphic Line (x0+rHorz,y0)-(x0+rHorz,y0+BC.Pie3DThickness), BCD(1).BorderColor
          Graphic Line (x0-rHorz,y0)-(x0-rHorz,y0+BC.Pie3DThickness), BCD(1).BorderColor
          Graphic Arc  (RC.nLeft,RC.nTop+BC.Pie3DThickness)-(RC.nRight,RC.nBottom+BC.Pie3DThickness), 3.14159, 6.28318, BCD(1).BorderColor
    
          'draw the 3D top of the pie
          For i = BC.XMin To BC.XMax
             If BCD(i).Selected(ThisDataSet) Then Graphic Width BC.LineThickness + BC.PieHighLightSelected * 3  Else Graphic Width BC.LineThickness
             Graphic Pie (RC.nLeft,RC.nTop)-(RC.nRight,RC.nBottom), BCD(i).ArcStart(ThisDataSet), BCD(i).ArcEnd(ThisDataSet), BCD(i).BorderColor, BCD(i).FadedColor
          Next i
    
       Else
          For i = BC.XMin To BC.XMax
             If BCD(i).Selected(ThisDataSet) Then Graphic Width BC.LineThickness + BC.PieHighLightSelected * 3
             ArcEnd += BCD(i).v(ThisDataSet)/PieTotal * 6.28318
             BCD(i).ArcStart(ThisDataSet) = ArcStart + ArcRotate
             BCD(i).ArcEnd(ThisDataSet) = ArcEnd + ArcRotate
             If BC.PieExplode Then
                ca = (BCD(i).ArcStart(ThisDataSet)+BCD(i).ArcEnd(ThisDataSet))/2 + ArcRotate
                x = BC.PieExplodeDistance * Sin(ca+1.57075)
                y = BC.PieExplodeDistance * Cos(ca+1.57075)
                Graphic Pie (RC.nLeft+x,RC.nTop+y)-(RC.nRight+x,RC.nBottom+y), ArcRotate + BCD(i).ArcStart(ThisDataSet), ArcRotate + BCD(i).ArcEnd(ThisDataSet), BCD(i).BorderColor, BCD(i).FadedColor
             ElseIf BCD(i).Selected(ThisDataSet) And BC.PieEject Then
                Graphic Width BC.LineThickness + BC.PieHighlightSelected * 3
                ca = (BCD(i).ArcStart(ThisDataSet)+BCD(i).ArcEnd(ThisDataSet))/2 '+ ArcRotate
                x = BC.PieExplodeDistance * Sin(ca+1.57075)
                y = BC.PieExplodeDistance * Cos(ca+1.57075)
                Graphic Pie (RC.nLeft+x,RC.nTop+y)-(RC.nRight+x,RC.nBottom+y), BCD(i).ArcStart(ThisDataSet), BCD(i).ArcEnd(ThisDataSet), BCD(i).BorderColor, BCD(i).FadedColor
             ElseIf BCD(i).Selected(ThisDataSet) = 0 And BC.PieHideUnselected Then
                'do not show
             Else
                Graphic Pie (RC.nLeft,RC.nTop)-(RC.nRight,RC.nBottom), BCD(i).ArcStart(ThisDataSet), BCD(i).ArcEnd(ThisDataSet), BCD(i).BorderColor, BCD(i).FadedColor
             End If
             ArcStart = ArcEnd
             Graphic Width BC.LineThickness
          Next i
       End If
    
    'temp$ = ""
    'For i = BC.XMin to BC.XMax
    '   temp$ += str$(BCD(i).v(ThisDataSet)/PieTotal * 6.28318) + $Tab + Str$(BCD(i).ArcStart(ThisDataSet)) + $TAB + Str$(BCD(i).ArcEnd(ThisDataSet)) + $crlf
    'next i
    '? Temp$
    
       'Draw Gradient on top of PIE
       If BC.PieGradient Then
          Graphic Get Bits To bmp$
          ReDim MyColors(0 To gW-1, 0 To gH-1) As Long At StrPtr(bmp$) + 8
          For i = RC.nLeft To RC.nRight
             For j = RC.nTop To RC.nBottom
                theta = Atn((j-y0)/(i-x0))
                r = (rHorz*rVert) / (rHorz*rHorz*Sin(theta)*Sin(theta) + rVert*rVert*Cos(theta)*Cos(theta))^0.5
                distance = ((i-x0)*(i-x0) + (j-y0)*(j-y0)) ^ 0.5
                If distance > r Then Iterate For
                MyColors(i,j) = RGB( Min(255,(r-distance)/r*BC.PieGradientValue+GetRValue(MyColors(i,j))), _
                                     Min(255,(r-distance)/r*BC.PieGradientValue+GetGValue(MyColors(i,j))), _
                                     Min(255,(r-distance)/r*BC.PieGradientValue+GetBValue(MyColors(i,j))) )
             Next j
          Next i
          Graphic Set Bits bmp$
       End If
    
       'Draw Pie %'s
       If BC.PiePerCent Then
          Graphic Color BC.cAxisValues
          Graphic Set Font BC.AxisValueFont
          For i = BC.Xmin To BC.Xmax
             If BC.PieHideUnselected And BCD(i).Selected(ThisDataSet)=0 Then Iterate For
             temp$ = Format$(BCD(i).v(ThisDataSet) / PieTotal * 100, "#0.0") + "%"
             Graphic Text Size temp$ To tw, th
             theta = (BCD(i).arcEnd(ThisDataSet) + BCD(i).arcStart(ThisDataSet))/2
             r = (rHorz*rVert) / (rHorz*rHorz*Sin(theta)*Sin(theta) + rVert*rVert*Cos(theta)*Cos(theta))^0.5
             x = x0 - tw/2 +  0.65 * r * Cos((BCD(i).arcEnd(ThisDataSet) + BCD(i).arcStart(ThisDataSet))/2)
             y = y0 - th/2 -  0.65 * r * Sin((BCD(i).arcEnd(ThisDataSet) + BCD(i).arcStart(ThisDataSet))/2)
             Graphic Set Pos(x, y)
             Graphic Print temp$
          Next i
       End If
    
       'Draw Pie Labels
       temp$ = ""
       If BC.ShowBarLabel Then
          Graphic Color BC.cTitle
          Graphic Set Font BC.LabelFont
          For i = BC.Xmin To BC.Xmax
             If BC.PieHideUnselected And BCD(i).Selected(ThisDataSet)=0 Then Iterate For
             Select Case BC.LabelType
                Case %Label_Value    : temp$ = Format$(BCD(i).v(ThisDataSet), "###,###,##0")
                Case %Label_Label    : temp$ = BCD(i).label(ThisDataSet)
                Case %Label_PerCent  : temp$ = Format$(BCD(i).v(ThisDataSet) / PieTotal * 100, "#0.0") + "%"
                Case %Label_AltXText : temp$ = BCD(i).altXText(ThisDataSet)
             End Select
             Graphic Text Size temp$ To tw, th
             theta = (BCD(i).arcEnd(ThisDataSet) + BCD(i).arcStart(ThisDataSet))/2
    
             If BC.PieExplode Then
                j = BC.PieExplodeDistance
             ElseIf BC.PieEject And BCD(i).Selected(ThisDataSet) Then
                j = BC.PieExplodeDistance
             Else
                j = 0
             End If
             If BC.PieCircle=0 And BC.Pie3D And (BCD(i).ArcStart(ThisDataSet) > 3.14159) Then j += BC.Pie3DThickness
    
             r = (rHorz*rVert) / (rHorz*rHorz*Sin(theta)*Sin(theta) + rVert*rVert*Cos(theta)*Cos(theta))^0.5 + j
             Select Case theta
                Case < 3.14159/2
                   x = x0 +  1.1 * r * Cos(Theta)
                   y = y0 - th/2 -  1.1 * r * Sin(Theta)
                Case < 3.14159
                   x = x0 - tw +  1.1 * r * Cos(Theta)
                   y = y0 - th/2 -  1.1 * r * Sin(Theta)
                Case < 3 * 3.14159/2
                   x = x0 - tw +  1.1 * r * Cos(Theta)
                   y = y0 -  1.1 * r * Sin(Theta)
                Case Else
                   x = x0 +  1.1 * r * Cos(Theta)
                   y = y0 -  1.1 * r * Sin(Theta)
             End Select
             Graphic Set Pos(x, y)
             Graphic Print temp$
          Next i
       End If
    
       'Show Legend
       Graphic Width 2
       If BC.PieLegend Then
          iCount = 0 : x = 0
          Graphic Color BC.cAxisValues, -2
          Graphic Set Font BC.axisTitleFont
          Graphic Text Size "8" To w,h
    
          y = ((RC.nBottom-RC.nTop) - (BC.XMax-BC.XMin+1)*h)/2
          For i = BC.Xmin To BC.XMax
             x0 = RC.nRight + 40
             y0 = RC.nTop + iCount * h + y
             Graphic Box (x0,y0)-(x0+w,y0+w),,BCD(i).FadedColor, BCD(i).FadedColor
             Graphic Set Pos (x0+2*w,y0-w/2)
             Graphic Print BCD(i).label(ThisDataSet)
             Incr iCount
          Next i
       End If
    
       'DrawDataSetTitles
       If BC.ShowDataSetTitles Then
          Graphic Color BC.cAxisValues, -2
          Graphic Set Font BC.axisTitleFont
          Graphic Set Pos (RC.nLeft + (Rc.nRight - Rc.nLeft)/2 - Graphic(Text.Size.X,BC.DataSetTitle(ThisDataSet))/2, gH - BC.BM)
          Graphic Print BC.DataSetTitle(ThisDataSet)
       End If
    
       If PieRedraw Then Graphic ReDraw
    
       If BC.SpeedTest Then
          QueryPerformanceCounter qStop
          Dialog Set Text BC.hParent, Format$((qStop-qStart)/qFreq,"###.000") & " seconds"
       End If
    
    End Sub
    
    Sub DrawBezier(ByVal dt As Single, pt0 As Point, pt1 As Point, pt2 As Point, pt3 As Point, iColor As Long)
        Local t,x0,y0,x1,y1 As Single
        t = 0
        x1 = pt0.x * (1 - t) ^ 3  + pt1.x * 3 * t * (1 - t) ^ 2 + pt2.x * 3 * t ^ 2 * (1 - t) + pt3.x * t ^ 3
        y1 = pt0.y * (1 - t) ^ 3  + pt1.y * 3 * t * (1 - t) ^ 2 + pt2.y * 3 * t ^ 2 * (1 - t) + pt3.y * t ^ 3
        t = t + dt
        Do While t < 1
            x0 = x1 : y0 = y1
            x1 = pt0.x * (1 - t) ^ 3  + pt1.x * 3 * t * (1 - t) ^ 2 + pt2.x * 3 * t ^ 2 * (1 - t) + pt3.x * t ^ 3
            y1 = pt0.y * (1 - t) ^ 3  + pt1.y * 3 * t * (1 - t) ^ 2 + pt2.y * 3 * t ^ 2 * (1 - t) + pt3.y * t ^ 3
            Graphic Line  (x0, y0)-(x1, y1), iColor
            t = t + dt
        Loop
        ' Connect to the final point.
        t = 1
        x0 = x1 : y0 = y1 : x1 = pt3.x : y1 = pt3.y
        Graphic Line (x0, y0)-(x1, y1), %Blue
    End Sub
    
    Sub DrawCurves(BCD() As ChartData, BC As ChartSettings, ByVal dt As Single, ByVal tension As Single, ThisDataSet As Long, iColor As Long)
       Local control_scale As Single, i As Integer
       Local pt,pt_before, pt_after, pt_after2, Di, DiPlus1, p1, p2, p3, p4 As Point
    
       'Graphic Clear
        control_scale = CSng(tension / 0.5 * 0.175)
        For i = BC.Xmin To BC.XMax - 1
            If BC.XMin = BC.XMin Then
               pt_before = BCD(i).pt(ThisDataSet)
            Else
               pt_before = BCD(i-1).pt(ThisDataSet)
            End If
            pt = BCD(i).pt(ThisDataSet)
            pt_after = BCD(i+1).pt(ThisDataSet)
            pt_after2 = BCD(Min(i + 2, BC.XMax)).pt(ThisDataSet)
            p1 = BCD(i).pt(ThisDataSet)
            p4 = BCD(i+1).pt(ThisDataSet)
    
            Di.X = pt_after.X - pt_before.X
            Di.Y = pt_after.Y - pt_before.Y
            p2.X = pt.X + control_scale * Di.X
            p2.Y = pt.Y + control_scale * Di.Y
    
            DiPlus1.X = pt_after2.X - BCD(i).pt(ThisDataSet).x
            DiPlus1.Y = pt_after2.Y - BCD(i).pt(ThisDataSet).y
            p3.X = pt_after.X - control_scale * DiPlus1.X
            p3.Y = pt_after.Y - control_scale * DiPlus1.Y
    
            DrawBezier dt, p1, p2, p3, p4, iColor
        Next i
    End Sub
    
    Function ThisLabel(BCD() As ChartData, BC As ChartSettings, iPos As Long, ThisDataSet As Long, DataTotal As Long) As String
       Select Case BC.LabelType
          Case %Label_Label    : Function = BCD(iPos).Label(ThisDataSet)
          Case %Label_Value    : Function = Format$(BCD(iPos).v(ThisDataSet),"###,###,##0")
          Case %Label_PerCent  : Function = Format$(BCD(iPos).v(ThisDataSet)/DataTotal*100,"##0.0") + "%"
          Case %Label_AltXText : Function = BCD(iPos).AltXText(ThisDataSet)
       End Select
    End Function
    
    Function ArcLength(rc As Rect,theta1 As Single, theta2 As Single, Steps As Long) As Single
       Local Result,x,y,L,theta,tn,div,x0,y0,rVert,rHorz,xOld,yOld As Single, i As Long
       'useful values
       div = (theta2 - theta1) / Steps
       rVert = (rc.nBottom - rc.nTop) / 2 : rHorz = (rc.nRight - rc.nLeft) / 2
       x0 = (rc.nRight + rc.nLeft) / 2    : y0 = (rc.nTop + rc.nBottom) / 2
       'approximate arc length by adding chords
       For i = 0 To Steps
          theta = theta1 + i * div
          tn = Tan(-theta)
          x = rVert * rHorz      / ((rVert*rVert + rHorz*rHorz*tn*tn)^0.5)
          y = rVert * rHorz * tn / ((rVert*rVert + rHorz*rHorz*tn*tn)^0.5)
          If theta > 3.14159/2 And theta < 1.5*3.14159 Then x = -1 * x : y = -1 * y
          x = x0 + x : y = y0 + y
          If i Then
             L = ((x-xOld)*(x-xOld) + (y-yOld)*(y-yOld)) ^0.5
             Result += L
          End If
          xOld = x : yOld = y
          Function = Result
       Next i
    End Function
    Last edited by Gary Beene; 21 Sep 2015, 11:02 PM. Reason: updated to v2.0

  • #2
    Great routine, do you have a charting routine for the powerbasic console compiler?

    Comment

    Working...
    X