Page 1 of 1

Scaling plots

Posted: Wed Dec 14, 2011 9:49 am
by 10046032
Hello,

In my application I use Picture objects to present my plots inside my FastReports pages. Currently I am investigating the possibility to present plots in a fixed Y-axis scale for example every 1 cm on the plot will reflect 1 meter in real life (for a plot where the Y axis represents a distance measurement). Any ideas, hints or tips would be mostly appreciated :D

Kindest regards

Re: Scaling plots

Posted: Thu Dec 15, 2011 3:55 pm
by yeray
Hi johnnix,

A cm on the screen depends on the screen resolution. GetDeviceCaps gives you the width and height of the screen so you can use it to calculate the chart size.
Take a look at the "All features\Welcome !\Axes\Isometric Axis" example in the features demo to see how this function is used in it.

Re: Scaling plots

Posted: Fri Dec 16, 2011 7:17 am
by 10046032
Hello Yeray,

Thank you for your tip but I know how to use the GetDeviceCaps but let me explain my question a little bit more. I can calculate that X pixels on the screen form a real cm, how can I transfer this to my plot so that the distance between major marks is X pixels? Or how can I draw the plot in such a way that the size of an axis equals specific pixels?

Regards

Re: Scaling plots

Posted: Mon Dec 19, 2011 1:31 pm
by yeray
Hi johnnix,
johnnix wrote:Or how can I draw the plot in such a way that the size of an axis equals specific pixels?
You can assign a ChartRect with a specific pixel size. However, note this ChartRect set, includes the space for the labels, titles, etc. So you should calculate the space this things will take and add it as extra space. Here it is a simple example of how you could force a ChartRect:

Code: Select all

uses Series;

const myWidth=200;
      myHeight=200;

procedure TForm1.FormCreate(Sender: TObject);
var horizOffset, vertOffset: Integer;
begin
  Chart1.View3D:=false;

  Chart1.AddSeries(TFastLineSeries).FillSampleValues();

  Chart1.CustomChartRect:=true;
  Chart1.Legend.Visible:=false;

  Chart1.Draw; //just to have a valid MaxLabelsWidth value

  horizOffset:=6;
  horizOffset:=horizOffset+Chart1.Axes.Left.MaxLabelsWidth;
  horizOffset:=horizOffset+Chart1.Axes.Left.TickLength;

  vertOffset:=6;
  vertOffset:=vertOffset+Chart1.Title.Height;
  vertOffset:=vertOffset+Chart1.Axes.Bottom.LabelHeight(0);
  vertOffset:=vertOffset+Chart1.Axes.Bottom.TickLength;

  Chart1.ChartRect:=Rect(0, 0, horizOffset+200, vertOffset+200);
end;

procedure TForm1.Chart1AfterDraw(Sender: TObject);
var tmpRight, tmpTop: Integer;
begin
  //drawing the desired chart rect
  Chart1.Canvas.Brush.Style:=bsClear;
  Chart1.Canvas.Pen.Color:=clRed;
  tmpRight:=Chart1.Axes.Left.PosAxis;
  tmpTop:=Chart1.Axes.Left.IStartPos;
  Chart1.Canvas.Rectangle(Rect(tmpRight, tmpTop, tmpRight+myWidth, tmpTop+myHeight));
end;