DRAW GRAPH

Moderator: Rathinagiri

Post Reply
User avatar
serge_girard
Posts: 2770
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Has thanked: 1064 times
Been thanked: 193 times
Contact:

DRAW GRAPH

Post by serge_girard »

There is a small problem with DRAW GRAPH.

When drawing 2 GRAPHS only the last one gest titles and series,
I took SAMPLES\CONTROLS\GRAPH\GRAPH_04\DEMO.PRG and changed to this code:

Code: Select all

#include "hmg.ch"
function main

	define window m at 0,0 width 1400 height 600 main On Init ShowPie() backcolor { 255,255,255}

		define button x
			row 10
			col 10
			caption "Draw"
			action showpie()
		end button

		Define Button Button_1
			Row	10
			Col	150
			Caption	'Print'
			Action PRINT GRAPH OF m PREVIEW DIALOG
		End Button

	end window

	m.center

	m.activate

return nil


function showpie

ERASE WINDOW m

DRAW GRAPH IN WINDOW m AT 100,15;
      TO 500,500 ;
      TITLE "Sales 1" ;
      TYPE PIE;
      SERIES {1500,1800,200,500,800};
		DEPTH 25;
		SERIENAMES {"Product 1","Product 2","Product 3","Product 4","Product 5"};
		COLORS {{255,0,0},{0,0,255},{255,255,0},{0,255,0},{255,128,64},{128,0,128}};
		3DVIEW;
		SHOWXVALUES; 
		SHOWLEGENDS NOBORDER

DRAW GRAPH IN WINDOW m AT 100,550;
      TO 500,900 ;
      TITLE "Sales 2" ;
      TYPE PIE;
      SERIES {1500,1800,1200,500,800};
		DEPTH 25;
		SERIENAMES {"Product 1","Product 2","Product 3","Product 4","Product 5"};
		COLORS {{255,0,0},{0,0,255},{255,255,0},{0,255,0},{255,128,64},{128,0,128}};
		3DVIEW;
		SHOWXVALUES; 
		SHOWLEGENDS NOBORDER

return nil
When clicking on the DRAW-Button titles and series are displayed for a second.

Serge
Attachments
draw_graph.png
draw_graph.png (21.19 KiB) Viewed 3354 times
Serge Now Is The Happiest Time Of Your Life !

User avatar
Pablo César
Posts: 4059
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil
Has thanked: 100 times
Been thanked: 182 times

Post by Pablo César »

Hi Serge,

Its seems to be a limitation... :shock:

I prepared this changing that accepts others by naming each graph as control name:
Screen177.png
Screen177.png (22.93 KiB) Viewed 3335 times
 

Code: Select all

#include "hmg.ch"

function main

	define window m at 0,0 width 940 height 560 main On Init ShowPie() backcolor { 255,255,255}

		define button x
			row 10
			col 10
			caption "Draw"
			action showpie()
		end button

		Define Button Button_1
			Row	10
			Col	150
			Caption	'Print'
			Action MsgInfo("Try to save form to image file with BosTaurus"+CRLF+"and then print it...","Hi Serge") // printgraph1( <"windowname"> , <.lpreview.> , <.ldialog.> )
		End Button

	end window

	m.center

	m.activate

return nil


function showpie
LOCAL aSer1:={1500,1800,200,500,800}
LOCAL aSer2:={500,800,20,50,80}
LOCAL aName1:={"Product 1","Product 2","Product 3","Product 4","Product 5"}
LOCAL aName2:={"Product 6","Product 7","Product 8","Product 9","Product 10"}
LOCAL aColor1:={{255,0,0},{0,0,255},{255,255,0},{0,255,0},{255,128,64},{128,0,128}}
LOCAL aColor2:={{255,0,0},{0,0,255},{255,255,0},{0,255,0},{255,128,64},{128,0,128}}
LOCAL cTitle1:="Sales 1"
LOCAL cTitle2:="Sales 2"
LOCAL nD1:=25
LOCAL nD2:=25

PRIVATE CtrlPiew:=1

ERASE WINDOW m
/*
DRAW GRAPH IN WINDOW m AT 100,15;
      TO 500,500 ;
      TITLE "Sales 1" ;
      TYPE PIE;
      SERIES {1500,1800,200,500,800};
		DEPTH 25;
		SERIENAMES {"Product 1","Product 2","Product 3","Product 4","Product 5"};
		COLORS {{255,0,0},{0,0,255},{255,255,0},{0,255,0},{255,128,64},{128,0,128}};
		3DVIEW;
		SHOWXVALUES; 
		SHOWLEGENDS NOBORDER

DRAW GRAPH IN WINDOW m AT 100,550;
      TO 500,900 ;
      TITLE "Sales 2" ;
      TYPE PIE;
      SERIES {1500,1800,1200,500,800};
		DEPTH 25;
		SERIENAMES {"Product 1","Product 2","Product 3","Product 4","Product 5"};
		COLORS {{255,0,0},{0,0,255},{255,255,0},{0,255,0},{255,128,64},{128,0,128}};
		3DVIEW;
		SHOWXVALUES; 
		SHOWLEGENDS NOBORDER
*/

DrawPieGraph1( "m",;
               "CtrlPiew_1",;
		       100,;
		       15,;
		       500,;
		       500,;
		       aSer1,;
		       aName1,;
		       aColor1,;
		       cTitle1,;
		       nD1,;
		       .T.,;
		       .T.,;
		       .T.,;
		       .T. )
			   
DrawPieGraph1( "m",;
               "CtrlPiew_2",;
		       100,;
		       550,;
		       500,;
		       900,;
		       aSer2,;
		       aName2,;
		       aColor2,;
		       cTitle2,;
		       nD2,;
		       .T.,;
		       .T.,;
		       .T.,;
		       .T. )
return nil

function drawpiegraph1(windowname,CtrlPiew,fromrow,fromcol,torow,tocol,series,aname,colors,ctitle,depth,l3d,lxval,lsleg,lnoborder)
local topleftrow := fromrow
local topleftcol := fromcol
local toprightrow := fromrow
local toprightcol := tocol
local bottomrightrow := torow
local bottomrightcol := tocol
local bottomleftrow := torow
local bottomleftcol := fromcol
local middletoprow := fromrow
local middletopcol := fromcol + int(tocol - fromcol) / 2
local middleleftrow := fromrow + int(torow - fromrow) / 2
local middleleftcol := fromcol
local middlebottomrow := torow
local middlebottomcol := fromcol + int(tocol - fromcol) / 2
local middlerightrow := fromrow + int(torow - fromrow) / 2
local middlerightcol := tocol
local fromradialrow := 0
local fromradialcol := 0
local toradialrow := 0
local toradialcol := 0
local degrees := {}
local cumulative := {}
local j,i,sum := 0
local cname := ""
local shadowcolor := {}
local previos_cumulative

_HMG_SYSDATA [ 108 ] [ GetFormIndex (windowname) ] := { fromrow , fromcol , tocol - fromcol , torow - fromrow }

if ! lnoborder

	DrawLine(windowname, torow  ,fromcol  ,torow  ,tocol  ,WHITE)
	DrawLine(windowname, torow-1,fromcol+1,torow-1,tocol-1,GRAY )
	DrawLine(windowname, torow-1,fromcol  ,fromrow  ,fromcol  ,GRAY )
	DrawLine(windowname, torow-2,fromcol+1,fromrow+1,fromcol+1,GRAY )
	DrawLine(windowname, fromrow  ,fromcol  ,fromrow  ,tocol-1,GRAY )
	DrawLine(windowname, fromrow+1,fromcol+1,fromrow+1,tocol-2,GRAY )
	DrawLine(windowname, fromrow  ,tocol  ,torow  ,tocol  ,WHITE)
	DrawLine(windowname, fromrow  ,tocol-1,torow-1,tocol-1,GRAY )
   
endif

if HMG_LEN(ALLTRIM(ctitle)) > 0
   if _iscontroldefined(CtrlPiew,windowname)
      _releasecontrol(CtrlPiew,windowname)
   endif
   define label &(CtrlPiew)
      parent &windowname
      row fromrow + 10
      col iif(HMG_LEN(ALLTRIM(ctitle)) * 12 > (tocol - fromcol),fromcol,int(((tocol - fromcol) - (HMG_LEN(ALLTRIM(ctitle)) * 12))/2) + fromcol)
      autosize .t.
      fontcolor {0,0,255}
      fontbold .t.
      fontname "Arial"
      fontunderline .t.
      fontsize 12
      value ALLTRIM(ctitle)
	  transparent .t.
   end label
   fromrow := fromrow + 40
endif   

if lsleg
   if HMG_LEN(aname) * 20 > (torow - fromrow)
      msginfo("No space for showing legends")
   else
      torow := torow - (HMG_LEN(aname) * 20)
   endif
endif

drawrect(windowname,fromrow+10,fromcol+10,torow-10,tocol-10,{0,0,0},1,{255,255,255})

if l3d
   torow := torow - depth
endif

fromcol := fromcol + 25
tocol := tocol - 25
torow := torow - 25
fromrow := fromrow + 25

topleftrow := fromrow
topleftcol := fromcol
toprightrow := fromrow
toprightcol := tocol
bottomrightrow := torow
bottomrightcol := tocol
bottomleftrow := torow
bottomleftcol := fromcol
middletoprow := fromrow
middletopcol := fromcol + int(tocol - fromcol) / 2
middleleftrow := fromrow + int(torow - fromrow) / 2
middleleftcol := fromcol
middlebottomrow := torow
middlebottomcol := fromcol + int(tocol - fromcol) / 2
middlerightrow := fromrow + int(torow - fromrow) / 2
middlerightcol := tocol

torow := torow + 1
tocol := tocol + 1

for i := 1 to HMG_LEN(series)
   sum := sum + series[i]
next i
for i := 1 to HMG_LEN(series)
   aadd(degrees,round(series[i]/sum * 360,0))
next i
sum := 0
for i := 1 to HMG_LEN(degrees)
   sum := sum + degrees[i]
next i
if sum <> 360
   degrees[HMG_LEN(degrees)] := degrees[HMG_LEN(degrees)] + (360 - sum)
endif

sum := 0
for i := 1 to HMG_LEN(degrees)
   sum := sum + degrees[i]
   aadd(cumulative,sum)
next i

previos_cumulative := -1

fromradialrow := middlerightrow
fromradialcol := middlerightcol
for i := 1 to HMG_LEN(cumulative)

	if cumulative[i] == previos_cumulative
		loop
	endif

	previos_cumulative := cumulative[i]

   shadowcolor := {iif(colors[i,1] > 50,colors[i,1] - 50,0),iif(colors[i,2] > 50,colors[i,2] - 50,0),iif(colors[i,3] > 50,colors[i,3] - 50,0)}

   do case
      case cumulative[i] <= 45
         toradialcol := middlerightcol
         toradialrow := middlerightrow - round(cumulative[i] / 45 * (middlerightrow - toprightrow),0)
         drawpie(windowname,fromrow,fromcol,torow,tocol,fromradialrow,fromradialcol,toradialrow,toradialcol,,,colors[i])
         fromradialrow := toradialrow
         fromradialcol := toradialcol
      case cumulative[i] <= 90 .and. cumulative[i] > 45
         toradialrow := toprightrow
         toradialcol := toprightcol - round((cumulative[i] - 45) / 45 * (toprightcol - middletopcol),0)
         drawpie(windowname,fromrow,fromcol,torow,tocol,fromradialrow,fromradialcol,toradialrow,toradialcol,,,colors[i])
         fromradialrow := toradialrow
         fromradialcol := toradialcol
      case cumulative[i] <= 135 .and. cumulative[i] > 90          
         toradialrow := topleftrow
         toradialcol := middletopcol - round((cumulative[i] - 90) / 45 * (middletopcol - topleftcol),0)
         drawpie(windowname,fromrow,fromcol,torow,tocol,fromradialrow,fromradialcol,toradialrow,toradialcol,,,colors[i])
         fromradialrow := toradialrow
         fromradialcol := toradialcol
      case cumulative[i] <= 180 .and. cumulative[i] > 135          
         toradialcol := topleftcol
         toradialrow := topleftrow + round((cumulative[i] - 135) / 45 * (middleleftrow - topleftrow),0)
         drawpie(windowname,fromrow,fromcol,torow,tocol,fromradialrow,fromradialcol,toradialrow,toradialcol,,,colors[i])
         fromradialrow := toradialrow
         fromradialcol := toradialcol
      case cumulative[i] <= 225 .and. cumulative[i] > 180          
         toradialcol := topleftcol
         toradialrow := middleleftrow + round((cumulative[i] - 180) / 45 * (bottomleftrow - middleleftrow),0)
         if l3d
            for j := 1 to depth
               drawarc(windowname,fromrow + j,fromcol,torow+j,tocol,fromradialrow+j,fromradialcol,toradialrow+j,toradialcol,shadowcolor)
            next j
         endif   
         drawpie(windowname,fromrow,fromcol,torow,tocol,fromradialrow,fromradialcol,toradialrow,toradialcol,,,colors[i])
         fromradialrow := toradialrow
         fromradialcol := toradialcol
      case cumulative[i] <= 270 .and. cumulative[i] > 225          
         toradialrow := bottomleftrow
         toradialcol := bottomleftcol + round((cumulative[i] - 225) / 45 * (middlebottomcol - bottomleftcol),0)
         if l3d
            for j := 1 to depth
               drawarc(windowname,fromrow + j,fromcol,torow+j,tocol,fromradialrow+j,fromradialcol,toradialrow+j,toradialcol,shadowcolor)
            next j
         endif   
         drawpie(windowname,fromrow,fromcol,torow,tocol,fromradialrow,fromradialcol,toradialrow,toradialcol,,,colors[i])
         fromradialrow := toradialrow
         fromradialcol := toradialcol
      case cumulative[i] <= 315 .and. cumulative[i] > 270          
         toradialrow := bottomleftrow
         toradialcol := middlebottomcol + round((cumulative[i] - 270) / 45 * (bottomrightcol - middlebottomcol),0)
         if l3d
            for j := 1 to depth
               drawarc(windowname,fromrow + j,fromcol,torow+j,tocol,fromradialrow+j,fromradialcol,toradialrow+j,toradialcol,shadowcolor)
            next j
         endif   
         drawpie(windowname,fromrow,fromcol,torow,tocol,fromradialrow,fromradialcol,toradialrow,toradialcol,,,colors[i])
         fromradialrow := toradialrow
         fromradialcol := toradialcol
      case cumulative[i] <= 360 .and. cumulative[i] > 315
         toradialcol := bottomrightcol
         toradialrow := bottomrightrow - round((cumulative[i] - 315) / 45 * (bottomrightrow - middlerightrow),0)
         if l3d
            for j := 1 to depth
               drawarc(windowname,fromrow + j,fromcol,torow+j,tocol,fromradialrow+j,fromradialcol,toradialrow+j,toradialcol,shadowcolor)
            next j
         endif
         drawpie(windowname,fromrow,fromcol,torow,tocol,fromradialrow,fromradialcol,toradialrow,toradialcol,,,colors[i])
         fromradialrow := toradialrow
         fromradialcol := toradialcol
      endcase
   if l3d            
      drawline(windowname,middleleftrow,middleleftcol,middleleftrow+depth,middleleftcol)
      drawline(windowname,middlerightrow,middlerightcol,middlerightrow+depth,middlerightcol)
      drawarc(windowname,fromrow + depth,fromcol,torow + depth,tocol,middleleftrow+depth,middleleftcol,middlerightrow+depth,middlerightcol)
   endif
next i
if lsleg
   fromrow := torow + 20 + iif(l3d,depth,0)
   for i := 1 to HMG_LEN(aname)
      if _iscontroldefined(CtrlPiew+"_pielegend_"+ALLTRIM(STR(i,3,0)),windowname)
         _releasecontrol(CtrlPiew+"_pielegend_"+ALLTRIM(STR(i,3,0)),windowname)
      endif
      cname := CtrlPiew+"_pielegend_"+ALLTRIM(STR(i,3,0))
      drawrect(windowname,fromrow,fromcol,fromrow + 15,fromcol + 15,{0,0,0},1,colors[i])
      define label &cname
         parent &windowname
         row fromrow
         col fromcol + 20
         fontname "Arial"
         fontsize 8
         autosize .t.
         value aname[i]+iif(lxval," - "+ALLTRIM(STR(series[i],19,2))+" ("+ALLTRIM(STR(degrees[i] / 360 * 100,6,2))+" %)","")
         fontcolor colors[i]
	transparent .t.
      end label
      fromrow := fromrow + 20
   next i
endif   
return nil
But there are other details, like as aLocation where _HMG_SYSDATA [ 108 ] is must include or most rightly to sum both piegraphs.

So, as my lack of time I left to prepare other printgraph. But you can try to save it with BosTaurus to a image file...
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein

User avatar
serge_girard
Posts: 2770
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Has thanked: 1064 times
Been thanked: 193 times
Contact:

Post by serge_girard »

Thx Pablo for your time and willingness!

I can wait, Serge
Serge Now Is The Happiest Time Of Your Life !

emzampi
Posts: 86
Joined: Sun Aug 11, 2013 9:00 am
Has thanked: 1 time

Post by emzampi »

Grafico.jpg
Grafico.jpg (72.69 KiB) Viewed 1528 times

emzampi
Posts: 86
Joined: Sun Aug 11, 2013 9:00 am
Has thanked: 1 time

Post by emzampi »

Hello nobody knows if it is possible to put the months of the Graph example vertically

special thanks to anyone who answers me

User avatar
Claudio Ricardo
Posts: 216
Joined: Tue Oct 27, 2020 3:38 am
DBs Used: DBF, MySQL, MariaDB
Location: Bs. As. - Argentina
Has thanked: 72 times
Been thanked: 91 times

Post by Claudio Ricardo »

Hi... BossTaurus library have one function to put text in different positions and degree rotate.
Corrige al sabio y lo harás más sabio, Corrige al necio y lo harás tu enemigo.
WhatsApp / Telegram: +54 911-63016162

emzampi
Posts: 86
Joined: Sun Aug 11, 2013 9:00 am
Has thanked: 1 time

Post by emzampi »

tanks Claudio

Post Reply