First of, excuse my ignorance of logarithmic scales, but 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)
If the decade is 2 to 3, he wants the following labels(1, 2, 3, 4, 7, 10) and the following minor ticks (1.5, 2.5, 5, 6, 8, 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
minor ticks at arbitrary positions logarithmic scale?
Re: minor ticks at arbitrary positions logarithmic scale?
Hi Errol,
I'm not sure about what do you mean with the "decade", but here you have an example of how you could have labels at 1, 2, 3,... and a minor tick between each 2 labels:Errol wrote: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)
Code: Select all
uses Series;
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.SetMinMax(1, 10);
Chart1.Axes.Bottom.MinorTickCount:=1;
end;
Here we have non-equidistant labels, so we should use custom labels. The minor ticks are drawn where you want for me here:Errol wrote: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)
Code: Select all
uses Series;
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 6 do
Chart1.Axes.Bottom.Items.Add(i, IntToStr(i));
Chart1.Axes.Bottom.Items.Add(8, '8');
Chart1.Axes.Bottom.Items.Add(10, '10');
Chart1.Axes.Bottom.MinorTickCount:=1;
end;
Here the minor ticks are also irregular, so in the example below I used custom labels (like above) and I'm implemented a DrawMinorTick method to draw the custom minor ticks manually:Errol wrote:If the decade is 2 to 3, he wants the following labels(1, 2, 3, 4, 7, 10) and the following minor ticks (1.5, 2.5, 5, 6, 8, 9)
Code: Select all
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;
Best Regards,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |
Re: minor ticks at arbitrary positions logarithmic scale?
Thanks for the code, will check it out and report back (no pun intended)