Class GanttChart<R extends Row<?,​?,​?>>

Type Parameters:
R - the type of the rows shown by the Gantt chart (e.g. "Aircraft")
All Implemented Interfaces:
Styleable, EventTarget, Skinnable

public class GanttChart<R extends Row<?,​?,​?>>
extends GanttChartBase<R>
A control used to visualize any kind of scheduling data along a timeline. The model data needed by the control consists of rows with activities, links between activities, and layers to group activities together.

The control consists of several children controls:

  • TreeTableView: shown on the left-hand side to display a hierarchical structure of rows
  • GraphicsBase: shown on the right-hand side to display a graphical representation of the model data
  • Timeline: shown above the graphics view. The timeline itself consists of two child controls.
  • Dateline: displays days, weeks, months, years, etc...
  • Eventline: displays various time markers
The screenshot belows shows the initial appearance of an empty Gantt chart control.
Gantt Chart Control

Master / Detail Panes

The Gantt chart uses two MasterDetailPane instances from ControlsFX for the high-level layout. The tree table master detail pane displays the tree table as its detail node. The graphics master detail pane displays a property sheet as its detail node. The property sheet is used at development time and can be replaced with any node by calling GanttChartBase.setDetail(Node). The property sheet displays a lot of properties that are used by the controls, the renderers, the system layers to fine-tune the appearance of the control. Many of them can be changed at runtime.

Standalone vs. Multi- / Dual Gantt Chart

A Gantt chart can be used standalone or inside a MultiGanttChartContainer or DualGanttChartContainer. When used in one of these containers the Position of the Gantt chart becomes important. The control can be the first chart, the last chart, the only chart, or a chart somewhere in the middle. A "first" or "only" chart always displays a timeline. A "middle" or "last" displays a special header (see GanttChartBase.setGraphicsHeader(Node)). The containers are also the reason why the control distinguishes between a timeline (GanttChartBase.getTimeline()) and a master timeline ( GanttChartBase.getMasterTimeline()). The master timeline is the one shown by the "first" chart, while the regular timeline is the one that belongs directly to an individual Gantt chart instance.

Code Example

 import java.time.Duration;
 import java.time.Instant;
 import java.time.temporal.ChronoUnit;

 import javafx.application.Application;
 import javafx.scene.Scene;
 import javafx.stage.Stage;

 import com.flexganttfx.model.GanttChartModel;
 import com.flexganttfx.model.Layer;
 import com.flexganttfx.model.Row;
 import com.flexganttfx.model.activity.MutableActivityBase;
 import com.flexganttfx.model.layout.GanttLayout;
 import com.flexganttfx.view.GanttChart;
 import com.flexganttfx.view.graphics.GraphicsView;
 import com.flexganttfx.view.graphics.renderer.ActivityBarRenderer;
 import com.flexganttfx.view.timeline.Timeline;

 public class TutorialAircraftFlight extends Application {


  class FlightData {
        String flightNo;
        Instant departureTime = Instant.now();
        Instant arrivalTime = Instant.now().plus(Duration.ofHours(6));

        public FlightData(String flightNo, int day) {
                this.flightNo = flightNo;
                departureTime = departureTime.plus(Duration.ofDays(day));
                arrivalTime = arrivalTime.plus(Duration.ofDays(day));
    }
  }

  class Flight extends MutableActivityBase<FlightData> {
        public Flight(FlightData data) {
                setUserObject(data);
                setName(data.flightNo);
                setStartTime(data.departureTime);
                setEndTime(data.arrivalTime);
    }
  }

  class Aircraft extends Row<Aircraft, Aircraft, Flight> {
        public Aircraft(String name) {
                super(name);
    }
  }

  public void start(Stage stage) {
        // Create the root row
        Aircraft root = new Aircraft("Root");
        root.setExpanded(true);

        // Create the Gantt chart
        GanttChart<Aircraft> gantt = new GanttChart<>(new FlightSchedule(new Aircraft("ROOT")));

        Layer flightsLayer = new Layer("Flights");
        gantt.getLayers().add(flightsLayer);

        Aircraft b747 = new Aircraft("B747");
        b747.addActivity(flightsLayer, new Flight(new FlightData("flight1", 1)));
        b747.addActivity(flightsLayer, new Flight(new FlightData("flight2", 2)));
        b747.addActivity(flightsLayer, new Flight(new FlightData("flight3", 3)));

        Aircraft a380 = new Aircraft("A380");
        a380.addActivity(flightsLayer, new Flight(new FlightData("flight1", 1)));
        a380.addActivity(flightsLayer, new Flight(new FlightData("flight2", 2)));
        a380.addActivity(flightsLayer, new Flight(new FlightData("flight3", 3)));

        root.getChildren().setAll(b747, a380);

        Timeline timeline = gantt.getTimeline();
        timeline.showTemporalUnit(ChronoUnit.HOURS, 10);

        GraphicsView<Aircraft> graphics = gantt.getGraphics();
        graphics.setActivityRenderer(Flight.class, GanttLayout.class,
                        new ActivityBarRenderer<>(graphics, "Flight Renderer"));
        graphics.showEarliestActivities();

        Scene scene = new Scene(gantt);
        stage.setScene(scene);
        stage.sizeToScene();
        stage.centerOnScreen();
        stage.show();
  }

  public static void main(String[] args) {
        launch(args);
  }
 
Since:
1.0