Page 1 of 1

Is it possible to have custom axis on left and right?

Posted: Tue Apr 16, 2013 3:34 pm
by 10047857
Hi

I would like to have two separate series in one chart as in your Multiple at Runtime demo.

In the demo you only have labels on the left-hand side of the chart, I would like to display labels for each series on both the left and right-hand sides of the chart - is this possible?

I know that I can swap the labels by setting the Boolean property OtherSide but this doesn't help.

Bruce.

Re: Is it possible to have custom axis on left and right?

Posted: Wed Apr 17, 2013 8:51 am
by yeray
Hi Bruce,

You can set a series to use both the default Left and Right axes:

Code: Select all

Series1.VertAxis:=aBothVertAxis;
However, you can only have one custom vertical axis assigned to a series. You can move it to the right with the OtherSide property, as you said.

A workaround to have two custom vertical axes assigned to a series would be to duplicate the series and set the second custom vertical axis to this dummy series. Ie:

Code: Select all

uses Series, TeeTools;

procedure TForm1.FormCreate(Sender: TObject);
var i, nSeries: Integer;
    tmpAxis: TChartAxis;
begin
  nSeries:=3;

  Chart1.View3D:=false;
  Chart1.MarginLeft:=7;
  Chart1.Legend.HorizMargin:=40;

  for i:=0 to nSeries-1 do
  begin
    with Chart1.AddSeries(TLineSeries) as TLineSeries do
    begin
      FillSampleValues;
      tmpAxis:=Chart1.CustomAxes.Add as TChartAxis;
      CustomVertAxis:=tmpAxis;
      tmpAxis.StartPosition:=i*100/nSeries;
      tmpAxis.EndPosition:=(i+1)*100/nSeries;
      tmpAxis.Axis.Color:=Color;
    end;
  end;

  Chart1.Draw;

  for i:=0 to nSeries-1 do
  begin
    with Chart1.AddSeries(TLineSeries) as TLineSeries do
    begin
      ShowInLegend:=false;
      ShowInEditor:=false;

      tmpAxis:=Chart1.CustomAxes.Add as TChartAxis;
      CustomVertAxis:=tmpAxis;
    end;
    with tmpAxis do
    begin
      StartPosition:=i*100/nSeries;
      EndPosition:=(i+1)*100/nSeries;
      Axis.Color:=Chart1[i].Color;
      OtherSide:=true;
      Grid.Visible:=false;
      SetMinMax(Chart1.CustomAxes[i].Minimum, Chart1.CustomAxes[i].Maximum);
    end;

    if i<nSeries-1 then
    begin
      with Chart1.Tools.Add(TColorLineTool) as TColorLineTool do
      begin
        Axis:=tmpAxis;
        AllowDrag:=false;
        Value:=tmpAxis.Minimum;
      end;
    end;
  end;
end;