Vis Js Timeline Component Basic Overview
Posted By : Manisha Kirodiwal | 28-Mar-2018
Vis.js is a visualization library.Using this library we can handle large amounts of dynamic data and can manipulate the data.This library is very easy to use.
Vis.js contains the multiple components.
Here we are discussing basics of Timeline View.
Timeline Component:
Overview:
The Timeline is
The timeline uses HTML DOM to make the timeline and items set to the timeline. Due to this Vis Js allows the flexible changes using
Example:
Loading:
Create a Sub folder in your project then Install the vis.js in that sub folder.After that import the library's css and script files in your html codes Head section.
<script src="vis/dist/vis.js"></script>
<link href="vis/dist/vis.css" rel="stylesheet" type="text/css" />
The Timeline constructor is vis.Timeline
var timeline = new vis.Timeline(container, items, options);
or when we are using groups:
var timeline = new vis.Timeline(container, items, groups, options);
The timeline constructor contains four parameters:
Container is the DOM element in which the timeline creates.Items is an Array containing items. Iems are data set which we are displaying over the timeline.Groups is an Array containing groups. Groups are used to categories the items.Options is an optional Object. Options can also be set using the setOptions method . Basically using options we can set settings of the timeline.
Items:
Items over the timeline can be constructed using an Array, a DataSet, or a DataView. Items are normal objects. Items can contain the following basic properties :
start, end , content, group, className, editable, and style. (some properties are optional)
A DataSet offers 2 way data binding, a DataView offers 1 way data binding.
A DataSet is constructed as:
var items = new vis.DataSet([
{
start: new Date(2019, 7, 15),
end: new Date(2015, 8, 2), // end is optional
content: 'Trajectory AB'
// Optional: fields 'id', 'type', 'group', 'className', 'style'
}
// more item....
]);
Groups:
We can create groups using an Array, a DataSet, or a DataView. Groups are used to group the items together.Items are categrories per
Groups can contain the properties id, content, and className (optional).
A DataSet offers 2 way data binding, a DataView offers 1 way data binding.
setGroups method is used to apply the groups to the timeline or supplied in the constructor. Following is the example to create A data with groups:
var groups = [
{
id: 1,
content: 'Group 1'
// Optional: a field 'className', 'style', 'order', [properties]
}
// more groups...
]);
Configuration Options:
Options can be used to customize or set settings of the timeline.Format of the Options are JSON object. Please nothe that All options are optional.
var options = {
width: '100%',
height: '30px',
margin: {
item: 20
}
};
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
Manisha Kirodiwal
Manisha is a Web Application developer and she is good in working with Angular, TypeScript , JavaScript and Jquery. In free time she loves to dance and cooking.