[RESOLVED] Ai's Grok and ChatGPT cannot fix non-displaying Graph
Posted: Wed Nov 26, 2025 7:00 am
what's keeping the Graph from showing ??
Ai's Grok and ChatGPT cannot fix non-displaying Graph :
Ai's Grok and ChatGPT cannot fix non-displaying Graph :
Code: Select all
Enumeration
#Window
#Canvas
EndEnumeration
; -------------------------------------------------
; Data
; -------------------------------------------------
Global Dim DataX.f(8)
Global Dim DataY.f(8)
DataX(0) = 0.200 : DataY(0) = 151.1
DataX(1) = 0.300 : DataY(1) = 225.6
DataX(2) = 0.400 : DataY(2) = 308.3
DataX(3) = 0.500 : DataY(3) = 384.1
DataX(4) = 0.600 : DataY(4) = 470.9
DataX(5) = 0.700 : DataY(5) = 517.7
DataX(6) = 0.800 : DataY(6) = 575.8
DataX(7) = 0.900 : DataY(7) = 625.3
DataX(8) = 1.000 : DataY(8) = 664.5
#POINTS = 8 ; highest index (0..8) = 9 points total
; -------------------------------------------------
; Settings
; -------------------------------------------------
Global MarginLeft = 80
Global MarginRight = 30
Global MarginTop = 50
Global MarginBottom = 80
Global PointSize.f = 6.0
; -------------------------------------------------
Procedure DrawGraph()
Protected w = GadgetWidth(#Canvas)
Protected h = GadgetHeight(#Canvas)
Protected pw = w - MarginLeft - MarginRight
Protected ph = h - MarginTop - MarginBottom
If pw < 10 Or ph < 10 : ProcedureReturn : EndIf
If StartVectorDrawing(CanvasVectorOutput(#Canvas))
; Background first
VectorSourceColor(#White)
FillVectorOutput()
; Min/max
Protected minX.f = DataX(0), maxX.f = DataX(0)
Protected minY.f = DataY(0), maxY.f = DataY(0)
Protected i
For i = 0 To #POINTS
If DataX(i) < minX : minX = DataX(i) : EndIf
If DataX(i) > maxX : maxX = DataX(i) : EndIf
If DataY(i) < minY : minY = DataY(i) : EndIf
If DataY(i) > maxY : maxY = DataY(i) : EndIf
Next
; padding
Protected padX.f = (maxX - minX) * 0.05 : If padX = 0 : padX = 0.1 : EndIf
Protected padY.f = (maxY - minY) * 0.05 : If padY = 0 : padY = 1.0 : EndIf
minX = minX - padX : maxX = maxX + padX
minY = minY - padY : maxY = maxY + padY
Macro PX(x) : (MarginLeft + (x - minX)/(maxX - minX)*pw) : EndMacro
Macro PY(y) : (MarginTop + ph - (y - minY)/(maxY - minY)*ph) : EndMacro
; Grid
VectorSourceColor(RGB(235,235,235))
Protected t.f
For i = 0 To 10
t = i/10
MovePathCursor(MarginLeft + t*pw, MarginTop) : AddPathLine(MarginLeft + t*pw, MarginTop + ph)
MovePathCursor(MarginLeft, MarginTop + t*ph) : AddPathLine(MarginLeft + pw, MarginTop + t*ph)
Next
StrokePath(1)
; Axes
VectorSourceColor(#Black)
MovePathCursor(MarginLeft, MarginTop)
AddPathLine(MarginLeft, MarginTop + ph)
AddPathLine(MarginLeft + pw, MarginTop + ph)
StrokePath(3)
; Tick labels
VectorFont(GetGadgetFont(#PB_Default), 12)
For i = 0 To 10
t = i/10
Protected vx.f = minX + t*(maxX-minX)
Protected vy.f = minY + t*(maxY-minY)
MovePathCursor(PX(vx) - VectorTextWidth(StrF(vx,2))/2, MarginTop+ph+12)
DrawVectorText(StrF(vx,2))
MovePathCursor(MarginLeft - VectorTextWidth(StrF(vy,0))-10, PY(vy)-6)
DrawVectorText(StrF(vy,0))
Next
; Title
VectorFont(GetGadgetFont(#PB_Default), 26)
MovePathCursor(w/2 - VectorTextWidth("XY Data Graph")/2, 20)
DrawVectorText("XY Data Graph")
; X label
VectorFont(GetGadgetFont(#PB_Default), 20)
MovePathCursor(w/2 - VectorTextWidth("X")/2, MarginTop + ph + 55)
DrawVectorText("X")
; Y label (rotated)
SaveVectorState()
VectorFont(GetGadgetFont(#PB_Default), 20)
TranslateCoordinates(26, h/2)
RotateCoordinates(0, 0, -90)
MovePathCursor(-VectorTextWidth("Y")/2, 0)
DrawVectorText("Y")
RestoreVectorState()
; Data line
VectorSourceColor(RGB(0,120,255))
MovePathCursor(PX(DataX(0)), PY(DataY(0)))
For i = 1 To #POINTS
AddPathLine(PX(DataX(i)), PY(DataY(i)))
Next
StrokePath(4)
; Data points
VectorSourceColor(#Red)
For i = 0 To #POINTS
AddPathCircle(PX(DataX(i)), PY(DataY(i)), PointSize)
Next
FillPath()
StopVectorDrawing()
EndIf
EndProcedure
; -------------------------------------------------
; MAIN
; -------------------------------------------------
If OpenWindow(#Window, 0, 0, 900, 600, "PureBasic XY Graph - FIXED",
#PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_SizeGadget)
CanvasGadget(#Canvas, 0, 0, WindowWidth(#Window), WindowHeight(#Window))
BindGadgetEvent(#Canvas, @DrawGraph(), #PB_EventType_Resize)
BindEvent(#PB_Event_SizeWindow, @DrawGraph())
DrawGraph()
Repeat
Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
EndIf