Fixed spacing between gantt bars

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
Markus46
Newbie
Newbie
Posts: 15
Joined: Thu Sep 20, 2018 12:00 am

Fixed spacing between gantt bars

Post by Markus46 » Sun Nov 13, 2022 9:44 pm

Hello.

I have a TChart with alClient alignment on a resizable form.
This is a code snippet of how the chart & series is set up:

Code: Select all

  FGanttSeries := TGanttSeries.Create(GanttChart);
  GanttChart.AddSeries(FGanttSeries);

  FGanttSeries.Marks.Visible := true;
  FGanttSeries.InflateMargins := true;
  FGanttSeries.ColorEachPoint := false;
  FGanttSeries.Pointer.Size := 8; FGanttSeries.Pointer.SizeUnits := suPixels;
  FGanttSeries.Pointer.Pen.Visible := false;  // no border around bars

  FGanttSeries.Marks.Transparent := true;
  FGanttSeries.Marks.Font.Color := clWhite;
  FGanttSeries.Marks.Margins.Left := 0;
  FGanttSeries.Marks.Margins.Right := 0;
  FGanttSeries.Marks.Margins.Top := 0;
  FGanttSeries.Marks.Margins.Bottom := 0;

  while not eof do begin
	LBarIndex := FGanttSeries.AddGanttColor(FieldByName(FView.ScheduleFieldStart).AsDateTime, FieldByName(FView.ScheduleFieldEnd).AsDateTime,
                 LPos, FieldByName(FView.ScheduleFieldDesc).AsString, LColour);
	Next;
  end;

  GanttChart.LeftAxis.Automatic := false
  GanttChart.LeftAxis.SetMinMax(LMinPos, LMaxPos);
  GanttChart.BottomAxis.SetMinMax(LStartDate, LStartDate + LDateRange);
  GanttChart.BottomAxis.Title.Caption := DateToStr(LStartDate);
As I change the height of the form, the spacing between the gantt bars change such that the 1st bar is at the bottom of the form and the last bar is at the top of the form.

Regarding the Left axis, how can I have fixed spacing between gantt bars (x pixels or y% of the height of a gantt bar) regardless of (i) the height of the chart and (ii) the min/max position?

Regards
Mark

Yeray
Site Admin
Site Admin
Posts: 9613
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Fixed spacing between gantt bars

Post by Yeray » Tue Nov 15, 2022 8:12 am

Hello Mark,

There are some variables missing from that code snipped so I have to skip parts of if that may be important to reproduce the problem.
Here is what I have:
Project1_2022-11-15_09-13-46.gif
Project1_2022-11-15_09-13-46.gif (206.27 KiB) Viewed 9451 times

Code: Select all

uses Chart, TeEngine, TeeGDIPlus, GanttCh;

var  GanttChart: TChart;

procedure TForm1.FormCreate(Sender: TObject);
var FGanttSeries: TGanttSeries;
    LBarIndex: Integer;
    LMinPos, LMaxPos: Double;
    LStartDate: TDateTime;
    LDateRange: TDateTime;
begin
  GanttChart:=TChart.Create(Self);
  GanttChart.Parent:=Self;
  GanttChart.Align:=alClient;

  FGanttSeries := TGanttSeries.Create(GanttChart);
  GanttChart.AddSeries(FGanttSeries);

  FGanttSeries.Marks.Visible := true;
  FGanttSeries.InflateMargins := true;
  FGanttSeries.ColorEachPoint := false;
  FGanttSeries.Pointer.Size := 8; FGanttSeries.Pointer.SizeUnits := suPixels;
  FGanttSeries.Pointer.Pen.Visible := false;  // no border around bars

  FGanttSeries.Marks.Transparent := true;
  FGanttSeries.Marks.Font.Color := clWhite;
  FGanttSeries.Marks.Margins.Left := 0;
  FGanttSeries.Marks.Margins.Right := 0;
  FGanttSeries.Marks.Margins.Top := 0;
  FGanttSeries.Marks.Margins.Bottom := 0;

  FGanttSeries.FillSampleValues(5);
end;
Could you please arrange a simple example project we can run as-is to reproduce the problem here?
Thanks in advance.
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Markus46
Newbie
Newbie
Posts: 15
Joined: Thu Sep 20, 2018 12:00 am

Re: Fixed spacing between gantt bars

Post by Markus46 » Tue Nov 15, 2022 8:12 pm

Hi Yeray,

Your animated GIF illustrates exactly the 'problem'. The gap between gantt bars is increasing/decreasing as the tchart resizes.
My boss doesn't want that behaviour. He wants the gap between bars to be fixed, regardless of the height of the tchart.

Regards
Mark

Yeray
Site Admin
Site Admin
Posts: 9613
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Fixed spacing between gantt bars

Post by Yeray » Wed Nov 16, 2022 7:16 am

Hello

It sounds as changing Chart1.Align property from alClient to ie alTop:
Project1_2022-11-16_08-15-48.gif
Project1_2022-11-16_08-15-48.gif (59.63 KiB) Viewed 9442 times
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Markus46
Newbie
Newbie
Posts: 15
Joined: Thu Sep 20, 2018 12:00 am

Re: Fixed spacing between gantt bars

Post by Markus46 » Thu Nov 17, 2022 3:39 am

Thanks Yeray,

That is close to what we are after.
Is there a way to control the vertical distance between gantt bars? Some property of the Left Axis perhaps?
We would like them to be drawn closer together.

Regards
Mark

Yeray
Site Admin
Site Admin
Posts: 9613
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Fixed spacing between gantt bars

Post by Yeray » Tue Nov 22, 2022 3:00 pm

Hello Mark,

The distance between gantt bars depends on the number of values to be drawn and the axis size, which depends on the chart height.
Also note the Pointer.VertSize (the size of the gantt bars) also affects how this looks.

Code: Select all

FGanttSeries.Pointer.VertSize:=12;
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Post Reply