Page 1 of 1

The Resize problem - the Axis labels overlapped by chart

Posted: Wed Dec 06, 2006 10:31 am
by 9343348
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

Posted: Fri Dec 08, 2006 12:06 pm
by Pep
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;

Posted: Wed Dec 13, 2006 8:00 am
by 9343348
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.

Posted: Mon Dec 18, 2006 3:47 pm
by Pep
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..