Vaadin Timeline uses Vaadin containers as data sources for both the graphs and the events. There are, however, some requirements for the containers to make them compatible with the Vaadin Timeline.

The containers have to implement Container.Indexed for the Vaadin Timeline to be able to use them. This is because the Vaadin Timeline dynamically fetches the data from the server when needed. This way large data sets can be used without having to load all data to the client-side at once and it brings a huge performance increase.

Another requirement is that the container has one property of type java.util.Date (or a class that can be cast to it), which contains the timestamp when a data point or event occurred. This property has to be set by using the setGraphTimestampPropertyId() in Timeline. The default property ID timeline.PropertyId.TIMESTAMP is used if no timestamp-property ID has been set.

A graph container also needs to have a value property that defines the value of the data point. This value can be any numerical value. The value property can be set with setGraphValuePropertyId() in Timeline. The default property ID Timeline.PropertyId.VALUE is used if no value property is given.

Below is an example of how a graph container could be constructed:

// Construct a container which implements Container.Indexed       
IndexedContainer container = new IndexedContainer();

// Add the Timestamp property to the container
Object timestampProperty = "Our timestamp property";
container.addContainerProperty(timestampProperty,
                               java.util.Date.class, null);

// Add the value property
Object valueProperty = "Our value property";
container.addContainerProperty(valueProperty, Float.class, null);

// Our timeline
Timeline timeline = new Timeline();

// Add the container as a graph container
timeline.addGraphDataSource(container, timestampProperty,
                                       valueProperty);

The event and marker containers are similar. They both need the timestamp property which should be of type java.util.Date and the caption property which should be a string. The marker container additionally needs a value property which is displayed in the marker popup.

Below is an example on how a marker or event container can be constructed:

// Create the container
IndexedContainer container = new IndexedContainer();
        
// Add the timestamp property
container.addContainerProperty(Timeline.PropertyId.TIMESTAMP,
                               Date.class, null);
        
// Add the caption property
container.addContainerProperty(Timeline.PropertyId.CAPTION,
                              String.class, "");

// Add the marker specific value property.
// Not needed for a event containers.
container.addContainerProperty(Timeline.PropertyId.VALUE,
                               String.class, "");

// Create the timeline with the container as both the marker
// and event data source
Timeline timeline = new Timeline();
timeline.setMarkerDataSource(container, 
	Timeline.PropertyId.TIMESTAMP,
	Timeline.PropertyId.CAPTION,
	Timeline.PropertyId.VALUE);

timeline.setEventDataSource(container,
	Timeline.PropertyId.TIMESTAMP,
	Timeline.PropertyId.CAPTION);

The above example uses the default property IDs. You can change them to suit your needs.

The Timeline listens for changes in the containers and updates the graph accordingly. When it updates the graph and items are added or removed from the container, the currently selected date range will remain selected. The selection bar in the browser area moves to keep the current selection selected. If you want the selection to change when the contents of the container changes and keep the selection area stationary, you can disable the selection lock by setting setBrowserSelectionLock() to false.