PDA

View Full Version : Statistical Graphics


Gautxo
05-16-2007, 09:28 AM
Here I leave you the code of a function that I have made to visualize statistical graphics.

The size of the same one is variable respect of the screen resolution.

The width of the bars varies regarding the I number of elements of the series.

I will wait that this finished the version 1.30 for test if goes well the event paint of the multi-form.

//--------------------------------------------------------------------------
/*
s_bar: Function that visualizes a graph of bars
Parámetros: hWnd$ - Window in which we will take out the information
serie$ - series of elements to visualize
*/
func s_bar(hWnd$,serie$)
// We calculate the width and high of the window.
Struct (r$, "Left", "Top", "Right", "Bottom");
GetWindowRect(hWnd$, &r$);
Ancho$ = r.right$ - r.left$;
Alto$ = r.bottom$ - r.top$;

// We catch the maximum value of the list
Max$ = 0;
ForEach(serie$)
if(serie$>Max$)
Max$ = serie$;
End;
End;
Tramo$ = Round(Max$/10);


G_Clear(G_RGB(252, 253, 196));
//We paint vertical and horizontal line
G_Line(40, Alto$-20, Ancho$-20, Alto$-20, G_RGB(124, 124, 124)); //horizontal
G_Line(40, Alto$-20, 40, Alto$-(Alto$-20), G_RGB(124, 124, 124)); //vertical
//We paint vertical separators
TamV$ = ((Alto$-20) - (Alto$-(Alto$-20)));
EspV$ = Round(TamV$/10);
ContPos$ = 0;
for (i$, Alto$-20-EspV$, Alto$-(Alto$-20), -EspV$)
ContPos$ = ContPos$ + 1;
G_Line(38, i$, 42, i$, G_RGB(85, 85, 85));

if(Max$<1000)
Valor$ = Round(Tramo$*ContPos$);
End;
if(Max$>1000 and Max$<100000)
Valor$ = Roundex((Tramo$*ContPos$)/1000,2);
End;

g_drawtext(SystemFont$, Valor$, 5, i$-5);
end;
if(Max$>1000 and Max$<100000)
g_drawtext(SystemFont$, "x1000", 1, 1);
End;
if(Max$>100000)
g_drawtext(SystemFont$, "x100000", 1, 1);
End;

miPos$ = 42;
nElem$ = count(serie$);
AnchoBar$ = ((Ancho$-40-20-2-((nElem$-1)*3))/nElem$);
ForEach(serie$)
G_FillRect(miPos$,Alto$-20-((serie$*TamV$)/Max$),miPos$+AnchoBar$,Alto$-20,G_RGB(255, 0, 0));
miPos$ = miPos$+AnchoBar$+3;
End;
end;

func Dibuja(hWnd$, Msg$, wParam$, lParam$)
case (Msg$)
WM_PAINT:
G_Clear(G_RGB(252, 253, 196));
List(serie$);
Add(serie$,1234,5643,467,892,1832);
s_bar(hWnd$,&serie$);

//WM_TIMER:
// if(KeysPressed$[keys.vkA$])
// PostMessage(FORM100$, WM_CLOSE, 0, 0);
// end;
end;
return(true);
end;
//------------------------------------------------------------------------