[TeeChart 2015.14.150120]
我是一个甘特图,所以x轴是基于日期的。我需要在图表中标记时间段。因此,即标记2009-2011,描述具有某种描述,2011-2013,另有名称......
所以我尝试使用 TColorLineTool ,效果更好(几乎完美),但是:
所以,现在我有了另一个想法:使用不同的系列在图表的整个宽度上构建一条线,每个系列显示一个周期。但我必须在奥德的额外传奇(TExtraLegendTool)中展示这些系列的描述,以便为文本留出足够的空间。但我无法显示 TExtraLegendTool 。我认为该版本的TeeChart存在一个错误,因为安装程序提供的演示也没有显示该工具。
现在我不知道怎么回事。有人有想法吗?
答案 0 :(得分:0)
I've given a try at the first approach:
I've tried to use TColorBandTool but it had some drawbacks:
- I wasn't able anymore to click the Chart-Entries (even if the tool was marked as "behind"
- I could not show a description of the period.
And I think it works fine for me here. This is how it looks and below the code I used.
Note I disabled the TColorBandTool
's AllowDrag
, ResizeStart
and ResizeEnd
properties.
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;