You can hide the "empty" series by setting its "Pointer.Visible" property to "false". This will still include that series in the legend. If you want the series to be blank on the chart (the label still drawn along the left-axis), you will need to add at least one value to it and you'll surely want to choose a value that helps preserve the chart's readability. In my example, I chose to use the smallest date from the non-empty series and if all the series are "empty" simply use the current DateTime ("Now").
Also, you want to connect the chart's "GetLegendText" event so you can provide only the name of each series instead of some combination of the series name and its data. There does not appear to be a useful setting in the legend's properties. You could extend this and return only the series' name when empty and some more meaningful name/data combination when not.
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, VclTee.TeeGDIPlus, VCLTee.TeEngine, Vcl.ExtCtrls, VCLTee.TeeProcs, VCLTee.Chart,
VCLTee.Series, VCLTee.GanttCh, Vcl.StdCtrls;
type
TForm1 = class(TForm)
Chart1: TChart;
Series1: TGanttSeries;
Button1: TButton;
Series2: TGanttSeries;
Series3: TGanttSeries;
procedure FormCreate(Sender: TObject);
procedure Chart1GetLegendText(Sender: TCustomAxisPanel; LegendStyle: TLegendStyle; Index: Integer; var LegendText: string);
private
Series : array[0..2] of TGanttSeries;
SeriesName : array[0..2] of string;
SeriesStart : array[0..2] of TDateTime;
SeriesEnd : array[0..3] of TDateTime;
SeriesColor : array[0..2] of TColor;
procedure DrawChart;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
var
i : integer;
begin
Series[0] := Series1;
Series[1] := Series2;
Series[2] := Series3;
SeriesName[0] := 'Task #1';
SeriesName[1] := 'Task #2';
SeriesName[2] := 'Task #3';
SeriesStart[0] := 0; SeriesEnd[0] := 0;
SeriesStart[1] := Now; SeriesEnd[1] := Now+1;
SeriesStart[2] := Now+0.5; SeriesEnd[2] := Now+3;
SeriesColor[0] := clBlue;
SeriesColor[1] := clGreen;
SeriesColor[2] := clRed;
for i := 0 to 2 do
begin
Series[i].ColorEachPoint := false;
Series[i].SeriesColor := SeriesColor[i];
end;
DrawChart;
end;
procedure TForm1.DrawChart;
var
EmptyValue : TDateTime;
i : integer;
begin
EmptyValue := 0;
for i := 0 to 2 do
begin
if (SeriesStart[i] <> 0) and
( (EmptyValue = 0) or (EmptyValue > SeriesStart[i]) ) then
EmptyValue := SeriesStart[i];
end;
if EmptyValue = 0 then
EmptyValue := Now;
for i := 0 to 2 do
begin
Series[i].Clear;
if SeriesStart[i] = 0 then
begin
Series[i].Pointer.Visible := false;
Series[i].AddGanttColor(EmptyValue,EmptyValue, i, SeriesName[i], SeriesColor[i])
end
else
begin
Series[i].Pointer.Visible := true;
Series[i].AddGanttColor(SeriesStart[i],SeriesEnd[i],i,SeriesName[i], SeriesColor[i])
end;
end;
end;
procedure TForm1.Chart1GetLegendText(Sender: TCustomAxisPanel; LegendStyle: TLegendStyle; Index: Integer; var LegendText: string);
begin
LegendText := SeriesName[Index];
end;
end.