Draw axis through origin

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
Ian
Newbie
Newbie
Posts: 5
Joined: Tue Jan 22, 2008 12:00 am

Draw axis through origin

Post by Ian » Fri Apr 24, 2009 5:14 am

Hello,
I'm fairly new to the newsgroup so apologies if this has been asked before.
I have an xy graph with the y axis going from negative to positive: say -100 to + 100. The x axis goes from 0: say 0 to 100. I want the x axis to go through y=0, but can't find a property to make this happen. This is like the default with an xy scatter graph in Excel 2007.
Any help much appreciated.
Thanks, Ian

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

Post by Yeray » Fri Apr 24, 2009 10:08 am

Hi Ian,

Here there is an example in ActiveX. If you find problems translating it don't hesitate to let us know.
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

Ian
Newbie
Newbie
Posts: 5
Joined: Tue Jan 22, 2008 12:00 am

Post by Ian » Fri Apr 24, 2009 11:34 am

Hi Yeray
If you've got some delphi code that would be great. I thought there might be a property to set.
Thanks, Ian

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

Post by Yeray » Fri Apr 24, 2009 3:28 pm

Hi Ian,

Here is how I would traduce that VB6 code to delphi:

Code: Select all

uses series, Types;

var usePercentages: Boolean;

procedure TForm1.FormCreate(Sender: TObject);
var series1: TLineSeries;
    i: Integer;
begin
  Chart1.View3D := false;

  series1 := TLineSeries.Create(self);
  Chart1.AddSeries(series1);

  for i:=-5 to 10 do
    Series1.AddXY(i, i, '', clTeeColor);

  Chart1.OnAfterDraw := Chart1AfterDraw;
  Chart1.MarginUnits := muPixels;
  usePercentages := false;
  Chart1.Draw;
end;

procedure TForm1.Chart1AfterDraw(Sender: TObject);
var chartWidth, chartHeight, horizZeroLoc, vertZeroLoc: Integer;
    horizPercentLoc, vertPercentLoc: Double;
begin
  with Chart1.Axes do
  begin
    if usePercentages then
    begin
      chartWidth := Chart1.ChartRect.Right - Chart1.ChartRect.Left;
      horizZeroLoc := Bottom.CalcXPosValue(0) - Chart1.ChartRect.Left;
      horizPercentLoc := horizZeroLoc / chartWidth * 100;

      Left.PositionUnits := muPercent;
      Left.PositionPercent := horizPercentLoc;

      chartHeight := Chart1.ChartRect.Bottom - Chart1.ChartRect.Top;
      vertZeroLoc := Left.CalcYPosValue(0) - Chart1.ChartRect.Top;
      vertPercentLoc := vertZeroLoc / chartHeight * 100;

      Bottom.PositionUnits := muPercent;
      Bottom.PositionPercent := 100 - vertPercentLoc;
    end
    else
    begin
      Left.PositionUnits := muPixels;
      Left.PositionPercent := Bottom.CalcXPosValue(0) - Chart1.ChartRect.Left;

      Bottom.PositionUnits := muPixels;
      Bottom.PositionPercent := Chart1.ChartRect.Bottom - Left.CalcYPosValue(0);
    end;
  end;
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

Ian
Newbie
Newbie
Posts: 5
Joined: Tue Jan 22, 2008 12:00 am

Post by Ian » Fri Apr 24, 2009 10:53 pm

Hi Yeray
Once again - problem solved. Many thanks.
Bit of a delay getting back to you because of the time difference here in Australia.
Best regards,
Ian

Post Reply