4

我对小蜱有一个非常具体的要求。我的客户想要一个根据不同年代的具有不同数量的次要刻度的图表。例如,如果十年小于 1,他想要 10 个标签(1、2、3、4、5、6、7、8、9、10)和以下次要刻度(1.5、2.5、3.5、4.5、5.5 , 6.5, 7.5, 8.5 ,9.5)

如果十年是 1 到 2,他想要以下标签(1、2、3、4、5、6、8、10)和以下小刻度(1.5、2.5、3.5、4.5、5.5、7、9)

非常感谢任何帮助。我找不到如何覆盖刻度线,因此我可以将它们放置在自定义点。不过,我已经想出了自定义标签。

谢谢

4

2 回答 2

2

在这里回答你。我在这里发布了最后一个更复杂示例的代码,其中自定义标签用于绘制不规则标签,并DrawMinorTick创建了一个函数来手动绘制不规则自定义次要刻度。

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;
于 2012-12-17T12:17:41.833 回答
1

我已经阅读了 TeeChart 源代码 (v2010)。没有定制的余地——没有什么像OnGetNextAxisLabel.

对于非对数轴,小刻度在标签之间等距绘制。

对于对数轴,小刻度在标签之间的间距不相等,至少对于非等间距的标签。事实上,我可以在我的代码中看到,在使用对数轴时,我总是禁用次要刻度。我怀疑那是因为它们根本不起作用!

所以我认为你唯一的选择是自己修改源代码。

于 2012-12-16T15:26:08.633 回答