FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Sparklines in XBROWSE like Excel 2010
Posts: 6983
Joined: Fri Oct 07, 2005 07:07 PM
Sparklines in XBROWSE like Excel 2010
Posted: Mon Dec 07, 2009 01:55 AM
Today I had a look at the new 2010 EXCEL features.
Now you can have graphs in every row. Complex data can be shown in a more easy form.
Thanks to :bPaintText you can do this with xBrowse too.
For Excel 2010 we’ve implemented sparklines, “intense, simple, word-sized graphics”, as their inventor Edward Tufte describes them in his book Beautiful Evidence. Sparklines help bring meaning and context to numbers being reported and, unlike a chart, are meant to be embedded into what they are describing:



Best regards,
Otto



Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Sparklines in XBROWSE like Excel 2010
Posted: Mon Dec 07, 2009 02:46 AM

Mr. Otto

Excellant.
Yes, this little known feature oCol:bPaintText puts lot of power in our hands.
But the way you have used this power is commendable.

Regards



G. N. Rao.

Hyderabad, India
Posts: 6983
Joined: Fri Oct 07, 2005 07:07 PM
Re: Sparklines in XBROWSE like Excel 2010
Posted: Mon Dec 07, 2009 11:01 AM
Best regards,
Otto

Code (fw): Select all Collapse
#include "fivewin.ch"
#include "xbrowse.ch"


function main()

   local oDlg, oBrw
   local oFont
   local aData    := {}

   DEFINE FONT oFont   NAME 'TAHOMA' SIZE 0,-12

   AAdd( aData, {'A',  12, 450, 130, 330, 155,  80, 70,  80, 90, 111, 166, 100,"A" } )
   AAdd( aData, {'B', 130, 230, 155,  80,  12, 500, 70,  80, 90, 111, 166, 200 ,"B"} )
   AAdd( aData, {'C',  80, 270, 280,  90, 411, 166, 12, 500, 130, 330, 155, 50 ,"C"} )
   AAdd( aData, {'D',  50,  90, 111, 130, 330, 355, 80,  12, 500, 70, 166, 300 ,"D"} )
   AAdd( aData, {'E', 330, 330, 155, 180, 412, 470, 70,  80, 90, 111, 166, 300 ,"B"} )
   AAdd( aData, {'F', 430, 330, 155, 280, 212, 500, 70,  80, 90, 111, 166, 300 ,"B"} )
   AAdd( aData, {'G',  30, 330, 155, 380, 200, 480, 70,  80, 90, 111, 166, 300 ,"B"} )
   AAdd( aData, {'H', 430, 330, 155, 480, 312, 250, 70,  80, 90, 111, 166, 300 ,"B"} )
   AAdd( aData, {'I', 330, 330, 155,  86, 212, 400, 70,  80, 90, 111, 166, 300 ,"B"} )
   AAdd( aData, {'J', 230, 330, 155,   8, 112, 300, 70,  80, 90, 111, 166, 300 ,"B"} )


   DEFINE DIALOG oDlg SIZE 1024,440 PIXEL FONT oFont

   @ 10, 10 XBROWSE oBrw ;
      HEADERS  'Name', 'I','II','III','IV','V','VI','VII','VIII','IX','X','XI','XII','Graph';
      SIZE 500, 200 PIXEL ;
      OF oDlg ;
      ARRAY aData AUTOCOLS ;
      LINES

   oBrw:nStretchCol := STRETCHCOL_LAST

   WITH OBJECT oBrw:aCols[14]
   :nHeadStrAlign := AL_CENTER
   :nWidth        := 200
   :bPaintText    := { |oCol, hDC, cText, aCoord| DrawText( oCol, hDC, cText, aCoord, oBrw ) }
END

oBrw:nDataLines := 6
oBrw:CreateFromCode()

ACTIVATE DIALOG oDlg CENTERED

RELEASE FONT oFont

return nil

static function DrawText( oCol, hDC, cText, aCoord, oBrw)

   local nTop  := aCoord[ 1 ], nLeft := aCoord[ 2 ]
   local nBottom := aCoord[ 3 ], nRight := aCoord[ 4 ]
   local nRow  := nTop
   local cLine, nFontHt, nAt,oBrush,aRect1:={}

   local rcttop      := nTop
   local rctleft     := nLeft
   local rctbottom   := nBottom
   local rctright    := nRight
   LOCAL I           :=0
   LOCAL nRowheight  := nBottom - nTop
   local nWidth      := 0
*----------------------------------------------------------


// missing:  get the Maxvalue here I use  500

   DEFINE BRUSH oBrush  COLOR RGB(55,255,55)


   FOR I:= 2 to  13
   
     /* 
      rcttop   := INT( rctbottom - nRowheight / 500 * oBrw:aCols[I]:value  )
      rctleft  := rctleft + 25
      rctright := rctleft + 20
      aRect1 := { rcttop, rctleft, rctbottom, rctright }
      FillRect( hDC, aRect1, oBrush:hBrush)
     */

      rctleft  := rctleft + 25
      rcttop   := INT( rctbottom - nRowheight / 500 * oBrw:aCols[I]:value  )

      MoveTo( hDC, rctleft, rcttop )
      nWidth:=5

      Ellipse( hDC, rctleft - 3, rcttop, rctleft + nWidth - 1, rcttop + nWidth - 1 )

      if I < 13
         rctright := rctleft + 25
         rcttop   :=     INT( rctbottom - nRowheight / 500 * oBrw:aCols[I+1]:value  )
         LineTo( hDC, rctright, rcttop )
      endif

   next

   oBrush:end()

return nil
*----------------------------------------------------------
Posts: 3107
Joined: Fri Oct 07, 2005 06:28 PM
Re: Sparklines in XBROWSE like Excel 2010
Posted: Mon Dec 07, 2009 11:18 AM

Otto,
It make an error on nzeile . wich is the value of nzeile ?
I think we can insert it on xbrowse class as a new method

Best Regards, Saludos



Falconi Silvio
Posts: 6983
Joined: Fri Oct 07, 2005 07:07 PM
Re: Sparklines in XBROWSE like Excel 2010
Posted: Mon Dec 07, 2009 12:05 PM

Silvio,

nZeile = nRowheight

I changed the code for better understanding and forgot of one item. Now it is ok.
Best regards,
Otto

Posts: 3107
Joined: Fri Oct 07, 2005 06:28 PM
Re: Sparklines in XBROWSE like Excel 2010
Posted: Mon Dec 07, 2009 07:35 PM

Otto why not use tgraph class ?

Best Regards, Saludos



Falconi Silvio
Posts: 6983
Joined: Fri Oct 07, 2005 07:07 PM
Re: Sparklines in XBROWSE like Excel 2010
Posted: Mon Dec 07, 2009 08:23 PM

Silvio,
Why not. I didn’t thought of that.
How would you suggest to address tGraph from inside txbrowse?
Do you think speed would be ok?
Best regards,
Otto

Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Sparklines in XBROWSE like Excel 2010
Posted: Tue Dec 08, 2009 03:06 AM

TGraph is a control.
Mr Otto's approach is the best

Regards



G. N. Rao.

Hyderabad, India
Posts: 1088
Joined: Fri Oct 07, 2005 03:33 PM
Re: Sparklines in XBROWSE like Excel 2010
Posted: Tue Dec 08, 2009 03:35 AM

Hello,

first, Otto very good sample about the flexibilities of xBrowse, (Antonio) now about xBrowse in the sample
when we go to the last column (graph) we can see all cell, the cursor (black border) don't appears complete, the right side is missing
I think it is because the use of oBrw:nStretchCol := STRETCHCOL_LAST

I am using fwh9.06 maybe it was solved in newers version ?

Thanks for share your work

Regards

Marcelo

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Sparklines in XBROWSE like Excel 2010
Posted: Tue Dec 08, 2009 08:50 PM
Marcelo,

This is how it looks using FWH 9.12 xbrowse (not published yet). Please notice that I use gray color as the background color in my Windows settings:
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 1088
Joined: Fri Oct 07, 2005 03:33 PM
Re: Sparklines in XBROWSE like Excel 2010
Posted: Wed Dec 09, 2009 02:02 AM

Antonio,

thanks, I will try to update my version

regards

Marcelo

Posts: 3107
Joined: Fri Oct 07, 2005 06:28 PM
Re: Sparklines in XBROWSE like Excel 2010
Posted: Wed Dec 09, 2009 08:42 AM

Otto ,
yesterday I try to create on this also a draw axes y,x but I hace some problem
can send you the func ?

Best Regards, Saludos



Falconi Silvio
Posts: 6983
Joined: Fri Oct 07, 2005 07:07 PM
Re: Sparklines in XBROWSE like Excel 2010
Posted: Wed Dec 09, 2009 08:48 AM
Best regards,
Otto
Code (fw): Select all Collapse
      MoveTo( hDC, rctleft, rcttop )
      nWidth:=5
SelectObject( hDC , cPen )
      Ellipse( hDC, rctleft - 3, rcttop, rctleft + nWidth - 1, rcttop + nWidth - 1 )
SelectObject( hDC , cPenRed )
      if I < 13


Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: Sparklines in XBROWSE like Excel 2010
Posted: Fri Dec 11, 2009 05:16 PM

Very impressive work, Otto.

Regards,
James

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10

Continue the discussion