Page 1 of 1

how to do chart like a gallery example

Posted: Tue Sep 14, 2004 5:09 pm
by 9339111
hello, browsing through your TeeChart Gallery.

The very first chart example, a gantt chart: How does one add that semi-transparent "overlay" effect, titled "holiday period." It's not another series, is it? How does one line it up with the correct dates? Can more than one overlay be added?

I guess a couple of lines of code as an example would be very helpful. (If the code for the gallery example is available somewhere, point me to it.)

Thanks and regards.

Posted: Wed Sep 15, 2004 7:34 am
by Marjan
Hi.
It's not another series, is it?
Nope. It's a TColorBandTool tool, combined with annotation tool (for "Holiday period" caption). Alternatively, you could also manually drawn required text over the color band in the chart OnAfterDraw event. Something like this:

Code: Select all

var x,y,th: Integer;
begin
  x := Chart1.Axes.Bottom.CalcPosValue(ChartTool1.StartValue);
  With Chart1.Axes.Left do
    y := (IStartPos + IEndPos) div 2;
  With Chart1.Canvas, Chart1 do
  begin
    ClipRectangle(ChartRect);
    Font.Height := -13;
    Font.Color := clNavy;
    th := TextHeight('W');
    TextOut(x+20,y-(th div 2),'Holiday period');
    UnclipRectangle;
  end;
end;
How does one line it up with the correct dates?
By setting the colorband tool StartValue and EndValue. Here is an example where start and end value are set to specific datetime range:

Code: Select all

endDate := EncodeDate(2004,9,10);
Chart1.Axes.Bottom.SetMinMax(endDate-45,enddate);
colorBandTool1.Axis := Chart1.Axes.Bottom;
colorBandTool1.StartValue := EncodeDate(2004,8,6);
colorBandTool1.EndValue := EncodeDate(2004,8,21);
colorBandTool1.Transparency := 50;
Can more than one overlay be added?
Yes (add multiple instances at design or at runtime).