Page 1 of 1

Minor Grids on tChart Logarithmic

Posted: Tue Feb 05, 2013 4:54 am
by 16463680
When the axis is logarithmic the minor grid intervals are not sensible. Minor grid lines should be at log2, log5, etc.

In log space, if the number of minor grids is 1 it should be at 3; if 2, at 2, 5; if 3, at 2, 5, 8, etc. This could be the default. Users may want to have other choices. Best would be to make it user-specific.

Alternative: can you show me how user can specify a custom grid line?

Comments welcome!

Re: Minor Grids on tChart Logarithmic

Posted: Tue Feb 05, 2013 11:39 am
by yeray
Hi Hans,

The algorithm that calculates where to place the MinorTicks, does it in function of the LogarithmicBase and the number of MinorTicks to draw. It's actually dividing the distance between Ticks between the MinorTicks Count, but considering the distances as logarithmic.
If you want to use a different algorithm to this, you can always hide the MinorTicks and draw them manually where you want.

Re: Minor Grids on tChart Logarithmic

Posted: Tue Feb 05, 2013 1:13 pm
by 16463680
Yeray, could you point me to method of manually drawing minor grid lines.

Re: Minor Grids on tChart Logarithmic

Posted: Tue Feb 05, 2013 2:50 pm
by yeray
Hi Hans,

Here you have an example where I set the MinorTicks Color and Length. Then I hide them but I use the MinorTicks Color and Length properties to set the Canvas Pen at the OnAfterDraw event, just before drawing the line that will be my custom MinorTick.

Code: Select all

uses Series, TeCanvas;

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

  with Chart1.AddSeries(TFastLineSeries) do
    for i:=1 to 100 do
      AddXY(i, i*i);

  Chart1.Axes.Left.Logarithmic:=true;
  Chart1.Axes.Left.TickLength:=10;

  Chart1.Axes.Left.MinorTickLength:=5;
  Chart1.Axes.Left.MinorTicks.Color:=clRed;
  Chart1.Axes.Left.MinorTicks.Visible:=false;
end;

procedure TForm1.Chart1AfterDraw(Sender: TObject);
var tmpY: Integer;
begin
  with Chart1.Canvas, Chart1.Axes.Left do
  begin
    Pen.Color:=MinorTicks.Color;
    tmpY:=CalcPosValue(5);
    Line(PosAxis-MinorTickLength, tmpY, PosAxis, tmpY);
  end;
end;