4

I have a very specific request regarding minor ticks. My client want a graph with a different number of minor ticks according to different decades. For example, if the decade is less than 1 he wants 10 labels(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) and the following minor ticks (1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5 ,9.5)

If the decade is 1 to 2, he wants the following labels(1, 2, 3, 4, 5, 6, 8, 10) and the following minor ticks (1.5, 2.5, 3.5, 4.5, 5.5, 7, 9)

Any help much appreciated. I can't find how to override the tick marks so I can place them at custom points. I have figured out custom labels though.

Thanks

Infinite Recursion
  • 6,511
  • 28
  • 39
  • 51

2 Answers2

2

Answered you here here. I post here the code from the last and more complex example in which custom labels are used to draw the irregular labels and a DrawMinorTick function is created to manually draw the irregular custom minor ticks.

uses Series, TeCanvas;

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

  Chart1.AddSeries(TFastLineSeries).FillSampleValues(10);
  for i:=0 to Chart1[0].Count-1 do
    Chart1[0].XValue[i]:=i+1;

  Chart1.Axes.Bottom.Items.Clear;
  for i:=1 to 4 do
    Chart1.Axes.Bottom.Items.Add(i, IntToStr(i));

  Chart1.Axes.Bottom.Items.Add(7, '7');
  Chart1.Axes.Bottom.Items.Add(10, '10');

  Chart1.Axes.Bottom.MinorTickCount:=0;
end;

procedure TForm1.Chart1AfterDraw(Sender: TObject);
begin
  DrawMinorTick(Chart1.Axes.Bottom, 1.5);
  DrawMinorTick(Chart1.Axes.Bottom, 2.5);
  DrawMinorTick(Chart1.Axes.Bottom, 5);
  DrawMinorTick(Chart1.Axes.Bottom, 6);
  DrawMinorTick(Chart1.Axes.Bottom, 8);
  DrawMinorTick(Chart1.Axes.Bottom, 9);
end;

procedure TForm1.DrawMinorTick(axis: TChartAxis; value: double);
var XPos, YPos: Integer;
begin
  Chart1.Canvas.Pen.Color:=axis.MinorTicks.Color;
  Chart1.Canvas.Pen.Width:=axis.MinorTicks.Width;
  Chart1.Canvas.Pen.Style:=axis.MinorTicks.Style;
  if axis.Horizontal then
  begin
    XPos:=axis.CalcPosValue(value);
    YPos:=axis.PosAxis+1;
    Chart1.Canvas.Line(XPos, YPos, XPos, YPos+axis.MinorTickLength);
  end
  else
  begin
    XPos:=axis.PosAxis;
    YPos:=axis.CalcPosValue(value);
    Chart1.Canvas.Line(XPos, YPos, XPos-axis.MinorTickLength, YPos);
  end;
end;
Yeray
  • 5,009
  • 1
  • 13
  • 25
1

I've had a read of the TeeChart source code (v2010). There is no scope for customisation–nothing like OnGetNextAxisLabel.

For non-logarithmic axes, the minor ticks are drawn equally spaced between the labels.

For logarithmic axes the minor ticks are not drawn equally spaced between the labels, at least for non-equally spaced labels. In fact I can see that in my code I always disable minor ticks when using logarithmic axes. I suspect that's because they simply don't work at all!

So I think your only option is to modify the source code yourself.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490