I am using Gantt series to show regions on a chart. The problem is that the series is drawn on the top of the chart grid.
I would like the normal line series to be drawn on the top of the grid and Gantt series behind it. Is it possible with standard TChart features, without OnAfterDraw?
You could draw the TGanttSeries
at OnBeforeDrawAxes
, then hide it at OnBeforeDrawSeries
and finally make it visible again at OnAfterDraw
for the next drawing cycle:
type
TForm1 = class(TForm)
Chart1: TChart;
Series1: TGanttSeries;
Series2: TLineSeries;
procedure FormCreate(Sender: TObject);
procedure Chart1BeforeDrawAxes(Sender: TObject);
procedure Chart1BeforeDrawSeries(Sender: TObject);
procedure Chart1AfterDraw(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
type TCustomSeriesAccess=class(TCustomSeries);
procedure TForm1.Chart1BeforeDrawAxes(Sender: TObject);
begin
TCustomSeriesAccess(Series1).DrawAllValues;
end;
procedure TForm1.Chart1BeforeDrawSeries(Sender: TObject);
begin
Series1.Visible:=False;
end;
procedure TForm1.Chart1AfterDraw(Sender: TObject);
begin
Series1.Visible:=True;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Chart1.Draw;
end;