【问题标题】:minor ticks TeeChart delphi logarithmic scale小刻度 TeeChart delphi 对数刻度
【发布时间】:2012-12-03 13:35:04
【问题描述】:

我有一个关于小刻度的非常具体的要求。我的客户想要一个根据不同年代具有不同数量的次要刻度的图表。例如,如果十年小于 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)

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

谢谢

【问题讨论】:

    标签: delphi teechart


    【解决方案1】:

    我已经阅读了 TeeChart 源代码 (v2010)。没有定制的余地——没有像OnGetNextAxisLabel 这样的东西。

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

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

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

    【讨论】:

      【解决方案2】:

      在这里回答你here。我在这里发布了最后一个更复杂的示例中的代码,其中自定义标签用于绘制不规则标签,并创建了一个 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;
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-01-09
        • 2011-11-01
        • 1970-01-01
        • 1970-01-01
        • 2020-09-07
        • 2022-01-02
        • 1970-01-01
        • 2014-03-22
        相关资源
        最近更新 更多