Scaling plots

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
johnnix
Advanced
Posts: 192
Joined: Tue Jul 10, 2007 12:00 am

Scaling plots

Post by johnnix » Wed Dec 14, 2011 9:49 am

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

Yeray
Site Admin
Site Admin
Posts: 9534
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Scaling plots

Post by Yeray » Thu Dec 15, 2011 3:55 pm

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.
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

johnnix
Advanced
Posts: 192
Joined: Tue Jul 10, 2007 12:00 am

Re: Scaling plots

Post by johnnix » Fri Dec 16, 2011 7:17 am

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

Yeray
Site Admin
Site Admin
Posts: 9534
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Scaling plots

Post by Yeray » Mon Dec 19, 2011 1:31 pm

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;
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Post Reply