Calculating space for axis

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
TheRoadrunner
Newbie
Newbie
Posts: 17
Joined: Thu Dec 07, 2006 12:00 am
Location: Sønderborg, Denmark

Calculating space for axis

Post by TheRoadrunner » Wed Jun 27, 2007 6:39 am

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

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

Post by Narcís » Wed Jun 27, 2007 7:46 am

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!
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

TheRoadrunner
Newbie
Newbie
Posts: 17
Joined: Thu Dec 07, 2006 12:00 am
Location: Sønderborg, Denmark

Thank you

Post by TheRoadrunner » Wed Jun 27, 2007 9:16 am

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;

moelski
Advanced
Posts: 212
Joined: Mon Apr 23, 2007 12:00 am
Location: Germany
Contact:

Post by moelski » Wed Jun 27, 2007 9:26 am

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.

TheRoadrunner
Newbie
Newbie
Posts: 17
Joined: Thu Dec 07, 2006 12:00 am
Location: Sønderborg, Denmark

Post by TheRoadrunner » Wed Jun 27, 2007 9:34 am

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

moelski
Advanced
Posts: 212
Joined: Mon Apr 23, 2007 12:00 am
Location: Germany
Contact:

Post by moelski » Wed Jun 27, 2007 9:44 am

Works great !

thx !

Post Reply