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.

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