Page 1 of 1

Second horizontal axis with different units

Posted: Thu Jun 25, 2015 6:00 pm
by 16570762
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?

Re: Second horizontal axis with different units

Posted: Fri Jun 26, 2015 10:20 am
by yeray
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.