Page 1 of 1

How to limit the scroll to a range [0,MAX] ?

Posted: Tue Feb 08, 2005 8:38 pm
by 9340780
Hi,

How to limit the scroll to a range [0,MAX] ?

Here is a code :

Code: Select all

 if(Chart1->BottomAxis->Minimum < 0)
      Chart1->BottomAxis->SetMinMax(0, Chart1->BottomAxis->Maximum);

   if(Chart1->BottomAxis->Maximum > 500)
      Chart1->BottomAxis->SetMinMax(Chart1->BottomAxis->Minimum, 500);
it gives a cool effect but not that I've expected ! It limits the range to 0,500 but it stretch the graphic :?

Thank you in advance for your help !
Cordially,
Rodrigue

Posted: Wed Feb 09, 2005 7:22 am
by Marjan
The following code will limit axis minimum to 0 and axis maximum to 500:

Code: Select all

void __fastcall LimitAxisRange(TChartAxis *axis, double amin, double amax)
{
  axis->Minimum = Math::Max(axis->Minimum,amin);
  axis->Maximum = Math::Min(axis->Maximum,amax);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Chart1BeforeDrawAxes(TObject *Sender)
{
  LimitAxisRange(Chart1->BottomAxis,0.0,500);
}
In case you don't want stretched image, you'll have to define the offset and add/subtract it to/from axis minimum/maximum when amin or amax value is reached.

Posted: Wed Feb 09, 2005 12:06 pm
by 9340780
Hi,

Thanks for your reply ! I use C++ Builder 6. I don't know :

Code: Select all

Math::Max
Math::Min
I must include a file ?

Cordially,
Rodrigue

Posted: Wed Feb 09, 2005 4:00 pm
by Marjan
Hi.

Yes, Math.hpp

Code: Select all

...
#include <Math.hpp>

Posted: Wed Feb 09, 2005 4:18 pm
by 9340780
Sorry,

I've included <math.h> or <Math> but not <Math.hpp> :?

I test your code but my data are always streched ... maybe it's because I put an offset of 5 pixels on my bottom axe ?

Cordially,
Rodrigue

Posted: Fri Feb 11, 2005 10:46 am
by Marjan
Hi.

Not really, axis scales are adjusted exactly as coded (following boolean evaluators I used). If you want different behavior, you'll have to define axis minimum or maximum value as Minimum = Maximum-YourManuallyDefinedOffset OR Maximum = Minimum + YourManuallyDefinedOffset. This way you can ensure chart range will not be "stretched" as it will always show [Minimum, Minimum + offset] or [maximum-offset,maximum] range.