Page 1 of 1

save scaled chart as bitmap

Posted: Fri Apr 24, 2009 12:42 pm
by 10548232
I have to save a scaled chart in a bitmap, that means I computed the size of the bitmap, the length of axes and the start position of axis in pixel.
I try to change the chart with Chart1.Width, Chart1.Height, Chart1.LeftAxis.IStartPos, Chart1.BottomAxis.IStartPos, Chart1.LeftAxis.IAxisSize and Chart1.BottomAxis.IAxisSize. If I look on my bitmap, the bitmap size is correct, but the axes length is not correct.
What can I do?

Best regards

Roland

Posted: Fri Apr 24, 2009 1:29 pm
by 10548232
Sorry, I forgot:

I work with Delphi 7 and TeeChart 8.04 VCL.

I try to change the Chart with this code:

Chart1.Height:=iLeft+iBreit+iRight;
Chart1.Width:=iTop+iLang+iBottom;
Chart1.MarginUnits:=muPixels;
Chart1.MarginLeft:=iTop;
Chart1.MarginBottom:=iLeft;
Chart1.MarginRight:=iBottom;
Chart1.MarginTop:=iRight;
Chart1.LeftAxis.IAxisSize:=iBreit;
Chart1.BottomAxis.IAxisSize:=iLang;

Posted: Fri Apr 24, 2009 2:57 pm
by yeray
Hi Roland,

If we understand well what you are trying to do, why don't you do like this?

Code: Select all

Chart1.CustomChartRect := true;
Chart1.ChartRect := Rect(50,50,Chart1.Width-100,Chart1.Height-100);
Then save your chart to a bitmap:

Code: Select all

Chart1.SaveToBitmapFile(filename,Chart1.ChartRect);
If that's not what you want, please, try to explain what are you exactly trying to achieve.

Posted: Mon Apr 27, 2009 1:58 pm
by 10548232
In my software I compute the size of horizontal and vertical axis in pixel. Now I want to create a bitmap of the chart
with the exact length of axes in pixel.

Example:

Code: Select all

  iLeft:=90;
   iTop:=100;
   iWidth:=830;                   {length of horizontal axis in pixel}
   iRight:=110;
   iBottom:=120;
   iHeight:=1340;
   iWidth:=830;                    {length of vertical axis in pixel}                    
   iRight:=60;
   iBottom:=60;
   iHeight:=1340;                     
   Chart1.Width:=iLeft+iWidth+iRight;
   Chart1.Height:=iTop+iHeight+iBottom;
   Chart1.LeftAxis.IAxisSize:=iHeight;
   Chart1.BottomAxis.IAxisSize:=iWidth;
   Chart1.SaveToBitmapFile(SavePictureDialog1.Filename);
   
The resulting bitmap has the correct size (1030 x 1560 Pixel).
The horizontal axis begins at pixel 63 and stops at pixel 1000 (length 937 pixel - not 830).
The vertical axis begins at pixel 83 and end at pixel 1497 (lenght 1414 pixel - not 1340).

Thanks!

Roland

Posted: Mon Apr 27, 2009 3:05 pm
by yeray
Hi Roland,

I'm not sure to understand what are you exactly trying to do. You are setting iWidth, iRight, iBottom and iHeight and you are resetting them before using. And with this code, I get an image with different size and different chart size than what you say.

Here is how I would do to obtain the image you seem to wish:

Code: Select all

procedure TForm1.FormCreate(Sender: TObject);
var imageWidth, imageHeight, ChartWidth, ChartHeight: Integer;
begin
  imageWidth := 1030;
  imageHeight := 1560;

  ChartWidth := 830;
  ChartHeight := 1340;

  Chart1.Width:=imageWidth;
  Chart1.Height:=imageHeight;

  Chart1.CustomChartRect := true;
  Chart1.ChartRect := Rect((imageWidth-ChartWidth) div 2,(imageHeight-ChartHeight) div 2,
                           ChartWidth+((imageWidth-ChartWidth) div 2),ChartHeight+((imageHeight-ChartHeight) div 2));

  Chart1.SaveToBitmapFile('C:\tmp\myChart.jpg');
end;

Posted: Mon Apr 27, 2009 5:13 pm
by 10548232
Hi Yeray,

that's exactly what I try to code...
I have a well log and have to create a Bitmap with a vertical depth axis from top down into the borehole (for a given scale like 1cm = 40 m) and a horizontal axis with the result of a physical measurement (for a given scale too).
Now, you have solved my problem.

:D Thank you.

Roland