Page 1 of 1

Fixed spacing between gantt bars

Posted: Sun Nov 13, 2022 9:44 pm
by 16584505
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

Re: Fixed spacing between gantt bars

Posted: Tue Nov 15, 2022 8:12 am
by yeray
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 9460 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.

Re: Fixed spacing between gantt bars

Posted: Tue Nov 15, 2022 8:12 pm
by 16584505
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

Re: Fixed spacing between gantt bars

Posted: Wed Nov 16, 2022 7:16 am
by yeray
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 9451 times

Re: Fixed spacing between gantt bars

Posted: Thu Nov 17, 2022 3:39 am
by 16584505
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

Re: Fixed spacing between gantt bars

Posted: Tue Nov 22, 2022 3:00 pm
by yeray
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;