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.

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