With GoDB you can construct graphs and charts- both static and dynamic quite easily and pep up your data presentation. This article will touch the shallow waters of charting with static data. End of the article there is a link to download the source code for this charting application.
First some definitions:
''***************************************************************** ''''SOME VARIABLES THAT CAN BE INCLUDED IN THE QUERY STRING ARE 'XMargin = 20 MARGIN WIDTH BETWEEN COORDINATES IN X LEGEND 'XOrigin = 5 STARTING X1 POSITION OF RECTANGLE 'XRange = 190 X2-530, XRANGE IS DIFF OF X1 AND X2 'XDiv = 5 NO. OF DIVISIONS IN X AXIS 'YMargin = 20 MARGIN WIDTH BETWEEN COORDINATES IN Y LEGEND 'YOrigin = 210 STARTING Y1 POSITION OF RECTANGLE 'YRange = 200 YRANGE IS DIFF OF Y1 AND Y2 'YDiv = 5 NO. OF DIVISIONS IN Y AXIS 'ShowData = 1 TO DISPLAY DATA, WHILE PLOTTING POINTS 'Type = 1 LINE CHART 'Type = 2 BAR CHART ''***************************************************************** 'XAXIS$ = LIST OF X COORDINATES 'YAXIS$ = LIST OF Y COORDINATES 'SAMPLE COORDINATES 'XAxis$ = "1999,2000,2001,2002,2003,2004,2005,2006,2007,2008, 2009" 'YAxis$ = "50.340,83,737,90.50,400,300,200,200,400, 200, 300"
Bar Chart
Drawing the rectangle bar
To draw the rectangle bar, use drawrect function. Ex:
drawrect(XOrigin-10,YOrigin,XRange+30,-YRange,2,0,46815,46815)
For Color coding the bar use fillrect function. Ex:
fillrect(XOrigin,YOrigin,XRange,-YRange,46815)
Line charts
Line charts involve two basic components. Plotting the data and drawing line.
Plotting Data
If ubound(Str$) > 0 Then For Count = 0 to ubound(Str$) If Count=0 Then m1=split(arrY$,Str$(Count),",") ElseIf Count = 1 Then m1=split(arrY$,Str$(Count),",") End If
for i = 0 to NoOfPoints - 1 DataX = atol(arrX$(i)) NewX = TransX(DataX, XMax, XMin) DataY = atol(arrY$(i)) NewY = TransY(DataY, YMax, YMin) If Request$("Type") = "1" Then iff i>0 then drawline(NewX,NewY,OldX,OldY,1,1) iff ShowData>0 then textout(NewX,NewY,arrY$(i),0,63504, 5) drawrect(NewX,NewY,2,2,2,1,63488,0) ElseIf Request$("Type") = "2" Then iff showData>0 then textout(NewX-5,NewY-20,arrY$(i),0,63504, 5) drawrect(NewX-5,NewY,10,YOrigin-NewY,2,1,1,255) End If OldX = NewX OldY = NewY next Next Else for i = 0 to NoOfPoints - 1 DataX = atol(arrX$(i)) NewX = TransX(DataX, XMax, XMin) DataY = atol(arrY$(i)) NewY = TransY(DataY, YMax, YMin) If Request$("Type") = "1" Then iff i>0 then drawline(NewX,NewY,OldX,OldY,1,1) iff ShowData>0 then textout(NewX,NewY,arrY$(i),0,63504, 5) drawrect(NewX,NewY,2,2,2,1,63488,0) ElseIf Request$("Type") = "2" Then iff showData>0 then textout(NewX-5,NewY-20,arrY$(i),0,63504, 5) drawrect(NewX-5,NewY,10,YOrigin-NewY,2,1,1,255) End If OldX = NewX OldY = NewY next End If
Download
Plotting charts from dynamic data or from database shall be dealt in future articles. So expect a sequel.
|