Page 1 of 1

is there a way to calculate this?

Posted: Mon Dec 19, 2005 10:23 pm
by 9338026
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

Posted: Tue Dec 20, 2005 11:19 am
by narcis
Hi Dave,

You may get that from axes IStartPos, IEndPos, PosAxis and IAxisSize properties and TChart margins (Chart1.MarginBottom, ...).

Posted: Tue Dec 20, 2005 8:27 pm
by 9338026
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;

Posted: Tue Dec 27, 2005 8:46 pm
by 9338026
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;

Posted: Wed Dec 28, 2005 8:30 am
by narcis
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.

How can we set AdjustMaxMinRect by EndPosition&StartPosi

Posted: Tue Dec 19, 2006 9:05 am
by 9336596
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.

Posted: Tue Dec 19, 2006 9:44 am
by narcis
Hi fnn,

It works fine here retrieving IAxisSize in the OnBeforeDrawAxes event. Have you tried using it?

AdjustMaxMinRect calculates IAxisSize

Posted: Tue Dec 19, 2006 1:45 pm
by 9336596
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!

Posted: Tue Dec 19, 2006 2:03 pm
by narcis
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?

how AxisSize is negative

Posted: Tue Dec 19, 2006 2:28 pm
by 9336596
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)

in axis.AdjustMaxMinRect(Arect):

Procedure RecalcAdjustedMinMax(Pos1,Pos2:Integer);
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