Page 1 of 1

Resizing the axis

Posted: Thu Mar 16, 2006 7:21 pm
by 9525970
Hello,

I have a problem with resizing the axis. My problem is to be able to resize the axis so that the frame looks like a rectangle with the same range.

For ex:- If the initial frame looks like a square with X and Y axis going from 0-100. I want to resize/redraw the frame in such a way that the X and Y axis still go from 0-100 but the frame appears like a rectangle.

How can I post images to this board ?

Thanks

Posted: Mon Apr 03, 2006 5:07 pm
by 9525970
I still havent been able to fix this issue .. does anyone have any ideas/solutions ?

Thanks

Posted: Tue Apr 11, 2006 9:32 am
by Pep
Hi,

the following code can be used to make isometric axis :

Code: Select all

unit UISOAxis;

interface

uses
  WinTypes,WinProcs, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, Buttons, TeEngine, Series, ExtCtrls, TeeProcs, Chart;

{ See below the MakeISOAxis routine.
  This routine will change the axis scales to be isometric
  with the screen size and video mode pixel size.

  So, both the Left and Bottom axis will have equivalent
  distance on screen for the same Axis Increment.
  This makes the grid lines to appear "squared".
}

type
  TIsoMetricAxisForm = class(TForm)
    Chart1: TChart;
    Series1: TFastLineSeries;
    ScrollBar1: TScrollBar;
    Label1: TLabel;
    Label2: TLabel;
    Button1: TButton;
    Button2: TButton;
    CheckBox1: TCheckBox;
    procedure Chart1UndoZoom(Sender: TObject);
    procedure ScrollBar1Change(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Chart1Zoom(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure CheckBox1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  IsoMetricAxisForm: TIsoMetricAxisForm;

implementation

{$R *.DFM}

{ Call this function with a Chart or DBChart component
  to adjust the axis scales isometrically:

    MakeISOAxis( Chart1 );
}
Procedure MakeIsoAxis(AChart:TCustomChart);
var tmpX,tmpY,XRange,YRange,Offset,XYScreen:Double;
begin
  With AChart do
  if (ChartHeight>0) and (ChartWidth>0) then
  begin
    With BottomAxis do XRange:=Maximum-Minimum;
    With LeftAxis do   YRange:=Maximum-Minimum;

    XYScreen:=1.0*(GetDeviceCaps(Canvas.Handle,HORZSIZE)/Screen.Width)/
                  (GetDeviceCaps(Canvas.Handle,VERTSIZE)/Screen.Height);

    tmpX:=(XRange/ChartWidth);
    tmpY:=(YRange/ChartHeight)*XYScreen;

    if tmpX>tmpY then
    begin
      if tmpY<>0 then
      begin
        Offset:=((YRange*tmpX/tmpY)-YRange)/2.0;
        With LeftAxis do SetMinMax(Minimum-Offset,Maximum+Offset);
      end;
    end
    else
    if tmpX<>0 then
    begin
      Offset:=((XRange*tmpY/tmpX)-XRange)/2.0;
      With BottomAxis do SetMinMax(Minimum-Offset,Maximum+Offset);
    end;
  end;
end;

{ If user unzooms the Chart with left mouse button, repeat isoaxis: }
procedure TIsoMetricAxisForm.Chart1UndoZoom(Sender: TObject);
begin
  MakeISOAxis(Chart1);
end;

{ This scrollbar is used in this example to change the axes increment... }
procedure TIsoMetricAxisForm.ScrollBar1Change(Sender: TObject);
begin
  With Chart1 do
  begin
    LeftAxis.Increment  :=ScrollBar1.Position*10;
    BottomAxis.Increment:=ScrollBar1.Position*10;
    Label2.Caption:=FloatToStr(LeftAxis.Increment);
  end;
end;

{ Add sample value and initialize the example controls... }
procedure TIsoMetricAxisForm.FormCreate(Sender: TObject);
begin
  Series1.FillSampleValues(100);
  ScrollBar1Change(Self);
  CheckBox1Click(Self);
end;

{ After Zooming the Chart, remake ISO axis: }
procedure TIsoMetricAxisForm.Chart1Zoom(Sender: TObject);
begin
  MakeISOAxis(Chart1);
end;

procedure TIsoMetricAxisForm.Button1Click(Sender: TObject);
begin
  Close;
end;

procedure TIsoMetricAxisForm.Button2Click(Sender: TObject);
begin
  MakeISOAxis(Chart1);
end;

{ When Axis.LabelsSeparation is zero, the axis will
   display all labels without checking for anti-overlapping.
}
procedure TIsoMetricAxisForm.CheckBox1Click(Sender: TObject);
begin
  if CheckBox1.Checked then
  begin
    Chart1.LeftAxis.LabelsSeparation:=0;
    Chart1.BottomAxis.LabelsSeparation:=0;
  end
  else
  begin
    Chart1.LeftAxis.LabelsSeparation:=10;
    Chart1.BottomAxis.LabelsSeparation:=10;
  end;
end;

end.