@ 1, 1 GRAPH oGraph;
SIZE 250, 200;
TYPE 3; // GRAPH_TYPE_...
YVALUES 3D XGRID YGRID XVALUES LEGENDS
James Bott wrote:Alvaro,
Sorry, no I never did. Most of my graphs are time series and TGraph works great for that. I can't remember what I did for the x,y plots that I needed back then, but I can find no evidence that I ever tried it. The TGraph code is quit complex and I expect it will take quite some time to modify it.
Regards,
James
#Define GRAPH_TYPE_XY_AQ 6
data chart_top
data chart_bottom
data chart_left
data chart_right
DATA nXMaxVal // Max Value
DATA nXMinVal // Min Value
data XY_Values
METHOD aq_DrawLine( nY, nX, nHigh, nWidth, nColor, lDotted , nPenwidth )
METHOD aq_DrawPoint( nY, nX, nColor, lDotted , nPixels , nPenwidth )
// --------------------------------------------------------------------------- //
METHOD aq_DrawLine( nY1, nX1, nY2, nX2, nColor, lDotted , nPenwidth) CLASS TGraph
local x1,x2,y1,y2
local era_nPenwidth
default nPenwidth := 3
era_nPenwidth := ::nPenwidth
::nPenWidth := nPenwidth
x1 := ::chart_left + (nX1-::nXMinVal ) / (::nXMaxval-::nXMinVal) * ( ::chart_right - ::chart_left )
y1 := ::chart_bottom - (nY1-::nMinVal) / (::nMaxval-::nMinVal) * ( ::chart_bottom - ::chart_top )
x2 := ::chart_left + (nX2-::nXMinVal ) / (::nXMaxval-::nXMinVal) * ( ::chart_right - ::chart_left )
y2 := ::chart_bottom - (nY2-::nMinVal) / (::nMaxval-::nMinVal) * ( ::chart_bottom - ::chart_top )
::DrawLine( y1, x1, y2, x2, nColor, lDotted )
::nPenWidth := era_nPenwidth
return nil
// --------------------------------------------------------------------------- //
METHOD aq_DrawPoint( nY1, nX1, nColor, lDotted , npixels , nPenwidth ) CLASS TGraph
local x1,y1
local era_nPenwidth
default nPenwidth := nPenwidth
default nPixels := 7
era_nPenwidth := ::nPenwidth
::nPenWidth := 4
nPixels := nPixels /2
x1 := ::chart_left + (nX1-::nXMinVal ) / (::nXMaxval-::nXMinVal) * ( ::chart_right - ::chart_left )
y1 := ::chart_bottom - (nY1-::nMinVal) / (::nMaxval-::nMinVal) * ( ::chart_bottom - ::chart_top )
::DrawLine( y1 , x1-nPixels , y1+nPixels, x1, nColor, lDotted )
::DrawLine( y1+nPixels , x1 , y1, x1+nPixels, nColor, lDotted )
::DrawLine( y1 , x1+nPixels , y1-nPixels, x1, nColor, lDotted )
::DrawLine( y1-nPixels , x1 , y1 , x1-nPixels , nColor, lDotted )
::nPenWidth := era_nPenwidth
return nil
::XY_Values :={}
::chart_top := nTop
::chart_bottom := nBottom
::chart_left := nLeft
::chart_right := nRight
IF ::nType == GRAPH_TYPE_XY_AQ
FOR nJ := 1 TO Len( ::aSeries )
for nI := 1 to len( ::XY_Values[nJ] ) -1
::aq_Drawline( ::XY_Values[nJ, nI,2] , ::XY_Values[nJ,nI,1] , ;
::XY_Values[nJ, nI+1,2] , ::XY_Values[nJ, nI+1,1], ::aSeries[nj,2] )
next nI
if len( ::XY_Values[nJ] ) == 1
::aq_DrawPoint( ::XY_Values[nJ, 1,2] , ::XY_Values[nJ,1,1] , ::aSeries[nj,2] ,, )
endif
next nJ
if ::lYVal
::Say( 325 , 80 , "Hola" , ::aFont[3], rgb(0,0,0) , ::nTLeft )
endif
endif
oChart:nType := GRAPH_TYPE_XY_AQ
oChart:nMaxVal := max_value // your calculated max value for Y axis
oChart:nMinVal := min_value // your calculated min value for Y axis
oChart:nXMaxVal := max_Xvalue // your calculated max value for X axis
oChart:nXMinVal := min_Xvalue // your calculated min value for X axis
oChart:AddSerie( {} , "name_or_the_serie1" , RGB(128,128,255) ) // empty array
aadd( oChart:XY_Values , aArray1 ) // aArray1 is an array with the XY points i.e. { { 1.25 , 9.25} , { 1.5 , 9.452 } , ......}
oChart:AddSerie( {} , "name_or_the_serie2" , RGB(128,128,255) ) // empty array
aadd( oChart:XY_Values , aArray2 ) // aArray2 is an array with the XY points i.e. { { 3.25 , 7.25} , { 2.5 , 8.452 } , ......}
you may add more series
James Bott wrote:Alvaro,
Wow, very impressive. May I get a copy of your new tgraph.prg?
You can find my email address on my website http://gointellitech.com.
James Bott wrote:Alvaro,
It is not clear to me if you are automatically finding the min and max for each axis in the class, or if you must do the calculation outside the class and pass those values.
One of the first programs I wrote (way back in the BASIC era, circa 1980), I wrote code to find those values. I discovered that it was a challenge to find those values since they needed to be rounded up (or down) to a reasonable number that made the chart look right. E.G. rounding 10.3 to 11 or 15 or whatever.
Of course, being able to specify the ranges by overriding the internal calculations would also be useful.
------------------------------
May I suggest changing this line:
oChart:nType := GRAPH_TYPE_XY_AQ
To something like this:
oChart:nType := GRAPH_TYPE_XY //AQ
I am assuming AQ are your initials? The above change just keeps the naming consistent with the existing ones.
If you care to share this modified class with everyone, then I would also first make sure you have the latest copy of TGraph, and make your changes to that version. Also I would suggest adding comments at the top explaining your work and adding your name and contact info.
I am looking forward to seeing your modified TGraph class.
Regards,
James
oChart:nXMaxVal := max_Xvalue + ( max_Xvalue - min_Xvalue ) *.1
oChart:nXMinVal := min_Xvalue - ( max_Xvalue - min_Xvalue ) *.1
Return to FiveWin for Harbour/xHarbour
Users browsing this forum: No registered users and 69 guests