Page 1 of 1
Axis Minimum / Maximum
Posted: Fri Nov 12, 2010 9:49 am
by 10548232
Hallo,
I use TChar VCL V. 8.04.11395 Win95.
In my code I want to change axis minimum and maximum. But first I want to read the axis maximum.
If I use
Chart1.BottomAxis.Maximum
or
Chart1.Axis.Bottom.Maximum ,
I get allways 0. How can I get the maximum of axis?
Best regards
Roland
Re: Axis Minimum / Maximum
Posted: Fri Nov 12, 2010 10:09 am
by narcis
Hi Geosucher,
I use TChar VCL V. 8.04.11395 Win95.
First of all please notice latest v8 release available at the client area is v8.07. BTW: Win95 really
!?!? This is a piece of computer archaeology those days
.
I get allways 0. How can I get the maximum of axis?
This is most likely because your chart hasn't been painted and therefore those properties haven't been calculated yet. To force the chart being internally painted to have valid values for those properties try calling
Chart1.Draw() before retrieving axes min./max.
Re: Axis Minimum / Maximum
Posted: Fri Nov 12, 2010 10:27 am
by 10548232
Hi Narcis,
sorry you are right. Archeology is very interesting, but I don't use Windows 95. it should be Win32.
Here is the part of m code:
Code: Select all
Series1.Clear;
Series2.Clear;
if CntSPS_S>0 then
begin
for i := 0 to CntSPS_S - 1 do
Series1.AddXY(SPS_S[i].Easting,SPS_S[i].Northing);
end;
if CntSPS_R>0 then
begin
for i := 0 to CntSPS_R - 1 do
Series2.AddXY(SPS_R[i].Easting,SPS_R[i].Northing);
end;
Chart1.Draw;
maxX:=Chart1.BottomAxis.Maximum;
minX:=Chart1.BottomAxis.Minimum;
maxY:=Chart1.LeftAxis.Maximum;
minY:=Chart1.LeftAxis.Minimum;
if (Chart1.ChartHeight>0) and (Chart1.ChartWidth>0) then
begin
XRange:=maxx-minx;
tmpX:=XRange/Chart1.ChartWidth;
XYScreen:=(GetDeviceCaps(Canvas.Handle,HORZSIZE)/Screen.Width)/(GetDeviceCaps(Canvas.Handle,VERTSIZE)/Screen.Height);
YRange:=maxy-miny;
tmpY:=YRange*XYScreen/Chart1.ChartHeight;
if tmpX>tmpY then
begin
if tmpY<>0 then
begin
Offset:=((YRange*tmpX/tmpY)-YRange)/2.0;
CHart1.Axes.Left.Automatic:=false;
Chart1.Axes.Left.SetMinMax(Chart1.Axes.Left.Minimum-Offset,Chart1.Axes.Left.Maximum+Offset);
end;
end
else if tmpX<tmpY then
begin
if tmpX<>0 then
begin
Offset:=((XRange*tmpY/tmpX)-XRange)/2.0;
Chart1.Axes.Bottom.SetMinMax(Chart1.Axes.Bottom.Minimum-Offset,Chart1.Axes.Bottom.Maximum+Offset);
end;
end;
mi:=Max(Chart1.Axes.Bottom.Increment,Chart1.Axes.Left.Increment);
Chart1.Axes.Bottom.Increment:=mi;
Chart1.Axes.Left.Increment:=mi;
end;
The values of minX,maxX,minY and MaxY have all the value zero.
Best regards
Roland
Re: Axis Minimum / Maximum
Posted: Fri Nov 12, 2010 10:48 am
by narcis
Hi Roland,
Thanks for the information. Code below does what you request here. Does it work fine at your end? If the problem persists can you please attach a simple example project we can run "as-is" to reproduce the problem here?
Code: Select all
uses Series;
procedure TForm1.FormCreate(Sender: TObject);
var i: Integer;
begin
for i:=0 to 2 do
begin
Chart1.AddSeries(TLineSeries.Create(Self));
Chart1[i].FillSampleValues;
end;
Chart1.Draw;
With Chart1.Axes, Chart1.Title.Text do
begin
Clear;
Add('MinX = ' + FloatToStr(Bottom.Minimum));
Add('MaxX = ' + FloatToStr(Bottom.Maximum));
Add('MinY = ' + FloatToStr(Left.Minimum));
Add('MaxY = ' + FloatToStr(Left.Maximum));
end;
end;
Thanks in advance.
Re: Axis Minimum / Maximum
Posted: Fri Nov 12, 2010 11:40 am
by 10548232
Hi Narcis,
sorry I found a big mistake in my code: I use two charts and that chart I wnat to change was Chart2. Now the code is right.
What a stupid error.
Best regards
Roland
Re: Axis Minimum / Maximum
Posted: Fri Nov 12, 2010 11:48 am
by narcis
Hi Roland,
Ok, no problem. I'm glad to hear you found the solution to your problem.