Second horizontal axis with different units

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
ironphil
Newbie
Newbie
Posts: 1
Joined: Fri Nov 21, 2014 12:00 am

Second horizontal axis with different units

Post by ironphil » Thu Jun 25, 2015 6:00 pm

I want to be able to show my data using different units. I am trying to create a second horizontal axis to show the other unit. All the source data and the data manipulation are done with the original X unit and I do not want to change that, I just want to show the same data using a different unit.
The relation between the two units is simple: 2nd unit = 12.398 / 1st unit (relation between energy (keV) and wavelength (A) of electrons).
How do I create a second horizontal axis showing the second unit?

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

Re: Second horizontal axis with different units

Post by Yeray » Fri Jun 26, 2015 10:20 am

Hello,

The easier solution is probably to add a Custom Horizontal axis and a dummy series assigned to it.
You can move the custom axis position, show or hide its grid, etc.
The dummy series can be populated with only 2 null points, the minimum and the maximum of the main series converted to the 2nd unit.
Here it is a simple example:

Code: Select all

uses Series;

procedure TForm1.FormCreate(Sender: TObject);
var custAxis: TChartAxis;
begin
  Chart1.View3D:=false;
  Chart1.Legend.Visible:=false;

  Chart1.AddSeries(TFastLineSeries).FillSampleValues;

  Chart1.MarginBottom:=10;
  custAxis:=Chart1.CustomAxes.Add;
  custAxis.Horizontal:=true;
  custAxis.PositionPercent:=-10;
  custAxis.Grid.Visible:=false;

  with Chart1.AddSeries(TFastLineSeries) as TFastLineSeries do
  begin
    CustomHorizAxis:=custAxis;
    AddNullXY(Chart1[0].MinXValue*12.398, Chart1[0].MinYValue);
    AddNullXY(Chart1[0].MaxXValue*12.398, Chart1[0].MinYValue);
    TreatNulls:=tnDontPaint;
  end;
end;
Another solution would be using the same data than the main series and use OnGetAxisLabel on the custom axis to transform the string labels.
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