TeeCreateBitmap and axis labels location

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
Mercury
Newbie
Newbie
Posts: 7
Joined: Wed Jul 11, 2001 4:00 am

TeeCreateBitmap and axis labels location

Post by Mercury » Wed Jun 29, 2005 1:47 pm

I'm using TeeChart5.02 VCL.
When I save the chart to bitmap using TeeCreateBitmap, The left axis title overwrites its labels. I tried settings LabelsSize to zero by code, but it didn't help.
Remarks:
* The graph is not visible to the user. It is created, edited using code, and then saved to bmp file.
* I saved the chart to *.tee file and there it looked ok.

Can you help?

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 29, 2005 2:39 pm

Hi Mercury,

It works fine here using the same version as you and the code below.

Code: Select all

procedure TForm1.FormCreate(Sender: TObject);
var
  tmpBmp: TBitMap;
  tmpAreaSeries:TAreaSeries;
  tmpChart: TChart;
  i: Integer;
begin
  tmpChart:=TChart.Create(self);

  tmpAreaSeries:=TAreaSeries.Create(self);
  With tmpAreaSeries do
  begin
    ParentChart:=tmpChart;
    Randomize;
    for i:=0 to 100 do tmpAreaSeries.Add(random(100000000));
  end;

  tmpChart.LeftAxis.Title.Caption:='MyTitle';

  tmpBmp:=tmpChart.TeeCreateBitmap(clWhite,Rect(0,0,tmpChart.Width,tmpChart.Height));
  try
    tmpBmp.SaveToFile('C:\Temp\chart1.bmp');
  finally
    tmpBmp.Free;
  end;
end;
Could you please send us an example we can run "as-is" or modify the code so that we can reproduce the problem here? You can post your files at [url]news://www.steema.net/steema.public.attachments[/url] newsgroup.
I tried settings LabelsSize to zero by code, but it didn't help.
You should increase LabelsSize not setting it to zero, you could try with quite a big value.
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

Mercury
Newbie
Newbie
Posts: 7
Joined: Wed Jul 11, 2001 4:00 am

To reproduce the problem...

Post by Mercury » Thu Jun 30, 2005 12:42 pm

To reproduce the problem...
tmpChart.LeftAxis.Maximum := 5;
tmpChart.LeftAxis.Increment := 0.5;

Mercury
Newbie
Newbie
Posts: 7
Joined: Wed Jul 11, 2001 4:00 am

To reproduce the problem...

Post by Mercury » Thu Jun 30, 2005 12:47 pm

...And add values between 0 and 5.

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

Post by Narcís » Thu Jun 30, 2005 2:54 pm

Hi Mercury,

I've been able to reproduce the problem here. I have been able to overcome it using LabelsSize so the working code would be:

Code: Select all

procedure TForm1.FormCreate(Sender: TObject);
var
  tmpBmp: TBitMap;
  tmpAreaSeries:TAreaSeries;
  tmpChart: TChart;
  i: Integer;
begin
  tmpChart:=TChart.Create(self);

  tmpAreaSeries:=TAreaSeries.Create(self);
  With tmpAreaSeries do
  begin
    ParentChart:=tmpChart;
    Randomize;
    for i:=0 to 100 do tmpAreaSeries.Add(random(5));
  end;

  With tmpChart.LeftAxis do
  begin
    Title.Caption:='MyTitle';
    Maximum := 5;
    Increment := 0.5;
    LabelsSize:=20;
  end;

  tmpBmp:=tmpChart.TeeCreateBitmap(clWhite,Rect(0,0,tmpChart.Width,tmpChart.Height));
  try
    tmpBmp.SaveToFile('C:\Temp\chart1.bmp');
  finally
    tmpBmp.Free;
  end;
end;
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

Mercury
Newbie
Newbie
Posts: 7
Joined: Wed Jul 11, 2001 4:00 am

Post by Mercury » Wed Jul 06, 2005 6:00 pm

We don't want to use LabelsSize other than zero because then we need to calculate the exact size of the text that will be displayed on the axis in order to avoid overwriting it and do it everytime the graph will be resized.
Anyway I found one way that works by using powers of ten:
//-------------------------------------------------------------
procedure FillNiceNumbersArray;
const
MIN_NICE_NUMBER = 0.001;
MAX_NICE_NUMBER = 1000000000;
var
i: Integer;
nVal: Double;
begin
//fill an array with 0.001, 0.01, 0.1, 1, 10, 100, 1000, ...
G_NiceNumbersArray := nil;
nVal := MIN_NICE_NUMBER;
repeat
SetLength(G_NiceNumbersArray, Length(G_NiceNumbersArray)+1);
G_NiceNumbersArray[Length(G_NiceNumbersArray)-1] := nVal;
nVal := nVal * 10;
until nVal > MAX_NICE_NUMBER;
end;
//-------------------------------------------------------------
function GetNiceMaxAxisVal(nVal: Double): Double;
var
i :integer;
begin
Result := nVal;
try
for i := Low(G_NiceNumbersArray) to High(G_NiceNumbersArray) do
begin
Result := G_NiceNumbersArray;
if (nVal < G_NiceNumbersArray) then
BREAK;
end;
except
end;
end;
//-------------------------------------------------------------
...
m_GraphChart.LeftAxis.Automatic := False;
m_GraphChart.LeftAxis.AutomaticMinimum := False;
m_GraphChart.LeftAxis.AutomaticMaximum := False;
m_GraphChart.LeftAxis.Minimum := 0;
if bUserWantedASpecificMaxYaxisValue then
begin
m_GraphChart.LeftAxis.Maximum := WantedYaxisValue;
m_GraphChart.LeftAxis.Increment := GetScale(WantedYaxisValue) / 10;
end
else
begin
fMax := 0;
for j := 0 to (m_GraphChart.SeriesCount - 1) do
begin
fMax := Max(fMax, m_GraphChart.Series[j].YValues.MaxValue);
end;
if fMax > 0 then
begin
m_GraphChart.LeftAxis.Maximum := GetNiceMaxAxisVal(fMax);
m_GraphChart.LeftAxis.Increment := m_GraphChart.LeftAxis.Maximum / 10;
end;
end;
...
//-------------------------------------------------------------

Mercury
Newbie
Newbie
Posts: 7
Joined: Wed Jul 11, 2001 4:00 am

Post by Mercury » Wed Jul 06, 2005 6:38 pm

One mistake on the code...
GetScale(WantedYaxisValue) / 10;
should be replaced with
GetNiceMaxAxisVal(WantedYaxisValue) / 10;

Post Reply