Page 1 of 1

Dual scale on plot

Posted: Thu Apr 13, 2017 1:37 pm
by 16578522
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

Re: Dual scale on plot

Posted: Tue Apr 18, 2017 10:59 am
by yeray
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;

Re: Dual scale on plot

Posted: Tue Apr 18, 2017 2:45 pm
by 16578522
Hello Yeray,

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

Regards

John