Page 1 of 1

Gantt: count maximum items visible inside

Posted: Thu Sep 01, 2005 2:19 pm
by 9339637
Hello,


is there a possibility to calculate the maximum number of vertically visible items in a gantt chart, to manually setup the min.max values for scrolling purpose? In automatic mode (LeftAxis.Automatic=True) the blocks of the ganttchart are overlapping but the labels don't, ie.

Label1 ---------[ a ]--------------
[ b ]
Label3 ----------------[ c ]---------------------------
[ d ]
Label5 -------------------------------[ e ]-----

a), c), e) are ok, b) and d) are bad (corresponding labels are hidden)

Should be:

Top of left axis (series)
------------------------

Label1 ----- - - -

Label2 ----- - - -

Label3 ----- - - -

------------------------
Bottom of left axis (series)


Thanks for support
Manfred

Posted: Fri Sep 02, 2005 2:15 pm
by narcis
Hi Manfred,

You could try "playing" with left axis SetMinMax method doing something like:

Code: Select all

procedure TForm1.FormCreate(Sender: TObject);
begin
  Series1.FillSampleValues(100);
  Series1.Marks.Visible:=true;
  AxisScroll:=(Series1.YValues.MaxValue - Series1.YValues.MinValue) / 4;
  Chart1.Draw;
end;

procedure TForm1.Chart1AfterDraw(Sender: TObject);
begin
  Chart1.Axes.Left.Maximum:=Chart1.Axes.Left.Minimum+AxisScroll;
end;

procedure TForm1.UpClick(Sender: TObject);
begin
  With Chart1.Axes.Left do
    if (Maximum<Series1.YValues.MaxValue) then
      SetMinMax(Minimum+AxisScroll, Maximum+AxisScroll);
end;

procedure TForm1.DownClick(Sender: TObject);
begin
  With Chart1.Axes.Left do
    if (Minimum>Series1.YValues.MinValue) then
      SetMinMax(Minimum-AxisScroll, Maximum-AxisScroll);
end;

Posted: Mon Sep 05, 2005 8:52 am
by 9339637
Hi Narcis,


hmm I want to deal with the left axis of a chart containing a gantt series.
Therefor you have to setup the leftaxis.minimum (default=1) and the leftaxis.maximum (depends on the height of the chart.clientheight, the amount of gantt items and the height of the labels/gantt bars).
For instance the resulting avaiable height is 300 pixels, the label height is 60 pixels, there will be enough room for 300/60 items -> 5.
And when you have a total of 8 items, you have to set the min/max values to 1/5. But how can I calculate this value: 5
Same problem you have some additional axes/ranges or the user changes the height of the chart....

Additional conditions: No label should be hidden, no bar of the gantt series should be overlapped, instead the visible range (min/max of the left axis) should be reduced, that all labels of this range are visible.

Greetings
Manfred

Posted: Wed Sep 14, 2005 2:41 pm
by narcis
Hi Manfred,

Then you should do something like:

Code: Select all

procedure TForm1.FormCreate(Sender: TObject);
var
  i : integer;
begin
  for i:=0 to 46 do
    Series1.AddGantt(38500+i,38502+1,i,'');
  Series1.Marks.Visible:=true;

  Chart1.Draw;
  Chart1.CustomAxes.Items[0].SetMinMax(0,NumGanttBars);
end;

procedure TForm1.Chart1AfterDraw(Sender: TObject);
var
  GanttBarHeight,ChartAreaHeight: Integer;

begin
  GanttBarHeight:=(Series1.Pointer.VertSize*2)+(Series1.Pointer.Pen.Width*2);//+Series1.Marks.Height+(Series1.Marks.Pen.Width*2);

  ChartAreaHeight:=Chart1.ChartRect.Bottom - Chart1.ChartRect.Top +
     (Chart1.Walls.Back.Pen.Width*2) + Chart1.Axes.Bottom.Axis.Width +
      Chart1.Axes.Top.Axis.Width;

  NumGanttBars:=ChartAreaHeight div GanttBarHeight;
  Edit1.Text := IntToStr(NumGanttBars);
end;

procedure TForm1.UpClick(Sender: TObject);
begin
  With Chart1.CustomAxes.Items[0] do
    if (Maximum<Series1.YValues.MaxValue) then
      SetMinMax(Minimum+1, Maximum+1);
end;

procedure TForm1.DownClick(Sender: TObject);
begin
  With Chart1.Axes.Left do
  With Chart1.CustomAxes.Items[0] do
    if (Minimum>Series1.YValues.MinValue) then
      SetMinMax(Minimum-1, Maximum-1);
end;

procedure TForm1.CheckBox1Click(Sender: TObject);
begin
  Series1.Marks.Visible := Checkbox1.Checked;
end;