vis.js is a dynamic, browser-based visualization library
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

728 lines
19 KiB

  1. <html>
  2. <head>
  3. <title>vis.js | timeline documentation</title>
  4. <link href='css/prettify.css' type='text/css' rel='stylesheet'>
  5. <link href='css/style.css' type='text/css' rel='stylesheet'>
  6. <script type="text/javascript" src="lib/prettify/prettify.js"></script>
  7. </head>
  8. <body onload="prettyPrint();">
  9. <div id="container">
  10. <h1>Timeline documentation</h1>
  11. <h2 id="Overview">Overview</h2>
  12. <p>
  13. The Timeline is an interactive visualization chart to visualize data in time.
  14. The data items can take place on a single date, or have a start and end date (a range).
  15. You can freely move and zoom in the timeline by dragging and scrolling in the
  16. Timeline. Items can be created, edited, and deleted in the timeline.
  17. The time scale on the axis is adjusted automatically, and supports scales ranging
  18. from milliseconds to years.
  19. </p>
  20. <h2 id="Contents">Contents</h2>
  21. <ul>
  22. <li><a href="#Overview">Overview</a></li>
  23. <li><a href="#Example">Example</a></li>
  24. <li><a href="#Loading">Loading</a></li>
  25. <li><a href="#Data_Format">Data Format</a>
  26. <ul>
  27. <li><a href="#items">Items</a></li>
  28. <li><a href="#groups">Groups</a></li>
  29. </ul>
  30. </li>
  31. <li><a href="#Configuration_Options">Configuration Options</a></li>
  32. <li><a href="#Methods">Methods</a></li>
  33. <li><a href="#Events">Events</a></li>
  34. <li><a href="#Styles">Styles</a></li>
  35. <li><a href="#Data_Policy">Data Policy</a></li>
  36. </ul>
  37. <h2 id="Example">Example</h2>
  38. <p>
  39. The following code shows how to create a Timeline and provide it with data.
  40. More examples can be found in the <a href="../examples">examples</a> directory.
  41. </p>
  42. <pre class="prettyprint lang-html">&lt;!DOCTYPE HTML&gt;
  43. &lt;html&gt;
  44. &lt;head&gt;
  45. &lt;title&gt;Timeline | Basic demo&lt;/title&gt;
  46. &lt;style type="text/css"&gt;
  47. body, html {
  48. font-family: sans-serif;
  49. }
  50. &lt;/style&gt;
  51. &lt;script src="../../dist/vis.js"&gt;&lt;/script&gt;
  52. &lt;link href="../../dist/vis.css" rel="stylesheet" type="text/css" /&gt;
  53. &lt;/head&gt;
  54. &lt;body&gt;
  55. &lt;div id="visualization"&gt;&lt;/div&gt;
  56. &lt;script type="text/javascript"&gt;
  57. var container = document.getElementById('visualization');
  58. var items = [
  59. {id: 1, content: 'item 1', start: '2013-04-20'},
  60. {id: 2, content: 'item 2', start: '2013-04-14'},
  61. {id: 3, content: 'item 3', start: '2013-04-18'},
  62. {id: 4, content: 'item 4', start: '2013-04-16', end: '2013-04-19'},
  63. {id: 5, content: 'item 5', start: '2013-04-25'},
  64. {id: 6, content: 'item 6', start: '2013-04-27'}
  65. ];
  66. var options = {};
  67. var timeline = new vis.Timeline(container, items, options);
  68. &lt;/script&gt;
  69. &lt;/body&gt;
  70. &lt;/html&gt;
  71. </pre>
  72. <h2 id="Loading">Loading</h2>
  73. <p>
  74. Install or download the <a href="http://visjs.org" target="_blank">vis.js</a> library.
  75. in a subfolder of your project. Include the libraries script and css files in the
  76. head of your html code:
  77. </p>
  78. <pre class="prettyprint lang-html">
  79. &lt;script src="vis/dist/vis.js"&gt;&lt;/script&gt;
  80. &lt;link href="vis/dist/vis.css" rel="stylesheet" type="text/css" /&gt;
  81. </pre>
  82. The constructor of the Timeline is <code>vis.Timeline</code>
  83. <pre class="prettyprint lang-js">var timeline = new vis.Timeline(container, items, options);</pre>
  84. The constructor accepts three parameters:
  85. <ul>
  86. <li>
  87. <code>container</code> is the DOM element in which to create the graph.
  88. </li>
  89. <li>
  90. <code>items</code> is an Array containing items. The properties of an
  91. item are described in section <a href="#Data_Format">Data Format</a>.
  92. </li>
  93. <li>
  94. <code>options</code> is an optional Object containing a name-value map
  95. with options. Options can also be set using the method
  96. <code>setOptions</code>.
  97. </li>
  98. </ul>
  99. <h2 id="Data_Format">Data Format</h2>
  100. <p>
  101. The timeline can be provided with two types of data:
  102. </p>
  103. <ul>
  104. <li><a href="#items">Items</a> containing a set of items to be displayed in time.</li>
  105. <li><a href="#groups">Groups</a> containing a set of groups used to group items
  106. together.</li>
  107. </ul>
  108. <h3 id="items">Items</h3>
  109. <p>
  110. The Timeline uses regular Arrays and Objects as data format.
  111. Data items can contain the properties <code>start</code>,
  112. <code>end</code> (optional), <code>content</code>,
  113. <code>group</code> (optional), and <code>className</code> (optional).
  114. </p>
  115. <p>
  116. A table is constructed as:
  117. </p>
  118. <pre class="prettyprint lang-js">
  119. var items = [
  120. {
  121. start: new Date(2010, 7, 15),
  122. end: new Date(2010, 8, 2), // end is optional
  123. content: 'Trajectory A'
  124. // Optional: fields 'id', 'type', 'group', 'className'
  125. }
  126. // more items...
  127. ]);
  128. </pre>
  129. <p>
  130. The item properties are defined as:
  131. </p>
  132. <table>
  133. <tr>
  134. <th>Name</th>
  135. <th>Type</th>
  136. <th>Required</th>
  137. <th>Description</th>
  138. </tr>
  139. <tr>
  140. <td>id</td>
  141. <td>String | Number</td>
  142. <td>no</td>
  143. <td>An id for the item. Using an id is not required but highly
  144. recommended. An id is needed when dynamically adding, updating,
  145. and removing items in a DataSet.</td>
  146. </tr>
  147. <tr>
  148. <td>start</td>
  149. <td>Date</td>
  150. <td>yes</td>
  151. <td>The start date of the item, for example <code>new Date(2010,09,23)</code>.</td>
  152. </tr>
  153. <tr>
  154. <td>end</td>
  155. <td>Date</td>
  156. <td>no</td>
  157. <td>The end date of the item. The end date is optional, and can be left <code>null</code>.
  158. If end date is provided, the item is displayed as a range.
  159. If not, the item is displayed as a box.</td>
  160. </tr>
  161. <tr>
  162. <td>content</td>
  163. <td>String</td>
  164. <td>yes</td>
  165. <td>The contents of the item. This can be plain text or html code.</td>
  166. </tr>
  167. <tr>
  168. <td>type</td>
  169. <td>String</td>
  170. <td>'box'</td>
  171. <td>The type of the item. Can be 'box' (default), 'range', or 'point'.
  172. <!-- TODO: describe rangeoverflow -->
  173. </td>
  174. </tr>
  175. <tr>
  176. <td>group</td>
  177. <td>any type</td>
  178. <td>no</td>
  179. <td>This field is optional. When the group column is provided,
  180. all items with the same group are placed on one line.
  181. A vertical axis is displayed showing the groups.
  182. Grouping items can be useful for example when showing availability of multiple
  183. people, rooms, or other resources next to each other.<br>
  184. </td>
  185. </tr>
  186. <tr>
  187. <td>className</td>
  188. <td>String</td>
  189. <td>no</td>
  190. <td>This field is optional. A className can be used to give items
  191. an individual css style. For example, when an item has className
  192. 'red', one can define a css style
  193. <code>
  194. .red {
  195. background-color: red;
  196. border-color: dark-red;
  197. }
  198. </code>.
  199. More details on how to style items can be found in the section
  200. <a href="#Styles">Styles</a>.
  201. </td>
  202. </tr>
  203. </table>
  204. <h3 id="groups">Groups</h3>
  205. <p>
  206. Like the items, groups are regular JavaScript Arrays and Objects.
  207. Using groups, items can be grouped together.
  208. Items are filtered per group, and displayed as
  209. Group items can contain the properties <code>id</code>,
  210. <code>content</code>, and <code>className</code> (optional).
  211. </p>
  212. <p>
  213. Groups can be applied to a timeline using the method <code>setGroups</code>.
  214. A table with groups can be created like:
  215. </p>
  216. <pre class="prettyprint lang-js">
  217. var groups = [
  218. {
  219. id: 1,
  220. content: 'Group 1'
  221. // Optional: a field 'className'
  222. }
  223. // more groups...
  224. ]);
  225. </pre>
  226. <p>
  227. Groups can have the following properties:
  228. </p>
  229. <table>
  230. <tr>
  231. <th>Name</th>
  232. <th>Type</th>
  233. <th>Required</th>
  234. <th>Description</th>
  235. </tr>
  236. <tr>
  237. <td>id</td>
  238. <td>String | Number</td>
  239. <td>yes</td>
  240. <td>An id for the group. The group will display all items having a
  241. property <code>group</code> which matches the <code>id</code>
  242. of the group.</td>
  243. </tr>
  244. <tr>
  245. <td>content</td>
  246. <td>String</td>
  247. <td>yes</td>
  248. <td>The contents of the group. This can be plain text or html code.</td>
  249. </tr>
  250. <tr>
  251. <td>className</td>
  252. <td>String</td>
  253. <td>no</td>
  254. <td>This field is optional. A className can be used to give groups
  255. an individual css style. For example, when a group has className
  256. 'red', one can define a css style
  257. <code>
  258. .red {
  259. color: red;
  260. }
  261. </code>.
  262. More details on how to style groups can be found in the section
  263. <a href="#Styles">Styles</a>.
  264. </td>
  265. </tr>
  266. </table>
  267. <h2 id="Configuration_Options">Configuration Options</h2>
  268. <p>
  269. Options can be used to customize the timeline.
  270. Options are defined as a JSON object. All options are optional.
  271. </p>
  272. <pre class="prettyprint lang-js">
  273. var options = {
  274. width: '100%',
  275. height: '30px'
  276. };
  277. </pre>
  278. <p>
  279. The following options are available.
  280. </p>
  281. <table>
  282. <tr>
  283. <th>Name</th>
  284. <th>Type</th>
  285. <th>Default</th>
  286. <th>Description</th>
  287. </tr>
  288. <tr>
  289. <td>align</td>
  290. <td>String</td>
  291. <td>"center"</td>
  292. <td>Alignment of items with type 'box'. Available values are
  293. 'center' (default), 'left', or 'right').</td>
  294. </tr>
  295. <tr>
  296. <td>autoResize</td>
  297. <td>boolean</td>
  298. <td>false</td>
  299. <td>If true, the Timeline will automatically detect when its
  300. container is resized, and redraw itself accordingly.</td>
  301. </tr>
  302. <tr>
  303. <td>end</td>
  304. <td>Date | Number | String</td>
  305. <td>none</td>
  306. <td>The initial end date for the axis of the timeline.
  307. If not provided, the latest date present in the items set is taken as
  308. end date.</td>
  309. </tr>
  310. <tr>
  311. <td>groupOrder</td>
  312. <td>String | Function</td>
  313. <td>none</td>
  314. <td>Order the groups by a field name or custom sort function.
  315. By default, groups are not ordered.
  316. </td>
  317. </tr>
  318. <tr>
  319. <td>height</td>
  320. <td>String</td>
  321. <td>none</td>
  322. <td>The height of the timeline in pixels or as a percentage.
  323. When height is undefined or null, the height of the timeline is automatically
  324. adjusted to fit the contents.
  325. It is possible to set a maximum height using option <code>maxHeight</code>
  326. to prevent the timeline from getting too high in case of automatically
  327. calculated height.
  328. </td>
  329. </tr>
  330. <tr>
  331. <td>margin.axis</td>
  332. <td>Number</td>
  333. <td>20</td>
  334. <td>The minimal margin in pixels between items and the time axis.</td>
  335. </tr>
  336. <tr>
  337. <td>margin.item</td>
  338. <td>Number</td>
  339. <td>10</td>
  340. <td>The minimal margin in pixels between items.</td>
  341. </tr>
  342. <tr>
  343. <td>max</td>
  344. <td>Date | Number | String</td>
  345. <td>none</td>
  346. <td>Set a maximum Date for the visible range.
  347. It will not be possible to move beyond this maximum.
  348. </td>
  349. </tr>
  350. <tr>
  351. <td>maxHeight</td>
  352. <td>Number</td>
  353. <td>none</td>
  354. <td>Specifies a maximum height for the Timeline in pixels.
  355. </td>
  356. </tr>
  357. <tr>
  358. <td>min</td>
  359. <td>Date | Number | String</td>
  360. <td>none</td>
  361. <td>Set a minimum Date for the visible range.
  362. It will not be possible to move beyond this minimum.
  363. </td>
  364. </tr>
  365. <tr>
  366. <td>order</td>
  367. <td>Function</td>
  368. <td>none</td>
  369. <td>Provide a custom sort function to order the items. The order of the
  370. items is determining the way they are stacked. The function
  371. order is called with two parameters, both of type
  372. `vis.components.items.Item`.
  373. </td>
  374. </tr>
  375. <tr>
  376. <td>orientation</td>
  377. <td>String</td>
  378. <td>'bottom'</td>
  379. <td>Orientation of the timeline: 'top' or 'bottom' (default).
  380. If orientation is 'bottom', the time axis is drawn at the bottom,
  381. and if 'top', the axis is drawn on top.</td>
  382. </tr>
  383. <tr>
  384. <td>padding</td>
  385. <td>Number</td>
  386. <td>5</td>
  387. <td>The padding of items, needed to correctly calculate the size
  388. of item ranges. Must correspond with the css of item ranges.</td>
  389. </tr>
  390. <tr>
  391. <td>showCurrentTime</td>
  392. <td>boolean</td>
  393. <td>false</td>
  394. <td>Show a vertical bar at the current time.</td>
  395. </tr>
  396. <tr>
  397. <td>showCustomTime</td>
  398. <td>boolean</td>
  399. <td>false</td>
  400. <td>Show a vertical bar displaying a custom time. This line can be dragged by the user. The custom time can be utilized to show a state in the past or in the future.
  401. <!-- TODO: more docs on showCustomTime
  402. When the custom time bar is dragged by the user, an event is triggered, on which the contents of the timeline can be changed in to the state at that moment in time.--></td>
  403. </tr>
  404. <tr>
  405. <tr>
  406. <td>showMajorLabels</td>
  407. <td>boolean</td>
  408. <td>true</td>
  409. <td>By default, the timeline shows both minor and major date labels on the
  410. time axis.
  411. For example the minor labels show minutes and the major labels show hours.
  412. When <code>showMajorLabels</code> is <code>false</code>, no major labels
  413. are shown.</td>
  414. </tr>
  415. <tr>
  416. <td>showMinorLabels</td>
  417. <td>boolean</td>
  418. <td>true</td>
  419. <td>By default, the timeline shows both minor and major date labels on the
  420. time axis.
  421. For example the minor labels show minutes and the major labels show hours.
  422. When <code>showMinorLabels</code> is <code>false</code>, no minor labels
  423. are shown. When both <code>showMajorLabels</code> and
  424. <code>showMinorLabels</code> are false, no horizontal axis will be
  425. visible.</td>
  426. </tr>
  427. <tr>
  428. <td>start</td>
  429. <td>Date | Number | String</td>
  430. <td>none</td>
  431. <td>The initial start date for the axis of the timeline.
  432. If not provided, the earliest date present in the events is taken as start date.</td>
  433. </tr>
  434. <tr>
  435. <td>type</td>
  436. <td>String</td>
  437. <td>'box'</td>
  438. <td>Specifies the type for the timeline items. Choose from 'dot' or 'point'.
  439. Note that individual items can override this global type.
  440. </td>
  441. </tr>
  442. <tr>
  443. <td>width</td>
  444. <td>String</td>
  445. <td>'100%'</td>
  446. <td>The width of the timeline in pixels or as a percentage.</td>
  447. </tr>
  448. <tr>
  449. <td>zoomMax</td>
  450. <td>Number</td>
  451. <td>315360000000000</td>
  452. <td>Set a maximum zoom interval for the visible range in milliseconds.
  453. It will not be possible to zoom out further than this maximum.
  454. Default value equals about 10000 years.
  455. </td>
  456. </tr>
  457. <tr>
  458. <td>zoomMin</td>
  459. <td>Number</td>
  460. <td>10</td>
  461. <td>Set a minimum zoom interval for the visible range in milliseconds.
  462. It will not be possible to zoom in further than this minimum.
  463. </td>
  464. </tr>
  465. </table>
  466. <h2 id="Methods">Methods</h2>
  467. <p>
  468. The Timeline supports the following methods.
  469. </p>
  470. <table>
  471. <tr>
  472. <th>Method</th>
  473. <th>Return Type</th>
  474. <th>Description</th>
  475. </tr>
  476. <tr>
  477. <td>getCustomTime()</td>
  478. <td>Date</td>
  479. <td>Retrieve the custom time. Only applicable when the option <code>showCustomTime</code> is true.
  480. </td>
  481. </tr>
  482. <tr>
  483. <td>setCustomTime(time)</td>
  484. <td>none</td>
  485. <td>Adjust the custom time bar. Only applicable when the option <code>showCustomTime</code> is true. <code>time</code> is a Date object.
  486. </td>
  487. </tr>
  488. <tr>
  489. <td>getSelection()</td>
  490. <td>ids</td>
  491. <td>Get an array with the ids of the currently selected items.</td>
  492. </tr>
  493. <tr>
  494. <td>on(event, callback)</td>
  495. <td>none</td>
  496. <td>Create an event listener. The callback function is invoked every time the event is triggered. Avialable events: <code>rangechange</code>, <code>rangechanged</code>, <code>select</code>. The callback function is invoked as <code>callback(properties)</code>, where <code>properties</code> is an object containing event specific properties. See section <a href="#Events">Events for more information</a>.</td>
  497. </tr>
  498. <tr>
  499. <td>off(event, callback)</td>
  500. <td>none</td>
  501. <td>Remove an event listener created before via function <code>on(event, callback)</code>. See section <a href="#Events">Events for more information</a>.</td>
  502. </tr>
  503. <tr>
  504. <td>setGroups(groups)</td>
  505. <td>none</td>
  506. <td>Set a data set with groups for the Timeline.
  507. <code>groups</code> can be an Array with Objects,
  508. a DataSet, or a DataView. For each of the groups, the items of the
  509. timeline are filtered on the property <code>group</code>, which
  510. must correspond with the id of the group.
  511. </td>
  512. </tr>
  513. <tr>
  514. <td>setItems(items)</td>
  515. <td>none</td>
  516. <td>Set a data set with items for the Timeline.
  517. <code>items</code> can be an Array with Objects,
  518. a DataSet, or a DataView.
  519. </td>
  520. </tr>
  521. <tr>
  522. <td>setOptions(options)</td>
  523. <td>none</td>
  524. <td>Set or update options. It is possible to change any option of the timeline at any time. You can for example switch orientation on the fly.
  525. </td>
  526. </tr>
  527. <tr>
  528. <td>setSelection([ids])</td>
  529. <td>none</td>
  530. <td>Select or deselect items. Currently selected items will be unselected.
  531. </td>
  532. </tr>
  533. </table>
  534. <h2 id="Events">Events</h2>
  535. <p>
  536. Timeline fires events when changing the visible window by dragging, or when
  537. selecting items.
  538. </p>
  539. <p>
  540. Here an example on how to listen for a <code>select</code> event.
  541. </p>
  542. <pre class="prettyprint lang-js">
  543. timeline.on('select', function (properties) {
  544. alert('selected items: ' + properties.nodes);
  545. });
  546. </pre>
  547. <p>
  548. A listener can be removed via the function <code>off</code>:
  549. </p>
  550. <pre class="prettyprint lang-js">
  551. function onSelect (properties) {
  552. alert('selected items: ' + properties.nodes);
  553. }
  554. // add event listener
  555. timeline.on('select', onSelect);
  556. // do stuff...
  557. // remove event listener
  558. timeline.off('select', onSelect);
  559. </pre>
  560. <p>
  561. The following events are available.
  562. </p>
  563. <table>
  564. <colgroup>
  565. <col style="width: 20%;">
  566. <col style="width: 40%;">
  567. <col style="width: 40%;">
  568. </colgroup>
  569. <tr>
  570. <th>name</th>
  571. <th>Description</th>
  572. <th>Properties</th>
  573. </tr>
  574. <tr>
  575. <td>rangechange</td>
  576. <td>Fired repeatedly when the user is dragging the timeline window.
  577. </td>
  578. <td>
  579. <ul>
  580. <li><code>start</code> (Number): timestamp of the current start of the window.</li>
  581. <li><code>end</code> (Number): timestamp of the current end of the window.</li>
  582. </ul>
  583. </td>
  584. </tr>
  585. <tr>
  586. <td>rangechanged</td>
  587. <td>Fired once after the user has dragging the timeline window.
  588. </td>
  589. <td>
  590. <ul>
  591. <li><code>start</code> (Number): timestamp of the current start of the window.</li>
  592. <li><code>end</code> (Number): timestamp of the current end of the window.</li>
  593. </ul>
  594. </td>
  595. </tr>
  596. <tr>
  597. <td>select</td>
  598. <td>Fired after the user selects or deselects items by tapping or holding them.
  599. Not fired when the method <code>setSelection</code>is executed.
  600. </td>
  601. <td>
  602. <ul>
  603. <li><code>items</code>: an array with the ids of the selected items</li>
  604. </ul>
  605. </td>
  606. </tr>
  607. </table>
  608. <h2 id="Styles">Styles</h2>
  609. <p>
  610. All parts of the Timeline have a class name and a default css style.
  611. The styles can be overwritten, which enables full customization of the layout
  612. of the Timeline.
  613. </p>
  614. <p>For example, to change the border and background color of all items, include the
  615. following code inside the head of your html code or in a separate stylesheet.</p>
  616. <pre class="prettyprint lang-html">&lt;style&gt;
  617. .graph .item {
  618. border-color: orange;
  619. background-color: yellow;
  620. }
  621. &lt;/style&gt;
  622. </pre>
  623. <h2 id="Data_Policy">Data Policy</h2>
  624. <p>
  625. All code and data is processed and rendered in the browser.
  626. No data is sent to any server.
  627. </p>
  628. </div>
  629. </body>
  630. </html>