Dual scale on plot

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
johnnix
Newbie
Newbie
Posts: 16
Joined: Mon Jun 20, 2016 12:00 am

Dual scale on plot

Post by johnnix » Thu Apr 13, 2017 1:37 pm

Hello,

I am investigating the possibility to have dual X scales on a plot (attached is an example), is this something that TChart supports?

Thank you very much for your time

Regards
Attachments
Screenshot_1.png
Screenshot_1.png (26.99 KiB) Viewed 7939 times

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

Re: Dual scale on plot

Post by Yeray » Tue Apr 18, 2017 10:59 am

Hello,

One possibility could be to use both Horizontal axes (Top and Bottom) as in the following example:

Code: Select all

procedure TForm1.Chart1GetAxisLabel(Sender: TChartAxis; Series: TChartSeries;
  ValueIndex: Integer; var LabelText: string);
begin
  if Sender = Chart1.Axes.Bottom then
  begin
    LabelText:= FormatFloat('#,##0', StrToFloatDef(LabelText, 0) / 10);
  end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Chart1.View3D:=False;
  Chart1.Legend.Visible:=False;

  Chart1.MarginBottom:=10;

  with Chart1.AddSeries(THorizLineSeries) as THorizLineSeries do
  begin
    FillSampleValues;
    HorizAxis:=aBothHorizAxis;
  end;

  Chart1.Axes.Bottom.OtherSide:=True;
  Chart1.Axes.Bottom.Grid.Visible:=False;
  Chart1.Axes.Bottom.Ticks.Visible:=False;
  Chart1.Axes.Bottom.MinorTicks.Visible:=False;
end;
Another similar possibility could be to use a SubAxis. Ie:

Code: Select all

procedure TForm1.Chart1GetAxisLabel(Sender: TChartAxis; Series: TChartSeries;
  ValueIndex: Integer; var LabelText: string);
begin
  if Sender = Chart1.Axes.Top.SubAxes[0] then
  begin
    LabelText:= FormatFloat('#,##0.##', StrToFloatDef(LabelText, 0) / 10);
  end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Chart1.View3D:=False;
  Chart1.Legend.Visible:=False;

  Chart1.MarginBottom:=10;

  with Chart1.AddSeries(THorizLineSeries) as THorizLineSeries do
  begin
    FillSampleValues;
    HorizAxis:=aTopAxis
  end;

  with Chart1.Axes.Top.SubAxes.Add do
  begin
    Axis.Visible:=False;
    LabelsFont.Name:=Chart1.Axes.Top.LabelsFont.Name;
  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

johnnix
Newbie
Newbie
Posts: 16
Joined: Mon Jun 20, 2016 12:00 am

Re: Dual scale on plot

Post by johnnix » Tue Apr 18, 2017 2:45 pm

Hello Yeray,

Thank you very much for your prompt reply, I will definitely give it a try :)

Regards

John

Post Reply