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.

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