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.

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