The Resize problem - the Axis labels overlapped by chart

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
Zbyněk Dolejšek
Newbie
Newbie
Posts: 2
Joined: Tue Sep 20, 2005 4:00 am

The Resize problem - the Axis labels overlapped by chart

Post by Zbyněk Dolejšek » Wed Dec 06, 2006 10:31 am

If I decrease the height of the form

Image
Figure 1. (initial state)



the height of the chart decreases correspondingly up to the moment when the chart is 1 point high (Chart.ChartHeight = 1)

Image
Figure 2. (the minimum height of the form with correctly displayed labels)


and any further decrease of the height of the form produces situation when the labels on the X Axis are overlapped by the chart (one highlighted by the red frame)

Image
Figure 3. (further decreased height - labels overlapping with the chart)



which does not look nice.

We have several questions:
Is it possible to prevent this behavior? For example, in the API, are there any constraints or a function to find out the minimal rectangle neccessary for correct display of the labels (i.e. not overlapped)?
Or is there a flag that suppresses this behavior?

Thanks

Pep
Site Admin
Site Admin
Posts: 3295
Joined: Fri Nov 14, 2003 5:00 am
Contact:

Post by Pep » Fri Dec 08, 2006 12:06 pm

Hi,

you can solve it by using similar code to the following :

Code: Select all

procedure TForm1.Chart1Resize(Sender: TObject);
begin
if Chart1.Height < (Chart1.Title.Height+Chart1.Axes.bottom.MaxLabelsWidth+Chart1.axes.bottom.TickLength+
   Chart1.MarginBottom+Chart1.MarginTop+20+(Chart1.ChartRect.Bottom-chart1.ChartRect.Top)) then
  chart1.Axes.Bottom.Visible:=false
else
  chart1.Axes.Bottom.Visible:=true;
end;

Zbyněk Dolejšek
Newbie
Newbie
Posts: 2
Joined: Tue Sep 20, 2005 4:00 am

Post by Zbyněk Dolejšek » Wed Dec 13, 2006 8:00 am

Hi,
thanks for the reply, your solution works fine. But I doubt that it will work also for other chart types and other settings.
What we need is a general solution how to calculate the minimal size (which ensures the correct display of all labels) for many chart types (f.e. bar, stacked bar, line, area, pie, ...) and many possibilities of chart customization.
Could you give us some insights how to implement such function?
Thanks.

Pep
Site Admin
Site Admin
Posts: 3295
Joined: Fri Nov 14, 2003 5:00 am
Contact:

Post by Pep » Mon Dec 18, 2006 3:47 pm

Hi,

I think it should work for all the Chart types, as you only are calculating the height of the bottom axis (including labels).
Another way is to calculate the text size using :
chart1.Canvas.TextWidth('text');
but you will have to sum also the axis size, bottom margin, etc..

Post Reply