Hi Ed,
You could do something like this to calculate the Margins needed for the multiline labels in the bottom axis, and for the multiline marks in the series:
Code: Select all
procedure TForm1.RecalcMargins;
var i, maxHeight, tmpNum: Integer;
tmpSize: TPoint;
begin
chrtSavingsNeeded.Draw;
with chrtSavingsNeeded.Axes.Bottom do
if LabelsMultiLine then
begin
maxHeight:=0;
for i:=0 to Pred(Items.Count) do
begin
tmpSize:=chrtSavingsNeeded.MultiLineTextSize(Items[i].Text, Items[i].Format.TextFormat, tmpNum);
maxHeight:=Max(maxHeight, tmpSize.Y);
end;
chrtSavingsNeeded.MarginUnits:=muPixels;
chrtSavingsNeeded.MarginBottom:=maxHeight;
end
else
begin
chrtSavingsNeeded.MarginUnits:=muPercent;
chrtSavingsNeeded.MarginBottom:=4;
end;
chrtSavingsNeeded.Draw;
if Series1.Count>0 then
begin
maxHeight:=Series1.Marks.Positions[0].LeftTop.Y;
for i:=1 to Pred(Series1.Count) do
maxHeight:=Min(maxHeight, Series1.Marks.Positions[i].LeftTop.Y);
chrtSavingsNeeded.MarginUnits:=muPixels;
chrtSavingsNeeded.MarginTop:=(chrtSavingsNeeded.ChartRect.Top-maxHeight);
end
else
begin
chrtSavingsNeeded.MarginUnits:=muPercent;
chrtSavingsNeeded.MarginTop:=8;
end;
end;
You could call this method in each button, after adding the values in the series.
However, the margins needed for the images are different. To fix this, you could create a temporal chart with the final size, calculate the margins for it as above, and export this temporal chart.