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?
TeeCreateBitmap and axis labels location
-
- Site Admin
- Posts: 14730
- Joined: Mon Jun 09, 2003 4:00 am
- Location: Banyoles, Catalonia
- Contact:
Hi Mercury,
It works fine here using the same version as you and the code below.
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.
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;
You should increase LabelsSize not setting it to zero, you could try with quite a big value.I tried settings LabelsSize to zero by code, but it didn't help.
Best Regards,
Narcís Calvet / Development & Support Steema Software Avinguda Montilivi 33, 17003 Girona, Catalonia Tel: 34 972 218 797 http://www.steema.com |
Instructions - How to post in this forum |
To reproduce the problem...
To reproduce the problem...
tmpChart.LeftAxis.Maximum := 5;
tmpChart.LeftAxis.Increment := 0.5;
tmpChart.LeftAxis.Maximum := 5;
tmpChart.LeftAxis.Increment := 0.5;
To reproduce the problem...
...And add values between 0 and 5.
-
- Site Admin
- Posts: 14730
- Joined: Mon Jun 09, 2003 4:00 am
- Location: Banyoles, Catalonia
- Contact:
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:
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 |
Instructions - How to post in this forum |
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;
...
//-------------------------------------------------------------
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;
...
//-------------------------------------------------------------