【问题标题】:mark regions in (Gantt) Chart在(甘特)图中标记区域
【发布时间】:2015-06-24 16:39:27
【问题描述】:

[TeeChart 2015.14.150120]
我有一个甘特图,所以 x 轴是基于日期的。我需要在图表中标记时间段。因此,即标记 2009 -2011 用某种描述来描述它,2011-2013 用另一个名称来描述......

我尝试使用 TColorBandTool 但它有一些缺点:
  1. 我无法再单击图表条目(即使该工具被标记为“落后”
  2. 我无法显示期间的描述。

所以我尝试使用 TColorLineTool 效果更好(几乎完美)但是:

  1. 不同时期的文本面板显示在相同(垂直)位置,因此它们重叠了一些时间。
  2. 当最后一个 TextPanel 比图表的其余部分长时,它会“退出”,图表没有重新调整大小以在图表中显示面板。

所以,现在我有了另一个想法:使用不同的系列在图表的整个宽度上构建一条线,每个系列显示一个时期。但是我必须在额外的图例(TExtraLegendTool)中显示这些系列的描述,以便有足够的空间容纳文本。但我无法显示 TExtraLegendTool。我认为该版本的 TeeChart 中存在错误,因为安装程序的演示也没有显示该工具。
现在我很茫然如何继续下去。有人有想法吗?

【问题讨论】:

    标签: delphi charts teechart gantt-chart


    【解决方案1】:

    我尝试了第一种方法:

    我曾尝试使用 TColorBandTool,但它有一些缺点:

    1. 我无法再单击图表条目(即使该工具被标记为“落后”
    2. 我无法显示该时期的描述。

    我认为这对我来说很好用。这就是它的外观,位于我使用的代码下方。 注意我禁用了TColorBandToolAllowDragResizeStartResizeEnd 属性。

    var gantt1: TGanttSeries;
        greenBand, blueBand: TColorBandTool;
        greenAnnot, blueAnnot: TAnnotationTool;
    
    procedure TForm1.FormCreate(Sender: TObject);
    begin
      Chart1.Title.Visible:=false;
      Chart1.View3D:=false;
      Chart1.Legend.Alignment:=laBottom;
    
      gantt1:=Chart1.AddSeries(TGanttSeries) as TGanttSeries;
      gantt1.FillSampleValues(10);
    
      greenBand:= Chart1.Tools.Add(TColorBandTool) as TColorBandTool;
      with greenBand do
      begin
        Color:=clGreen;
        Transparency:=50;
        Axis:=Chart1.Axes.Bottom;
        StartValue:=gantt1.StartValues[1];
        EndValue:=gantt1.EndValues[2];
        AllowDrag:=false;
        ResizeStart:=false;
        ResizeEnd:=false;
      end;
    
      blueBand:= Chart1.Tools.Add(TColorBandTool) as TColorBandTool;
      with blueBand do
      begin
        Color:=clBlue;
        Transparency:=50;
        Axis:=Chart1.Axes.Bottom;
        StartValue:=gantt1.StartValues[9];
        EndValue:=gantt1.EndValues[8];
        AllowDrag:=false;
        ResizeStart:=false;
        ResizeEnd:=false;
      end;
    
      Chart1.MarginTop:=10;
    
      Chart1.Draw;
    
      greenAnnot:=Chart1.Tools.Add(TAnnotationTool) as TAnnotationTool;
      with greenAnnot do
      begin
        Shape.Transparent:=true;
        Shape.Font.Color:=clGreen;
        Text:='Green annotation';
        Top:=Chart1.ChartRect.Top-15;
        Left:=Chart1.Axes.Bottom.CalcPosValue(greenBand.StartValue+(greenBand.EndValue-greenBand.StartValue)/2) -
              (Chart1.Canvas.TextWidth(Text) div 2);
      end;
    
      blueAnnot:=Chart1.Tools.Add(TAnnotationTool) as TAnnotationTool;
      with blueAnnot do
      begin
        Shape.Transparent:=true;
        Shape.Font.Color:=clBlue;
        Text:='Blue annotation';
        Top:=Chart1.ChartRect.Top-15;
        Left:=Chart1.Axes.Bottom.CalcPosValue(blueBand.StartValue+(blueBand.EndValue-blueBand.StartValue)/2) -
              (Chart1.Canvas.TextWidth(Text) div 2);
      end;
    end;
    

    【讨论】:

      猜你喜欢
      • 2019-09-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多