Page 1 of 1

Sparklines in XBROWSE like Excel 2010

PostPosted: Mon Dec 07, 2009 1:55 am
by Otto
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:

Image

Best regards,
Otto

Image

Image

Re: Sparklines in XBROWSE like Excel 2010

PostPosted: Mon Dec 07, 2009 2:46 am
by nageswaragunupudi
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.

Re: Sparklines in XBROWSE like Excel 2010

PostPosted: Mon Dec 07, 2009 11:01 am
by Otto
Best regards,
Otto

Code: Select all  Expand view


#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
*----------------------------------------------------------


 

Re: Sparklines in XBROWSE like Excel 2010

PostPosted: Mon Dec 07, 2009 11:18 am
by Silvio
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

Re: Sparklines in XBROWSE like Excel 2010

PostPosted: Mon Dec 07, 2009 12:05 pm
by Otto
Silvio,

nZeile = nRowheight

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

Re: Sparklines in XBROWSE like Excel 2010

PostPosted: Mon Dec 07, 2009 7:35 pm
by Silvio
Otto why not use tgraph class ?

Re: Sparklines in XBROWSE like Excel 2010

PostPosted: Mon Dec 07, 2009 8:23 pm
by Otto
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

Re: Sparklines in XBROWSE like Excel 2010

PostPosted: Tue Dec 08, 2009 3:06 am
by nageswaragunupudi
TGraph is a control.
Mr Otto's approach is the best

Re: Sparklines in XBROWSE like Excel 2010

PostPosted: Tue Dec 08, 2009 3:35 am
by Marcelo Via Giglio
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

Re: Sparklines in XBROWSE like Excel 2010

PostPosted: Tue Dec 08, 2009 8:50 pm
by Antonio Linares
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:
Image

Re: Sparklines in XBROWSE like Excel 2010

PostPosted: Wed Dec 09, 2009 2:02 am
by Marcelo Via Giglio
Antonio,

thanks, I will try to update my version

regards

Marcelo

Re: Sparklines in XBROWSE like Excel 2010

PostPosted: Wed Dec 09, 2009 8:42 am
by Silvio
Otto ,
yesterday I try to create on this also a draw axes y,x but I hace some problem
can send you the func ?

Re: Sparklines in XBROWSE like Excel 2010

PostPosted: Wed Dec 09, 2009 8:48 am
by Otto
Best regards,
Otto
Code: Select all  Expand view

      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


 


Image

Re: Sparklines in XBROWSE like Excel 2010

PostPosted: Fri Dec 11, 2009 5:16 pm
by James Bott
Very impressive work, Otto.

Regards,
James