|
I found a problem when I used this control in a small window: The plot was wrong
suppose the following:
SetBarValue(0,10);
SetBarValue(1,100);
SetBarValue(0,30);
if the window height is smaller than bar[1]*unit then the graph output is wrong with bar[1] smaller than bar[0] and bar[2]
This is a scale problem and I corrected using the following code: (notice ++KM)
BOOL CGraphCtrl::OnEraseBkgnd(CDC* pDC)
{
int *BAR=new int[NumOfBars]; //++KM
float scale=1.0; //++KM
int i,max=0; //++KM
CRect rc;
GetClientRect (rc);
BGC = RGB(224,231,240);
int Width = rc.Width();
int Height= rc.Height();
int bx=0, by=0;
//find max value //++KM
for(i=0;i<(int)NumOfBars;i++) //++KM
max=(bar[i]>max)?bar[i]:max; //++KM
if(max>Height-offset-7) //++KM
{ //++KM
scale=(float)((float)(Height-offset-7)/(float)max); //++KM
} //++KM
for(i=0;i<(int)NumOfBars;i++) //++KM
{ //++KM
BAR[i] = (int)((float)(bar[i])*scale); //++KM
} //++KM
// KillTimer(1);
pDC->FillSolidRect(0,0,Width,Height,BGC);
pDC->FillSolidRect(offset-2,0,2,Height-(offset-2),RGB(0,0,0,));
pDC->FillSolidRect(offset,Height-offset,Width-offset,2,RGB(0,0,0,));
for(i=1;i<=(Height-offset)/(unit/2);i++)
{
if(i%2 != 0)
{
pDC->MoveTo(offset-2,(Height-offset) - i*(unit/2));
pDC->LineTo(offset-6,(Height-offset) - i*(unit/2));
}
else
{
pDC->MoveTo(offset-2,(Height-offset) - i*(unit/2));
pDC->LineTo(offset-10,(Height-offset) - i*(unit/2));
}
}
for(i=0;i<(int)NumOfBars;i++)
{
bx = ((Width-offset)/NumOfBars)*i+offset;
pDC->FillSolidRect(bx, Height-BAR[i]-offset,(Width-offset)/NumOfBars,BAR[i],BC[i]); //++KM
pDC->Draw3dRect(bx, Height-BAR[i]-offset,(Width-offset)/NumOfBars,BAR[i],RGB(255,255,255),BC[i]); //++KM
}
delete BAR; //++KM
return CStatic::OnEraseBkgnd(pDC);
}
(there is another problem with the original code: It changes the values of original data: bar[i])
|
|
|
|
|
thanx. u did solve my problem
u got my 5
|
|
|
|