Page 1 of 1

Calculating space for axis

Posted: Wed Jun 27, 2007 6:39 am
by 9348284
Hi

I have an app where multiple lineseries are shown in one chart. Each series have their own vertical axis.
Normal view on screen only shows one vertical axis at a time, and the user can toggle through the axises (is that the right plural form of axis?) by clicking the vertical axis. So far everything is fine. :)

For special purposes such as printing, I am trying to decrease the actual chart area to make room for all the vertical axis's (whatever) side by side, but depending on the AxisValuesFormat and the actual value the axis needs more or less space.
How do I calculate this :?:

If I haven't made myself clear, I'd be happy to apply sample code.

TIA

Søren

Posted: Wed Jun 27, 2007 7:46 am
by narcis
Hi TheRoadrunner,

My colleague Yeray made some similar examples for other customers at the forums threads below:

http://www.teechart.net/support/viewtopic.php?t=6146
http://www.teechart.net/support/viewtopic.php?t=5923

Hope this helps!

Thank you

Posted: Wed Jun 27, 2007 9:16 am
by 9348284
Hi Narcís

Thank you for your fast and excellent support.
The key to my solution was the article:

http://www.teechart.net/support/viewtopic.php?t=5923

Especially the PlaceAxes procedure was useful.

Since my App hasn't got a linear relation between series and CustomAxes, and since I don't quite get the point of having two constants (you have to tune them in parallel anyway), I made a few improvements.
Here is my version (in case anyone is interested):

Code: Select all

procedure TfrmGraph.PlaceAxes(nSeries: Integer=0; NextXLeft: Integer=0; NextXRight: Integer=0; MargLeft: Integer=0; MargRight: Integer=0);
const
  extraPos = 18;
  minMarginLeft = 15;
  minMarginRight = 15;
var
  ca : TChartAxis;
begin
  ca := Chart.Series[nSeries].GetVertAxis;
  if Chart[nSeries].Active and Assigned(ca) and ca.Visible then
  begin
    if ca.OtherSide then
    begin
      ca.PositionPercent := NextXRight;
      NextXRight := NextXRight - ca.MaxLabelsWidth - ca.TickLength - extraPos;
      MargRight := MargRight + ca.MaxLabelsWidth + ca.TickLength + extraPos;
    end
    else
    begin
      ca.PositionPercent := NextXLeft;
      NextXLeft := NextXLeft - ca.MaxLabelsWidth - ca.TickLength - extraPos;
      MargLeft := MargLeft + ca.MaxLabelsWidth + ca.TickLength + extraPos;
    end;
  end;

  Chart.MarginLeft := Max(minMarginLeft,MargLeft);
  Chart.MarginRight := Max(minMarginRight, MargRight);

  nSeries := nSeries + 1;

  if nSeries <= Chart.SeriesCount - 1 then
  begin
    PlaceAxes(nSeries, NextXLeft, NextXRight, MargLeft, MargRight);
  end;
end;

Posted: Wed Jun 27, 2007 9:26 am
by 9349911
Hi TheRoadrunner,
Here is my version (in case anyone is interested):
Because this is exact the function I got from the support I´m very interested :D

Code: Select all

Chart.MarginLeft := Max(minMarginLeft,MargLeft); 
  Chart.MarginRight := Max(minMarginRight, MargRight); 
Could you please tell me what MAX() is about? Is it a Delphi function or a special function from you?

If you are interested I can send you my demo application which has some additional features.

Posted: Wed Jun 27, 2007 9:34 am
by 9348284
Hi Moelski

Max is a standard Delphi function (Math unit).
I used it to make sure my margins don't hit zero (when all axes are on one side).

HTH

Søren

Posted: Wed Jun 27, 2007 9:44 am
by 9349911
Works great !

thx !