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.

1186 lines
36 KiB

10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
9 years ago
9 years ago
10 years ago
  1. <html>
  2. <head>
  3. <title>vis.js | Graph2d documentation</title>
  4. <style>
  5. td.greenField {
  6. background-color: #c9ffc7;
  7. }
  8. </style>
  9. <link href='css/prettify.css' type='text/css' rel='stylesheet'>
  10. <link href='css/style.css' type='text/css' rel='stylesheet'>
  11. <script type="text/javascript" src="lib/prettify/prettify.js"></script>
  12. </head>
  13. <body onload="prettyPrint();">
  14. <div id="container">
  15. <h1>Graph2d documentation</h1>
  16. <h2 id="Overview">Overview</h2>
  17. <p>
  18. Graph2d is an interactive visualization chart to draw data in a 2D graph.
  19. You can freely move and zoom in the graph by dragging and scrolling in the
  20. window.
  21. </p>
  22. <p>
  23. Graph2d uses HTML DOM and SVG for rendering. This allows for flexible
  24. customization using css styling.
  25. </p>
  26. <h2 id="Contents">Contents</h2>
  27. <ul>
  28. <li><a href="#Overview">Overview</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>
  37. <ul>
  38. <li><a href="#graph2dOptions">Graph2d options</a></li>
  39. <li><a href="#timelineOptions">Timeline options</a></li>
  40. </ul>
  41. </li>
  42. <li><a href="#Methods">Methods</a></li>
  43. <li><a href="#Events">Events</a></li>
  44. <li><a href="#Localization">Localization</a></li>
  45. <li><a href="#Styles">Styles</a></li>
  46. <li><a href="#Data_Policy">Data Policy</a></li>
  47. </ul>
  48. <h2 id="Example">Example</h2>
  49. <p>
  50. The following code shows how to create a Graph2d and provide it with data.
  51. More examples can be found in the <a href="../examples">examples</a> directory.
  52. </p>
  53. <pre class="prettyprint lang-html">
  54. &lt;!DOCTYPE HTML&gt;
  55. &lt;html&gt;
  56. &lt;head&gt;
  57. &lt;title&gt;Graph2d | Basic Example&lt;/title&gt;
  58. &lt;style type="text/css"&gt;
  59. body, html {
  60. font-family: sans-serif;
  61. }
  62. &lt;/style&gt;
  63. &lt;script src="../../dist/vis.js"&gt;&lt;/script&gt;
  64. &lt;link href="../../dist/vis.css" rel="stylesheet" type="text/css" /&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. {x: '2014-06-11', y: 10},
  72. {x: '2014-06-12', y: 25},
  73. {x: '2014-06-13', y: 30},
  74. {x: '2014-06-14', y: 10},
  75. {x: '2014-06-15', y: 15},
  76. {x: '2014-06-16', y: 30}
  77. ];
  78. var dataset = new vis.DataSet(items);
  79. var options = {
  80. start: '2014-06-10',
  81. end: '2014-06-18'
  82. };
  83. var Graph2d = new vis.Graph2d(container, dataset, options);
  84. &lt;/script&gt;
  85. &lt;/body&gt;
  86. &lt;/html&gt;
  87. </pre>
  88. <h2 id="Loading">Loading</h2>
  89. <p>
  90. The class name of the Graph2d is <code>vis.Graph2d</code>.
  91. When constructing a Graph2d, an HTML DOM container must be provided to attach
  92. the graph to. Optionally, data an options can be provided.
  93. Data is a vis <code>DataSet</code> or an <code>Array</code>, described in
  94. section <a href="#Data_Format">Data Format</a>.
  95. Options is a name-value map in the JSON format. The available options
  96. are described in section <a href="#Configuration_Options">Configuration Options</a>.
  97. Groups is a vis <code>DataSet</code> containing groups. The available options and the method of construction
  98. are described in section <a href="#Group_Options">Data Format</a>.
  99. </p>
  100. <pre class="prettyprint lang-js">var graph = new vis.Graph2d(container [, data] [, groups] [, options]);</pre>
  101. For backwards compatibility, groups and options can be interchanged.
  102. <p>
  103. Data, options and groups can be set or changed later on using the functions
  104. <code>Graph2d.setItems(data)</code>, <code>Graph2d.setOptions(options)</code> and <code>Graph2d.setGroups(groups)</code>.
  105. </p>
  106. <h2 id="Data_Format">Data Format</h2>
  107. <p>
  108. Graph2d can load data from an <code>Array</code>, a <code>DataSet</code> or a <code>DataView</code>.
  109. JSON objects are added to this DataSet by using the <code>add()</code> function.
  110. Data points must have properties <code>x</code>, <code>y</code>, and <code>z</code>,
  111. and can optionally have a property <code>style</code> and <code>filter</code>.
  112. <p>
  113. Graph2d can be provided with two types of data:
  114. </p>
  115. <ul>
  116. <li><a href="#items">Items</a> containing a set of points to be displayed.</li>
  117. <li><a href="#groups">Groups</a> containing a set of groups used to group items
  118. together. All items belonging to a group will be drawn as a single graph.</li>
  119. </ul>
  120. <h3 id="items">Items</h3>
  121. <pre class="prettyprint lang-js">
  122. var items = [
  123. {x: '2014-06-13', y: 30, group: 0},
  124. {x: '2014-06-14', y: 10, group: 0},
  125. {x: '2014-06-15', y: 15, group: 1},
  126. {x: '2014-06-16', y: 30, group: 1},
  127. {x: '2014-06-17', y: 10, group: 1},
  128. {x: '2014-06-18', y: 15, group: 1}
  129. ];
  130. </pre>
  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>x</td>
  140. <td>number</td>
  141. <td>yes</td>
  142. <td>Location on the x-axis.</td>
  143. </tr>
  144. <tr>
  145. <td>y</td>
  146. <td>number</td>
  147. <td>yes</td>
  148. <td>Location on the y-axis.</td>
  149. </tr>
  150. </tr>
  151. <tr>
  152. <td>group</td>
  153. <td>number | string</td>
  154. <td>no</td>
  155. <td>The ID of the group this point belongs to.</td>
  156. </tr>
  157. <tr>
  158. <td>label</td>
  159. <td>object</td>
  160. <td>no</td>
  161. <td>A label object which will be displayed near to the item. A label object has one requirement - a <b> content </b> property. In addition you can set the <b> xOffset, yOffset and className </b> for further appearance customisations </td>
  162. </tr>
  163. </table>
  164. <h3 id="groups">Groups</h3>
  165. <p>
  166. Like the items, groups are regular JavaScript Arrays and Objects.
  167. Using groups, items can be grouped together.
  168. Items are filtered per group, and displayed as individual graphs. Groups can contain the properties <code>id</code>,
  169. <code>content</code>, <code>className</code> (optional) and <code>options</code> (optional).
  170. </p>
  171. <p>
  172. Groups can be applied to a timeline using the method <code>setGroups</code>.
  173. A table with groups can be created like:
  174. </p>
  175. <pre class="prettyprint lang-js">
  176. var groups = new vis.DataSet();
  177. groups.add({
  178. id: 1,
  179. content: 'Group 1',
  180. // Optional: a field 'visible'
  181. // Optional: a field 'className'
  182. // Optional: options
  183. })
  184. groups.add({
  185. // more groups...
  186. });
  187. </pre>
  188. <p>
  189. Groups can have the following properties:
  190. </p>
  191. <table>
  192. <tr>
  193. <th>Name</th>
  194. <th>Type</th>
  195. <th>Required</th>
  196. <th>Description</th>
  197. </tr>
  198. <tr>
  199. <td>id</td>
  200. <td>String | Number</td>
  201. <td>yes</td>
  202. <td>An id for the group. The group will display all items having a
  203. property <code>group</code> which matches the <code>id</code>
  204. of the group.</td>
  205. </tr>
  206. <tr>
  207. <td>content</td>
  208. <td>String</td>
  209. <td>yes</td>
  210. <td>The contents of the group. This can be plain text or html code.</td>
  211. </tr>
  212. <tr>
  213. <td>className</td>
  214. <td>String</td>
  215. <td>no</td>
  216. <td>This field is optional. A className can be used to give groups
  217. an individual css style.
  218. </td>
  219. </tr>
  220. <tr>
  221. <td>style</td>
  222. <td>String</td>
  223. <td>no</td>
  224. <td>This field is optional. A style can be used to give groups
  225. an individual css style, and any style tags specified in style will
  226. override the definition in the className style defined in css.
  227. </td>
  228. </tr>
  229. <tr>
  230. <td>options</td>
  231. <td>JSON object</td>
  232. <td>no</td>
  233. <td>This field is optional. The options can be used to give a group a specific draw style.
  234. Any options that are colored green in the Configuration Options can be used as options here.
  235. </tr>
  236. <tr>
  237. <td>visible</td>
  238. <td>Boolean</td>
  239. <td>true</td>
  240. <td>This field is optional. If false, this group will not be drawn.
  241. </tr>
  242. </table>
  243. <h2 id="Configuration_Options">Configuration Options</h2>
  244. <h3 id="graph2dOptions">Graph2d Options</h3>
  245. Options can be used to customize the Graph2d to your purposes. These options can be passed to the Graph2d object either in
  246. the constructor, or by the <code>setOptions</code> function.
  247. <pre class="prettyprint lang-js">
  248. var options = {
  249. width: '100%',
  250. height: '400px',
  251. style: 'surface'
  252. };
  253. </pre>
  254. The options colored in green can also be used as options for the groups. All options are optional.
  255. <table>
  256. <tr>
  257. <th>Name</th>
  258. <th>Type</th>
  259. <th>Default</th>
  260. <th>Description</th>
  261. </tr>
  262. <tr>
  263. <td class="greenField">yAxisOrientation</td>
  264. <td>String</td>
  265. <td>'left'</td>
  266. <td>This defines with which axis, left or right, the graph is coupled. <a href="../examples/graph2d/05_bothAxis.html">Example 5</a> shows groups with different Y axis. If no groups are coupled
  267. with an axis, it will not be shown.</td>
  268. </tr>
  269. <tr>
  270. <td>defaultGroup</td>
  271. <td>String</td>
  272. <td>'default'</td>
  273. <td>This is the label for the default, ungrouped items when shown in a legend.</td>
  274. </tr>
  275. <tr>
  276. <td class="greenField">sort</td>
  277. <td>Boolean</td>
  278. <td>true</td>
  279. <td>This determines if the items are sorted automatically.
  280. They are sorted by the x value. If sort is enabled, more optimizations are possible, increasing the performance.</td>
  281. </tr>
  282. <tr>
  283. <td class="greenField">sampling</td>
  284. <td>Boolean</td>
  285. <td>true</td>
  286. <td>If sampling is enabled, Graph2d will automatically determine the amount of points per pixel.
  287. If there are more than 1 point per pixel, not all points will be drawn. Disabling sampling will cause a decrease in performance.</td>
  288. </tr>
  289. <tr>
  290. <td>graphHeight</td>
  291. <td>Number | String</td>
  292. <td>'400px'</td>
  293. <td>This is the height of the graph SVG canvas.
  294. If it is larger than the height of the outer frame, you can drag up and down
  295. the vertical direction as well as the usual horizontal direction.</td>
  296. </tr>
  297. <tr>
  298. <td class="greenField">shaded</td>
  299. <td>Boolean | Object</td>
  300. <td>false</td>
  301. <td>Toggle a shaded area with the default settings.</td>
  302. </tr>
  303. <tr>
  304. <td class="greenField">shaded.enabled</td>
  305. <td>Boolean</td>
  306. <td>false</td>
  307. <td>This toggles the shading.</td>
  308. </tr>
  309. <tr>
  310. <td class="greenField">shaded.orientation</td>
  311. <td>String</td>
  312. <td>'bottom'</td>
  313. <td>This determines if the shaded area is at the bottom or at the top of the curve. The options are 'bottom' or 'top'.</td>
  314. </tr>
  315. <tr>
  316. <td class="greenField">shaded.style</td>
  317. <td>String</td>
  318. <td>undefined</td>
  319. <td>Set the style for the shading. This is a css string and it will override the attributes set in the class.</td>
  320. </tr>
  321. <tr>
  322. <td class="greenField">style</td>
  323. <td>String</td>
  324. <td>'line'</td>
  325. <td>This allows the user to define if this should be a linegraph, barchart or pointcloud. The options are: 'line', 'bar', 'points'.</td>
  326. </tr>
  327. <tr>
  328. <td class="greenField">barChart.width</td>
  329. <td>Number</td>
  330. <td>50</td>
  331. <td>The width of the bars.</td>
  332. </tr>
  333. <tr>
  334. <td class="greenField">barChart.align</td>
  335. <td>String</td>
  336. <td>'center'</td>
  337. <td>The alignment of the bars with regards to the coordinate. The options are 'left', 'right' or 'center'.</td>
  338. </tr>
  339. <tr>
  340. <td class="greenField">barChart.handleOverlap</td>
  341. <td>String</td>
  342. <td>'overlap'</td>
  343. <td>You can choose how graph2d handles the case where barcharts are occupying the same datapoint. The possible options are:
  344. <code>overlap, sideBySide, stack</code>.
  345. See <a href="../examples/graph2d/10_barsSideBySide.html">example 10</a> for more information.
  346. When using groups, see <a href="../examples/graph2d/11_barsSideBySideGroups.html">example 11</a>.
  347. </td>
  348. </tr>
  349. <tr>
  350. <td class="greenField">catmullRom</td>
  351. <td>Boolean | Object</td>
  352. <td>true</td>
  353. <td>Toggle the interpolation with the default settings. For more customization use the JSON format.</td>
  354. </tr>
  355. <tr>
  356. <td class="greenField">catmullRom.enabled</td>
  357. <td>Boolean</td>
  358. <td>true</td>
  359. <td>Toggle the interpolation.</td>
  360. </tr>
  361. <tr>
  362. <td class="greenField">catmullRom.parametrization</td>
  363. <td>String</td>
  364. <td>'centripetal'</td>
  365. <td>Define the type of parametrizaion. <a href="../examples/graph2d/07_scrollingAndSorting.html">Example 7</a> shows the different methods. The options are 'centripetal' (best results), 'chordal' and 'uniform'. Uniform is the computationally cheapest variant.
  366. If catmullRom is disabled, linear interpolation is used.</td>
  367. </tr>
  368. <tr>
  369. <td class="greenField">drawPoints</td>
  370. <td>Boolean | Object</td>
  371. <td>true</td>
  372. <td>Toggle the drawing of the datapoints with the default settings.</td>
  373. </tr>
  374. <tr>
  375. <td class="greenField">drawPoints.enabled</td>
  376. <td>Boolean</td>
  377. <td>true</td>
  378. <td>Toggle the drawing of the datapoints.</td>
  379. </tr>
  380. <tr>
  381. <td class="greenField">drawPoints.size</td>
  382. <td>Number</td>
  383. <td>6</td>
  384. <td>Determine the size at which the data points are drawn.</td>
  385. </tr>
  386. <tr>
  387. <td class="greenField">drawPoints.style</td>
  388. <td>String</td>
  389. <td>'square'</td>
  390. <td>Determine the shape of the data points. The options are 'square' or 'circle'.</td>
  391. </tr>
  392. <tr>
  393. <td>dataAxis.customRange.left.min</td>
  394. <td>Number</td>
  395. <td>undefined</td>
  396. <td>Set the minimum value of the left y-Axis.</td>
  397. </tr>
  398. <tr>
  399. <td>dataAxis.customRange.left.max</td>
  400. <td>Number</td>
  401. <td>undefined</td>
  402. <td>Set the maximum value of the left y-Axis.</td>
  403. </tr>
  404. <tr>
  405. <td>dataAxis.customRange.right.min</td>
  406. <td>Number</td>
  407. <td>undefined</td>
  408. <td>Set the minimum value of the right y-Axis.</td>
  409. </tr>
  410. <tr>
  411. <td>dataAxis.customRange.right.max</td>
  412. <td>Number</td>
  413. <td>undefined</td>
  414. <td>Set the maximum value of the right y-Axis.</td>
  415. </tr>
  416. <tr>
  417. <td>dataAxis.showMinorLabels</td>
  418. <td>Boolean</td>
  419. <td>true</td>
  420. <td>Toggle the drawing of the minor labels on the Y axis.</td>
  421. </tr>
  422. <tr>
  423. <td>dataAxis.showMajorLabels</td>
  424. <td>Boolean</td>
  425. <td>true</td>
  426. <td>Toggle the drawing of the major labels on the Y axis.</td>
  427. </tr>
  428. <tr>
  429. <td>dataAxis.icons</td>
  430. <td>Boolean</td>
  431. <td>false</td>
  432. <td>Toggle the drawing of automatically generated icons the Y axis.</td>
  433. </tr>
  434. <tr>
  435. <td>dataAxis.width</td>
  436. <td>Number | String</td>
  437. <td>'40px'</td>
  438. <td>Set the (minimal) width of the yAxis. The axis will resize to accomodate the labels of the Y values.</td>
  439. </tr>
  440. <tr>
  441. <td>dataAxis.visible</td>
  442. <td>Boolean</td>
  443. <td>true</td>
  444. <td>Show or hide the data axis.</td>
  445. </tr>
  446. <tr>
  447. <td>dataAxis.title.left.text</td>
  448. <td>String</td>
  449. <td>undefined</td>
  450. <td>Set the title for the left axis.</td>
  451. </tr>
  452. <tr>
  453. <td>dataAxis.title.left.style</td>
  454. <td>String</td>
  455. <td>undefined</td>
  456. <td>Set the title style for the left axis. This is a css string and it will override the attributes set in the class.</td>
  457. </tr>
  458. <tr>
  459. <td>dataAxis.title.right.text</td>
  460. <td>String</td>
  461. <td>undefined</td>
  462. <td>Set the title for the right axis.</td>
  463. </tr>
  464. <tr>
  465. <td>dataAxis.title.right.style</td>
  466. <td>String</td>
  467. <td>undefined</td>
  468. <td>Set the title style for the right axis. This is a css string and it will override the attributes set in the class.</td>
  469. </tr>
  470. <tr>
  471. <td>dataAxis.format.left.decimals</td>
  472. <td>Number</td>
  473. <td>undefined</td>
  474. <td>Set the number of decimal points used on the the left axis. If set, this will fix the number of decimal places
  475. displayed after the decimal point.
  476. If undefined, trailing zeros will be removed.</td>
  477. </tr>
  478. <tr>
  479. <td>dataAxis.format.right.decimals</td>
  480. <td>Number</td>
  481. <td>undefined</td>
  482. <td>Set the number of decimal points used on the the right axis. If set, this will fix the number of decimal places
  483. displayed after the decimal point.
  484. If undefined, trailing zeros will be removed.</td>
  485. </tr>
  486. <tr>
  487. <td>dataAxis.alignZeros</td>
  488. <td>Boolean</td>
  489. <td>true</td>
  490. <td>When using multiple axis, the right one is slaved to the left one. If you need to ensure that the zero-lines are on the same
  491. height, you can turn this option on.</td>
  492. </tr>
  493. <tr>
  494. <td>groups.visibility</td>
  495. <td>Object</td>
  496. <td></td>
  497. <td>You can use this to toggle the visibility of groups per graph2D instance. This is different from setting the visibility flag of the groups since
  498. this is not communicated across instances of graph2d. Take a look at <a href="../examples/graph2d/14_toggleGroups.html">Example 14</a>
  499. for more explanation.
  500. </td>
  501. </tr>
  502. <tr>
  503. <td>legend</td>
  504. <td>Boolean</td>
  505. <td>false</td>
  506. <td>Toggle the legend with the default settings.</td>
  507. </tr>
  508. <tr>
  509. <td>legend.enabled</td>
  510. <td>Boolean</td>
  511. <td>false</td>
  512. <td>Toggle the legend.</td>
  513. </tr>
  514. <tr>
  515. <td>legend.icons</td>
  516. <td>Boolean</td>
  517. <td>true</td>
  518. <td>Show automatically generated icons on the legend.</td>
  519. </tr>
  520. <tr>
  521. <td>legend.left.visible</td>
  522. <td>Boolean</td>
  523. <td>true</td>
  524. <td>Both axis, left and right, have a corresponding legend. This toggles the visibility of the legend that is coupled with the left axis.</td>
  525. </tr>
  526. <tr>
  527. <td>legend.left.position</td>
  528. <td>String</td>
  529. <td>'top-left'</td>
  530. <td>Determine the position of the legend coupled to the left axis. Options are 'top-left', 'top-right', 'bottom-left' or 'bottom-right'.</td>
  531. </tr>
  532. <tr>
  533. <td>legend.right.visible</td>
  534. <td>Boolean</td>
  535. <td>true</td>
  536. <td>This toggles the visibility of the legend that is coupled with the right axis.</td>
  537. </tr>
  538. <tr>
  539. <td>legend.right.position</td>
  540. <td>String</td>
  541. <td>'top-right'</td>
  542. <td>Determine the position of the legend coupled to the right axis. Options are 'top-left', 'top-right', 'bottom-left' or 'bottom-right'.</td>
  543. </tr>
  544. </table>
  545. <h3 id="timelineOptions">Timeline Options</h3>
  546. <p>
  547. Graph2d is built upon the framework of the timeline. These options from the timeline can be used with graph2D.
  548. All options are optional.
  549. </p>
  550. <table>
  551. <tr>
  552. <th>Name</th>
  553. <th>Type</th>
  554. <th>Default</th>
  555. <th>Description</th>
  556. </tr>
  557. <tr>
  558. <td>autoResize</td>
  559. <td>boolean</td>
  560. <td>true</td>
  561. <td>If true, the Timeline will automatically detect when its container is resized, and redraw itself accordingly. If false, the Timeline can be forced to repaint after its container has been resized using the function <code>redraw()</code>.</td>
  562. </tr>
  563. <tr>
  564. <td>clickToUse</td>
  565. <td>boolean</td>
  566. <td>false</td>
  567. <td>When a Graph2d is configured to be <code>clickToUse</code>, it will react to mouse and touch events only when active.
  568. When active, a blue shadow border is displayed around the Graph2d. The Graph2d is set active by clicking on it, and is changed to inactive again by clicking outside the Graph2d or by pressing the ESC key.</td>
  569. </tr>
  570. <tr>
  571. <td>end</td>
  572. <td>Date | Number | String</td>
  573. <td>none</td>
  574. <td>The initial end date for the axis of the timeline.
  575. If not provided, the latest date present in the items set is taken as
  576. end date.</td>
  577. </tr>
  578. <tr>
  579. <td>height</td>
  580. <td>Number | String</td>
  581. <td>none</td>
  582. <td>The height of the timeline in pixels or as a percentage.
  583. When height is undefined or null, the height of the timeline is automatically
  584. adjusted to fit the contents.
  585. It is possible to set a maximum height using option <code>maxHeight</code>
  586. to prevent the timeline from getting too high in case of automatically
  587. calculated height.
  588. </td>
  589. </tr>
  590. <tr>
  591. <td>locale</td>
  592. <td>String</td>
  593. <td>none</td>
  594. <td>Select a locale for the Graph2d. See section <a href="timeline.html#Localization">Localization</a> for more information.</td>
  595. </tr>
  596. <tr>
  597. <td>locales</td>
  598. <td>Object</td>
  599. <td>none</td>
  600. <td>A map with i18n locales. See section <a href="timeline.html#Localization">Localization</a> for more information.</td>
  601. </tr>
  602. <tr>
  603. <td>max</td>
  604. <td>Date | Number | String</td>
  605. <td>none</td>
  606. <td>Set a maximum Date for the visible range.
  607. It will not be possible to move beyond this maximum.
  608. </td>
  609. </tr>
  610. <tr>
  611. <td>maxHeight</td>
  612. <td>Number | String</td>
  613. <td>none</td>
  614. <td>Specifies the maximum height for the Timeline. Can be a number in pixels or a string like "300px".</td>
  615. </tr>
  616. <tr>
  617. <td>min</td>
  618. <td>Date | Number | String</td>
  619. <td>none</td>
  620. <td>Set a minimum Date for the visible range.
  621. It will not be possible to move beyond this minimum.
  622. </td>
  623. </tr>
  624. <tr>
  625. <td>minHeight</td>
  626. <td>Number | String</td>
  627. <td>none</td>
  628. <td>Specifies the minimum height for the Timeline. Can be a number in pixels or a string like "300px".</td>
  629. </tr>
  630. <tr>
  631. <td>orientation</td>
  632. <td>String</td>
  633. <td>'bottom'</td>
  634. <td>Orientation of the timeline: 'top', 'bottom' (default), or 'both'. If orientation is 'bottom', the time axis is drawn at the bottom. When 'top', the axis is drawn on top. When 'both', two axes are drawn, both on top and at the bottom.</td>
  635. </tr>
  636. <tr>
  637. <td>showCurrentTime</td>
  638. <td>boolean</td>
  639. <td>true</td>
  640. <td>Show a vertical bar at the current time.</td>
  641. </tr>
  642. <tr>
  643. <td>showCustomTime</td>
  644. <td>boolean</td>
  645. <td>false</td>
  646. <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. When the custom time bar is dragged by the user, the event <code>timechange</code> is fired repeatedly. After the bar is dragged, the event <code>timechanged</code> is fired once.</td>
  647. </tr>
  648. <tr>
  649. <td>showMajorLabels</td>
  650. <td>boolean</td>
  651. <td>true</td>
  652. <td>By default, the timeline shows both minor and major date labels on the
  653. time axis.
  654. For example the minor labels show minutes and the major labels show hours.
  655. When <code>showMajorLabels</code> is <code>false</code>, no major labels
  656. are shown.</td>
  657. </tr>
  658. <tr>
  659. <td>showMinorLabels</td>
  660. <td>boolean</td>
  661. <td>true</td>
  662. <td>By default, the timeline shows both minor and major date labels on the
  663. time axis.
  664. For example the minor labels show minutes and the major labels show hours.
  665. When <code>showMinorLabels</code> is <code>false</code>, no minor labels
  666. are shown. When both <code>showMajorLabels</code> and
  667. <code>showMinorLabels</code> are false, no horizontal axis will be
  668. visible.</td>
  669. </tr>
  670. <tr>
  671. <td>showMajorLines</td>
  672. <td>boolean</td>
  673. <td>true</td>
  674. <td>By default, the timeline shows both minor and major date lines on the
  675. time axis. You can use this option to hide the lines from the major dates.
  676. </tr>
  677. <tr>
  678. <td>showMinorLines</td>
  679. <td>boolean</td>
  680. <td>true</td>
  681. <td>By default, the timeline shows both minor and major date lines on the
  682. time axis. You can use this option to hide the lines from the minor dates.
  683. </tr>
  684. <tr>
  685. <td>start</td>
  686. <td>Date | Number | String</td>
  687. <td>none</td>
  688. <td>The initial start date for the axis of the timeline.
  689. If not provided, the earliest date present in the events is taken as start date.</td>
  690. </tr>
  691. <tr>
  692. <td>timeAxis.scale</td>
  693. <td>string</td>
  694. <td>none</td>
  695. <td>Set a fixed scale for the time axis of the Timeline. Choose from <code>'millisecond'</code>, <code>'second'</code>, <code>'minute'</code>, <code>'hour'</code>, <code>'weekday'</code>, <code>'day'</code>, <code>'month'</code>, <code>'year'</code>.</td>
  696. </tr>
  697. <tr>
  698. <td>timeAxis.step</td>
  699. <td>number</td>
  700. <td>1</td>
  701. <td>
  702. Set a fixed step size for the time axis. Only applicable when used together with <code>timeAxis.scale</code>.
  703. Choose for example 1, 2, 5, or 10.</td>
  704. </tr>
  705. <tr>
  706. <td>width</td>
  707. <td>String</td>
  708. <td>'100%'</td>
  709. <td>The width of the timeline in pixels or as a percentage.</td>
  710. </tr>
  711. <tr>
  712. <td>zoomMax</td>
  713. <td>Number</td>
  714. <td>315360000000000</td>
  715. <td>Set a maximum zoom interval for the visible range in milliseconds.
  716. It will not be possible to zoom out further than this maximum.
  717. Default value equals about 10000 years.
  718. </td>
  719. </tr>
  720. <tr>
  721. <td>zoomMin</td>
  722. <td>Number</td>
  723. <td>10</td>
  724. <td>Set a minimum zoom interval for the visible range in milliseconds.
  725. It will not be possible to zoom in further than this minimum.
  726. </td>
  727. </tr>
  728. </table>
  729. <h2 id="Methods">Methods</h2>
  730. <p>
  731. The Graph2d supports the following methods.
  732. </p>
  733. <table>
  734. <tr>
  735. <th>Method</th>
  736. <th>Return Type</th>
  737. <th>Description</th>
  738. </tr>
  739. <tr>
  740. <td>clear([what])</td>
  741. <td>none</td>
  742. <td>
  743. Clear the Graph2d. An object can be passed specifying which sections to clear: items, groups,
  744. and/or options. By Default, items, groups and options are cleared, i.e. <code>what = {items: true, groups: true, options: true}</code>. Example usage:
  745. <pre class="prettyprint lang-js">Graph2d.clear(); // clear items, groups, and options
  746. Graph2d.clear({options: true}); // clear options only
  747. </pre>
  748. </td>
  749. </tr>
  750. <tr>
  751. <td>click</td>
  752. <td>Fired when clicked inside the Graph2d.
  753. </td>
  754. <td>
  755. Passes a properties object as returned by the method <a href="#getEventProperties"><code>Graph2d.getEventProperties(event)</code></a>.
  756. </td>
  757. </tr>
  758. <tr>
  759. <td>contextmenu</td>
  760. <td>Fired when right-clicked inside the Graph2d. Note that in order to prevent the context menu from showing up, default behavior of the event must be stopped:
  761. <pre class="prettyprint lang-js">graph2d.on('contextmenu', function (props) {
  762. alert('Right click!');
  763. props.event.preventDefault();
  764. });
  765. </pre>
  766. </td>
  767. <td>
  768. Passes a properties object as returned by the method <a href="#getEventProperties"><code>Graph2d.getEventProperties(event)</code></a>.
  769. </td>
  770. </tr>
  771. <tr>
  772. <td>destroy()</td>
  773. <td>none</td>
  774. <td>Destroy the Graph2d. The Graph2d is removed from memory. all DOM elements and event listeners are cleaned up.
  775. </td>
  776. </tr>
  777. <tr>
  778. <td>doubleClick</td>
  779. <td>Fired when double clicked inside the Graph2d.
  780. </td>
  781. <td>
  782. Passes a properties object as returned by the method <a href="#getEventProperties"><code>Graph2d.getEventProperties(event)</code></a>.
  783. </td>
  784. </tr>
  785. <tr>
  786. <td>fit()</td>
  787. <td>none</td>
  788. <td>Adjust the visible window such that it fits all items.
  789. </td>
  790. </tr>
  791. <tr>
  792. <td>getCurrentTime()</td>
  793. <td>Date</td>
  794. <td>Get the current time. Only applicable when option <code>showCurrentTime</code> is true.
  795. </td>
  796. </tr>
  797. <tr>
  798. <td>getCustomTime()</td>
  799. <td>Date</td>
  800. <td>Retrieve the custom time. Only applicable when the option <code>showCustomTime</code> is true.
  801. </td>
  802. </tr>
  803. <tr id="getEventProperties">
  804. <td>getEventProperties(event)</td>
  805. <td>Object</td>
  806. <td>
  807. Returns an Object with relevant properties from an event:
  808. <ul>
  809. <li><code>pageX</code> (Number): absolute horizontal position of the click event.</li>
  810. <li><code>pageY</code> (Number): absolute vertical position of the click event.</li>
  811. <li><code>x</code> (Number): relative horizontal position of the click event.</li>
  812. <li><code>y</code> (Number): relative vertical position of the click event.</li>
  813. <li><code>time</code> (Date): Date of the clicked event.</li>
  814. <li><code>value</code> (Number[]): The data value of the click event. The array contains one value when there is one data axis visible, and two values when there are two visible data axes.</li>
  815. <li><code>what</code> (String | null): name of the clicked thing: <code>background</code>, <code>axis</code>, <code>dat-axis</code>, <code>custom-time</code>, or <code>current-time</code>, <code>legend</code>.</li>
  816. <li><code>event</code> (Object): the original click event.</li>
  817. </ul>
  818. </td>
  819. </tr>
  820. <tr>
  821. <td>getLegend(groupId, iconWidth, iconHeight)</td>
  822. <td>SVGelement, String, String</td>
  823. <td>Returns an object containing an SVG element with the icon of the group (size determined by iconWidth and iconHeight), the label of the group (content) and the yAxisOrientation of the group (left or right).
  824. </td>
  825. </tr>
  826. <tr>
  827. <td>getWindow()</td>
  828. <td>Object</td>
  829. <td>Get the current visible window. Returns an object with properties <code>start: Date</code> and <code>end: Date</code>.</td>
  830. </tr>
  831. <tr>
  832. <td>getItemRange()</td>
  833. <td>Object</td>
  834. <td>Get the range of all the items as an object containing <code>min: Date</code> and <code>max: Date</code>.</td>
  835. </tr>
  836. <tr>
  837. <td>hiddenDates</td>
  838. <td>Object</td>
  839. <td>none</td>
  840. <td>This option allows you to hide specific timespans from the time axis. The dates can be supplied as an object:
  841. <code>{start: '2014-03-21 00:00:00', end: '2014-03-28 00:00:00', [repeat:'daily']}</code> or as an Array of these objects. The repeat argument is optional.
  842. The possible values are (case-sensitive): <code>daily, weekly, monthly, yearly</code>. To hide a weekend, pick any Saturday as start and the following Monday as end
  843. and set repeat to weekly.
  844. </td>
  845. </tr>
  846. <tr>
  847. <td>isGroupVisible(groupId)</td>
  848. <td>Boolean</td>
  849. <td>This checks if the visible option of the supplied group (by ID) is true or false.
  850. </td>
  851. </tr>
  852. <tr>
  853. <td>moveTo(time [, options])</td>
  854. <td>none</td>
  855. <td>Move the window such that given time is centered on screen. Parameter <code>time</code> can be a <code>Date</code>, <code>Number</code>, or <code>String</code>. Available options:
  856. <ul>
  857. <li><code>animate: boolean | number</code><br>If true (default), the range is animated smoothly to the new window. If a number, the number is taken as duration for the animation. Default duration is 500 ms.</li>
  858. </ul>
  859. </td>
  860. </tr>
  861. <tr>
  862. <td>on(event, callback)</td>
  863. <td>none</td>
  864. <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>
  865. </tr>
  866. <tr>
  867. <td>off(event, callback)</td>
  868. <td>none</td>
  869. <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>
  870. </tr>
  871. <tr>
  872. <td>redraw()</td>
  873. <td>none</td>
  874. <td>Force a redraw of the Graph2d. Can be useful to manually redraw when option autoResize=false.
  875. </td>
  876. </tr>
  877. <tr>
  878. <td>setCurrentTime(time)</td>
  879. <td>none</td>
  880. <td>Set a current time. This can be used for example to ensure that a client's time is synchronized with a shared server time.
  881. <code>time</code> can be a Date object, numeric timestamp, or ISO date string.
  882. Only applicable when option <code>showCurrentTime</code> is true.</td>
  883. </tr>
  884. <tr>
  885. <td>setCustomTime(time)</td>
  886. <td>none</td>
  887. <td>Adjust the custom time bar. Only applicable when the option <code>showCustomTime</code> is true. <code>time</code> can be a Date object, numeric timestamp, or ISO date string.
  888. </td>
  889. </tr>
  890. <tr>
  891. <td>setGroups(groups)</td>
  892. <td>none</td>
  893. <td>Set a data set with groups for the Graph2d.
  894. <code>groups</code> can be an Array with Objects,
  895. a DataSet, or a DataView. For each of the groups, the items of the
  896. Graph2d are filtered on the property <code>group</code>, which
  897. must correspond with the id of the group.
  898. </td>
  899. </tr>
  900. <tr>
  901. <td>setItems(items)</td>
  902. <td>none</td>
  903. <td>Set a data set with items for the Graph2d.
  904. <code>items</code> can be an Array with Objects,
  905. a DataSet, or a DataView.
  906. </td>
  907. </tr>
  908. <tr>
  909. <td>setOptions(options)</td>
  910. <td>none</td>
  911. <td>Set or update options. It is possible to change any option of the Graph2d at any time. You can for example switch orientation on the fly.
  912. </td>
  913. </tr>
  914. <tr>
  915. <td>setWindow(start, end)</td>
  916. <td>none</td>
  917. <td>Set the current visible window. The parameters <code>start</code> and <code>end</code> can be a <code>Date</code>, <code>Number</code>, or <code>String</code>. If the parameter value of <code>start</code> or <code>end</code> is null, the parameter will be left unchanged.</td>
  918. </tr>
  919. </table>
  920. <h2 id="Events">Events</h2>
  921. <p>
  922. Graph2d fires events when changing the visible window by dragging, when
  923. selecting items, and when dragging the custom time bar.
  924. </p>
  925. <p>
  926. Here an example on how to listen for a <code>rangeChanged</code> event. A listener can be removed via the function <code>off</code>:
  927. </p>
  928. <pre class="prettyprint lang-js">
  929. function onChange (properties) {
  930. alert('changed!');
  931. }
  932. // add event listener
  933. Graph2d.on('rangechanged', onChange);
  934. // do stuff...
  935. // remove event listener
  936. Graph2d.off('rangechanged', onChange);
  937. </pre>
  938. <p>
  939. The following events are available.
  940. </p>
  941. <table>
  942. <colgroup>
  943. <col style="width: 20%;">
  944. <col style="width: 40%;">
  945. <col style="width: 40%;">
  946. </colgroup>
  947. <tr>
  948. <th>name</th>
  949. <th>Description</th>
  950. <th>Properties</th>
  951. </tr>
  952. <tr>
  953. <td>finishedRedraw</td>
  954. <td>Fired after a redraw is complete. When moving the Graph2d around, this could be fired frequently.
  955. </td>
  956. <td>
  957. none.
  958. </td>
  959. </tr>
  960. <tr>
  961. <td>rangechange</td>
  962. <td>Fired repeatedly when the user is dragging the Graph2d window.
  963. </td>
  964. <td>
  965. <ul>
  966. <li><code>start</code> (Number): timestamp of the current start of the window.</li>
  967. <li><code>end</code> (Number): timestamp of the current end of the window.</li>
  968. </ul>
  969. </td>
  970. </tr>
  971. <tr>
  972. <td>rangechanged</td>
  973. <td>Fired once after the user has dragged the Graph2d window.
  974. </td>
  975. <td>
  976. <ul>
  977. <li><code>start</code> (Number): timestamp of the current start of the window.</li>
  978. <li><code>end</code> (Number): timestamp of the current end of the window.</li>
  979. </ul>
  980. </td>
  981. </tr>
  982. <tr>
  983. <td>timechange</td>
  984. <td>Fired repeatedly when the user is dragging the custom time bar.
  985. Only available when the custom time bar is enabled.
  986. </td>
  987. <td>
  988. <ul>
  989. <li><code>time</code> (Date): the current time.</li>
  990. </ul>
  991. </td>
  992. </tr>
  993. <tr>
  994. <td>timechanged</td>
  995. <td>Fired once after the user has dragged the custom time bar.
  996. Only available when the custom time bar is enabled.
  997. </td>
  998. <td>
  999. <ul>
  1000. <li><code>time</code> (Date): the current time.</li>
  1001. </ul>
  1002. </td>
  1003. </tr>
  1004. </table>
  1005. <h2 id="Localization">Localization</h2>
  1006. <p>
  1007. Graph2d can be localized. For localization, Graph2d depends largely on the localization of <a href="http://momentjs.com">moment.js</a>. Locales are not included in vis.js by default. To enable localization, moment.js must be loaded with locales. Moment.js offers a bundle named "moment-with-locales.min.js" for this and there are various alternative ways to load locales.
  1008. </p>
  1009. <p>
  1010. To set a locale for the Graph2d, specify the option <code>locale</code>:
  1011. </p>
  1012. <pre class="prettyprint lang-js">var options = {
  1013. locale: 'nl'
  1014. };
  1015. </pre>
  1016. <h3>Create a new locale</h3>
  1017. To load a locale into the Graph2d not supported by default, one can add a new locale to the option <code>locales</code>:
  1018. <pre class="prettyprint lang-js">var options = {
  1019. locales: {
  1020. // create a new locale
  1021. mylocale: {
  1022. current: 'current',
  1023. time: 'time',
  1024. }
  1025. },
  1026. // use the new locale
  1027. locale: 'mylocale'
  1028. };
  1029. </pre>
  1030. <h3 id="available-locales">Available locales</h3>
  1031. Graph2d comes with support for the following locales:
  1032. <table>
  1033. <tr><th>Language</th><th>Code</th></tr>
  1034. <tr>
  1035. <td>English</td>
  1036. <td>
  1037. <code>en</code><br>
  1038. <code>en_EN</code><br>
  1039. <code>en_US</code>
  1040. </td>
  1041. </tr>
  1042. <tr>
  1043. <td>Dutch</td>
  1044. <td>
  1045. <code>nl</code><br>
  1046. <code>nl_NL</code><br>
  1047. <code>nl_BE</code>
  1048. </td>
  1049. </tr>
  1050. </table>
  1051. <h2 id="Styles">Styles</h2>
  1052. <p>
  1053. All parts of the Graph2d have a class name and a default css style just like the Graph2d.
  1054. The styles can be overwritten, which enables full customization of the layout
  1055. of the Graph2d.
  1056. </p>
  1057. <p>
  1058. Additionally, Graph2d has 10 preset styles for graphs, which are cycled through when loading groups. These styles can be overwritten
  1059. as well, along with defining your own classes to style the graphs! <a href="../examples/graph2d/04_rightAxis.html">Example 4</a> and
  1060. <a href="../examples/graph2d/05_bothAxis.html">example 5</a> show the usage of custom styles.
  1061. </p>
  1062. <h2 id="Data_Policy">Data Policy</h2>
  1063. <p>
  1064. All code and data is processed and rendered in the browser.
  1065. No data is sent to any server.
  1066. </p>
  1067. </div>
  1068. </body>
  1069. </html>