how to set different scale for axis(log+linear mixed)

TeeChart for Java (NetBeans, Eclipse, Android Studio, etc)
Post Reply
Chen
Newbie
Newbie
Posts: 43
Joined: Tue Mar 11, 2008 12:00 am
Contact:

how to set different scale for axis(log+linear mixed)

Post by Chen » Mon Aug 03, 2009 4:29 pm

Hi,
We are doing cumulative probability chart using Teechart Java version. There is a request to set mixed scale for Y-axis. 0-5% and 95%-100% is in logarithm, and 5%-95% is regular linear scale. I did not find any existing APIs can do it. If not, how to make a customized axis scale?

Thanks for your time,


Chen

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

Re: how to set different scale for axis(log+linear mixed)

Post by Yeray » Thu Aug 06, 2009 7:52 am

Hi Chen

I'm afraid that's not possible to make a custom (irregular) axis scale. The only solution I can think right now would be having three vertical axes (with three identical series) and you could set two of them to be logarithmic.

Here you have a very simple example. Note that you'll have to adjust manually your axes minimum and maximum in order to "connect the lines":

Code: Select all

uses series;

var log1, log2, linear1: TFastLineSeries;

procedure TForm1.FormCreate(Sender: TObject);
var i: Integer;
begin
  Chart1.View3D := false;

  log1 := TFastLineSeries.Create(self);
  log2 := TFastLineSeries.Create(self);
  linear1 := TFastLineSeries.Create(self);

  with Chart1 do
  begin
    AddSeries(log1);
    AddSeries(log2);
    AddSeries(linear1);
  end;

  for i:=0 to 99 do linear1.Add(i);
  log1.DataSource := linear1;
  log2.DataSource := linear1;

  with Chart1 do
  begin
    CustomAxes.Add;
    CustomAxes.Add;
    log1.CustomVertAxis := CustomAxes[0];
    log2.CustomVertAxis := CustomAxes[1];

    CustomAxes[0].Axis.Color := log1.Color;
    Axes.Left.Axis.Color := linear1.Color;
    CustomAxes[1].Axis.Color := log2.Color;

    CustomAxes[0].StartPosition := 0;
    CustomAxes[0].EndPosition := 5;
    Axes.Left.StartPosition := 5;
    Axes.Left.EndPosition := 95;
    CustomAxes[1].StartPosition := 95;
    CustomAxes[1].EndPosition := 100;

    CustomAxes[0].Logarithmic := true;
    CustomAxes[1].Logarithmic := true;

    CustomAxes[0].SetMinMax(95, 100);
    Axes.Left.SetMinMax(5, 95);
    CustomAxes[1].SetMinMax(0,5);
  end;

  linear1.BeforeDrawValues:=SeriesBeforeDraw;
  log1.BeforeDrawValues:=SeriesBeforeDraw;
  log2.BeforeDrawValues:=SeriesBeforeDraw;
  linear1.AfterDrawValues:=SeriesAfterDraw;
  log1.AfterDrawValues:=SeriesAfterDraw;
  log2.AfterDrawValues:=SeriesAfterDraw;
end;

procedure TForm1.SeriesBeforeDraw(Sender: TObject);

  Function SeriesRect(Series:TChartSeries):TRect;
  begin
    With result do
    begin
      Left:=Series.GetHorizAxis.IStartPos;
      Right:=Series.GetHorizAxis.IEndPos;
      Top:=Series.GetVertAxis.IStartPos;
      Bottom:=Series.GetVertAxis.IEndPos;
    end;
  end;

begin
  With Chart1 do
    if CanClip then
      Canvas.ClipRectangle(SeriesRect( Sender as TChartSeries ));
end;

procedure TForm1.SeriesAfterDraw(Sender: TObject);
begin
  Chart1.Canvas.UnClipRectangle;
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

Post Reply