## is there a way to calculate this?

David Novo
Newbie
Posts: 71
Joined: Fri Jul 02, 2004 4:00 am
Location: Culver City
Contact:

### is there a way to calculate this?

Is there any function I can call to say:

Give me the Chart BoundsRect I need so that the axis lengths will be a certain value. That way I would be able to set the bounds so that my x and y axis will be a specified size.

Alternatively, is there a function that returns:
Given a specific bounds rect, this is what the chartRect will be....

Thanks,
Dave

Narcís
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:
Hi Dave,

You may get that from axes IStartPos, IEndPos, PosAxis and IAxisSize properties and TChart margins (Chart1.MarginBottom, ...).
Best Regards,
 Narcís Calvet / Development & Support Steema Software Avinguda Montilivi 33, 17003 Girona, Catalonia Tel: 34 972 218 797 http://www.steema.com Instructions - How to post in this forum

David Novo
Newbie
Posts: 71
Joined: Fri Jul 02, 2004 4:00 am
Location: Culver City
Contact:
Hi Narcis,

Is there any explanation of IStartPos, IEndPos etc. I cannot find it in the help.

If there is no help, it would be great if you could you post sample code for the following two functions

function getChartRectForBoundsRect(const bRect:TRect):TRect;
begin
// assuming the tchart boundsRect=bRect, result:= the size of the chartrect
end;

function getBoundsRectForChartRect(const cRrect:tREct):tRect
begin
result:= the size of the tchart bounds, such that chart rect for the chart will be equal to cRect
end;

David Novo
Newbie
Posts: 71
Joined: Fri Jul 02, 2004 4:00 am
Location: Culver City
Contact:
Hi Narcis,

I am trying to figure this out on my own, but I am confused how to apply what you said.

All of those variables (IStartPos, iEndPos) change only after the chart has been drawn. I do not want to have to change the chart to figure out what the chartRect is, that defeats the purpose. I want to be able to determine what the chart rect WILL BE IF I adjust the chart to the specified rectangle.

I have even tried to make a temporary chart, assign my original chart to the temporary one, but I cannot force it to recalculate the chartrect unless I make a bitmap.

This is the best code I have come up with, please let me know if there is a better way.....

unction calculateChartRectForBounds(theChart:tchart;newBounds:tRect):trect;
var
tmp: tchart;
bmp:tbitmap;
begin
tmp:=tchart.create(nil);

try
tmp.assign(theChart);
tmp.FreeAllSeries;
tmp.boundsRect:=newBounds;
bmp:=tmp.teecreateBitmap(clNone,tmp.boundsRect);
result:=tmp.chartRect;
finally
bmp.free;
tmp.free;
end;
end;

Narcís
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:
Hi David,

I'd try forcing the chart to be drawn by calling Chart1.Draw before doing the calculations so that chart axes properties will be initialized.
Best Regards,
 Narcís Calvet / Development & Support Steema Software Avinguda Montilivi 33, 17003 Girona, Catalonia Tel: 34 972 218 797 http://www.steema.com Instructions - How to post in this forum

fnn
Newbie
Posts: 5
Joined: Tue Mar 23, 2004 5:00 am

### How can we set AdjustMaxMinRect by EndPosition&StartPosi

I need to calculate IAxisSize for some calculations for drawing. But, I need to before draw. Also, I dont want to paint chart for twice, since program slows down.

For AdjustMaxMinRect, if we supply a rect calculated by EndPosition&StartPosition properties, then we have a non zero IAxisSize.

Narcís
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:
Hi fnn,

It works fine here retrieving IAxisSize in the OnBeforeDrawAxes event. Have you tried using it?
Best Regards,
 Narcís Calvet / Development & Support Steema Software Avinguda Montilivi 33, 17003 Girona, Catalonia Tel: 34 972 218 797 http://www.steema.com Instructions - How to post in this forum

fnn
Newbie
Posts: 5
Joined: Tue Mar 23, 2004 5:00 am

I use a simple method:

Chart.Autorepaint:=false;
....
set chart operations
.....
Chart.Autorepaint:=true;
Chart.Repaint;

I need to set IAxisSize on loading, because I use some functions and properties:
axis.CalcPosValue, axis.increment, axis.setminmax.
if IAxisSize =0 then CalcPosValue is always zero.
if IAxisSize =0 then axis.increment could not be calculated.
axis.AdjustMaxMinRect calculate IAxisSize but, I tied to use for chart.bottomaxis, but IAxisSize was calculated as negative value. I think IAxisSize should not be negative!

Narcís
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:
Hi fnn,

IAxisSize and similar properties can't have valid values until the chart is drawn. When did you exactly got negative values for it?
Best Regards,
 Narcís Calvet / Development & Support Steema Software Avinguda Montilivi 33, 17003 Girona, Catalonia Tel: 34 972 218 797 http://www.steema.com Instructions - How to post in this forum

fnn
Newbie
Posts: 5
Joined: Tue Mar 23, 2004 5:00 am

### how AxisSize is negative

on create form

chart. RecalcWidthHeight;//initialize cahrt bounds.

chart.autorepaint:=false;//no auoto

everything is zero: IStartPos, IEndPos,IAxisSize. becasuse no painting occurs

for a Horizontal axis:
Arect:=chart.BoundsRect;//i.e: arect=(0,0,500,500)

Var OldStart : Integer;
OldEnd : Integer;
Begin
OldStart :=IStartPos;
OldEnd :=IEndPos;
Inc(IStartPos,Pos1);
Dec(IEndPos,Pos2);//negative. IEndPos is zero
IAxisSize:=IEndPos-IStartPos;
tmpMin:=CalcPosPoint(OldStart);
tmpMax:=CalcPosPoint(OldEnd);
end;

IAxisSize is calculated on TChartAxis.InternalCalcPositions.
But, IAxisSize is recalculated in RecalcAdjustedMinMax.
this casues calculation of IAxisSize, while IStartPos and IEndPos are not calculated