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.

1072 lines
31 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
  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.setData(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. </table>
  158. <h3 id="groups">Groups</h3>
  159. <p>
  160. Like the items, groups are regular JavaScript Arrays and Objects.
  161. Using groups, items can be grouped together.
  162. Items are filtered per group, and displayed as individual graphs. Groups can contain the properties <code>id</code>,
  163. <code>content</code>, <code>className</code> (optional) and <code>options</code> (optional).
  164. </p>
  165. <p>
  166. Groups can be applied to a timeline using the method <code>setGroups</code>.
  167. A table with groups can be created like:
  168. </p>
  169. <pre class="prettyprint lang-js">
  170. var groups = new vis.DataSet();
  171. groups.add({
  172. id: 1,
  173. content: 'Group 1',
  174. // Optional: a field 'visible'
  175. // Optional: a field 'className'
  176. // Optional: options
  177. })
  178. groups.add({
  179. // more groups...
  180. });
  181. </pre>
  182. <p>
  183. Groups can have the following properties:
  184. </p>
  185. <table>
  186. <tr>
  187. <th>Name</th>
  188. <th>Type</th>
  189. <th>Required</th>
  190. <th>Description</th>
  191. </tr>
  192. <tr>
  193. <td>id</td>
  194. <td>String | Number</td>
  195. <td>yes</td>
  196. <td>An id for the group. The group will display all items having a
  197. property <code>group</code> which matches the <code>id</code>
  198. of the group.</td>
  199. </tr>
  200. <tr>
  201. <td>content</td>
  202. <td>String</td>
  203. <td>yes</td>
  204. <td>The contents of the group. This can be plain text or html code.</td>
  205. </tr>
  206. <tr>
  207. <td>className</td>
  208. <td>String</td>
  209. <td>no</td>
  210. <td>This field is optional. A className can be used to give groups
  211. an individual css style.
  212. </td>
  213. </tr>
  214. <tr>
  215. <td>style</td>
  216. <td>String</td>
  217. <td>no</td>
  218. <td>This field is optional. A style can be used to give groups
  219. an individual css style, and any style tags specified in style will
  220. override the definition in the className style defined in css.
  221. </td>
  222. </tr>
  223. <tr>
  224. <td>options</td>
  225. <td>JSON object</td>
  226. <td>no</td>
  227. <td>This field is optional. The options can be used to give a group a specific draw style.
  228. Any options that are colored green in the Configuration Options can be used as options here.
  229. </tr>
  230. <tr>
  231. <td>visible</td>
  232. <td>Boolean</td>
  233. <td>true</td>
  234. <td>This field is optional. If false, this group will not be drawn.
  235. </tr>
  236. </table>
  237. <h2 id="Configuration_Options">Configuration Options</h2>
  238. <h3 id="graph2dOptions">Graph2d Options</h3>
  239. Options can be used to customize the Graph2d to your purposes. These options can be passed to the Graph2d object either in
  240. the constructor, or by the <code>setOptions</code> function.
  241. <pre class="prettyprint lang-js">
  242. var options = {
  243. width: '100%',
  244. height: '400px',
  245. style: 'surface'
  246. };
  247. </pre>
  248. The options colored in green can also be used as options for the groups. All options are optional.
  249. <table>
  250. <tr>
  251. <th>Name</th>
  252. <th>Type</th>
  253. <th>Default</th>
  254. <th>Description</th>
  255. </tr>
  256. <tr>
  257. <td class="greenField">yAxisOrientation</td>
  258. <td>String</td>
  259. <td>'left'</td>
  260. <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
  261. with an axis, it will not be shown.</td>
  262. </tr>
  263. <tr>
  264. <td>defaultGroup</td>
  265. <td>String</td>
  266. <td>'default'</td>
  267. <td>This is the label for the default, ungrouped items when shown in a legend.</td>
  268. </tr>
  269. <tr>
  270. <td class="greenField">sort</td>
  271. <td>Boolean</td>
  272. <td>true</td>
  273. <td>This determines if the items are sorted automatically.
  274. They are sorted by the x value. If sort is enabled, more optimizations are possible, increasing the performance.</td>
  275. </tr>
  276. <tr>
  277. <td class="greenField">sampling</td>
  278. <td>Boolean</td>
  279. <td>true</td>
  280. <td>If sampling is enabled, Graph2d will automatically determine the amount of points per pixel.
  281. If there are more than 1 point per pixel, not all points will be drawn. Disabling sampling will cause a decrease in performance.</td>
  282. </tr>
  283. <tr>
  284. <td>graphHeight</td>
  285. <td>Number | String</td>
  286. <td>'400px'</td>
  287. <td>This is the height of the graph SVG canvas.
  288. If it is larger than the height of the outer frame, you can drag up and down
  289. the vertical direction as well as the usual horizontal direction.</td>
  290. </tr>
  291. <tr>
  292. <td class="greenField">shaded</td>
  293. <td>Boolean | Object</td>
  294. <td>false</td>
  295. <td>Toggle a shaded area with the default settings.</td>
  296. </tr>
  297. <tr>
  298. <td class="greenField">shaded.enabled</td>
  299. <td>Boolean</td>
  300. <td>false</td>
  301. <td>This toggles the shading.</td>
  302. </tr>
  303. <tr>
  304. <td class="greenField">shaded.orientation</td>
  305. <td>String</td>
  306. <td>'bottom'</td>
  307. <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>
  308. </tr>
  309. <tr>
  310. <td class="greenField">shaded.style</td>
  311. <td>String</td>
  312. <td>undefined</td>
  313. <td>Set the style for the shading. This is a css string and it will override the attributes set in the class.</td>
  314. </tr>
  315. <tr>
  316. <td class="greenField">style</td>
  317. <td>String</td>
  318. <td>'line'</td>
  319. <td>This allows the user to define if this should be a linegraph, barchart or pointcloud. The options are: 'line', 'bar', 'points'.</td>
  320. </tr>
  321. <tr>
  322. <td class="greenField">barChart.width</td>
  323. <td>Number</td>
  324. <td>50</td>
  325. <td>The width of the bars.</td>
  326. </tr>
  327. <tr>
  328. <td class="greenField">barChart.align</td>
  329. <td>String</td>
  330. <td>'center'</td>
  331. <td>The alignment of the bars with regards to the coordinate. The options are 'left', 'right' or 'center'.</td>
  332. </tr>
  333. <tr>
  334. <td class="greenField">barChart.handleOverlap</td>
  335. <td>String</td>
  336. <td>'overlap'</td>
  337. <td>You can choose how graph2d handles the case where barcharts are occupying the same datapoint. The possible options are:
  338. <code>overlap, sideBySide, stack</code>.
  339. See <a href="../examples/graph2d/10_barsSideBySide.html">example 10</a> for more information.
  340. When using groups, see <a href="../examples/graph2d/11_barsSideBySideGroups.html">example 11</a>.
  341. </td>
  342. </tr>
  343. <tr>
  344. <td class="greenField">catmullRom</td>
  345. <td>Boolean | Object</td>
  346. <td>true</td>
  347. <td>Toggle the interpolation with the default settings. For more customization use the JSON format.</td>
  348. </tr>
  349. <tr>
  350. <td class="greenField">catmullRom.enabled</td>
  351. <td>Boolean</td>
  352. <td>true</td>
  353. <td>Toggle the interpolation.</td>
  354. </tr>
  355. <tr>
  356. <td class="greenField">catmullRom.parametrization</td>
  357. <td>String</td>
  358. <td>'centripetal'</td>
  359. <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.
  360. If catmullRom is disabled, linear interpolation is used.</td>
  361. </tr>
  362. <tr>
  363. <td class="greenField">drawPoints</td>
  364. <td>Boolean | Object</td>
  365. <td>true</td>
  366. <td>Toggle the drawing of the datapoints with the default settings.</td>
  367. </tr>
  368. <tr>
  369. <td class="greenField">drawPoints.enabled</td>
  370. <td>Boolean</td>
  371. <td>true</td>
  372. <td>Toggle the drawing of the datapoints.</td>
  373. </tr>
  374. <tr>
  375. <td class="greenField">drawPoints.size</td>
  376. <td>Number</td>
  377. <td>6</td>
  378. <td>Determine the size at which the data points are drawn.</td>
  379. </tr>
  380. <tr>
  381. <td class="greenField">drawPoints.style</td>
  382. <td>String</td>
  383. <td>'square'</td>
  384. <td>Determine the shape of the data points. The options are 'square' or 'circle'.</td>
  385. </tr>
  386. <tr>
  387. <td>dataAxis.customRange.left.min</td>
  388. <td>Number</td>
  389. <td>undefined</td>
  390. <td>Set the minimum value of the left y-Axis.</td>
  391. </tr>
  392. <tr>
  393. <td>dataAxis.customRange.left.max</td>
  394. <td>Number</td>
  395. <td>undefined</td>
  396. <td>Set the maximum value of the left y-Axis.</td>
  397. </tr>
  398. <tr>
  399. <td>dataAxis.customRange.right.min</td>
  400. <td>Number</td>
  401. <td>undefined</td>
  402. <td>Set the minimum value of the right y-Axis.</td>
  403. </tr>
  404. <tr>
  405. <td>dataAxis.customRange.right.max</td>
  406. <td>Number</td>
  407. <td>undefined</td>
  408. <td>Set the maximum value of the right y-Axis.</td>
  409. </tr>
  410. <tr>
  411. <td>dataAxis.showMinorLabels</td>
  412. <td>Boolean</td>
  413. <td>true</td>
  414. <td>Toggle the drawing of the minor labels on the Y axis.</td>
  415. </tr>
  416. <tr>
  417. <td>dataAxis.showMajorLabels</td>
  418. <td>Boolean</td>
  419. <td>true</td>
  420. <td>Toggle the drawing of the major labels on the Y axis.</td>
  421. </tr>
  422. <tr>
  423. <td>dataAxis.icons</td>
  424. <td>Boolean</td>
  425. <td>false</td>
  426. <td>Toggle the drawing of automatically generated icons the Y axis.</td>
  427. </tr>
  428. <tr>
  429. <td>dataAxis.width</td>
  430. <td>Number | String</td>
  431. <td>'40px'</td>
  432. <td>Set the (minimal) width of the yAxis. The axis will resize to accomodate the labels of the Y values.</td>
  433. </tr>
  434. <tr>
  435. <td>dataAxis.visible</td>
  436. <td>Boolean</td>
  437. <td>true</td>
  438. <td>Show or hide the data axis.</td>
  439. </tr>
  440. <tr>
  441. <td>dataAxis.title.left.text</td>
  442. <td>String</td>
  443. <td>undefined</td>
  444. <td>Set the title for the left axis.</td>
  445. </tr>
  446. <tr>
  447. <td>dataAxis.title.left.style</td>
  448. <td>String</td>
  449. <td>undefined</td>
  450. <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>
  451. </tr>
  452. <tr>
  453. <td>dataAxis.title.right.text</td>
  454. <td>String</td>
  455. <td>undefined</td>
  456. <td>Set the title for the right axis.</td>
  457. </tr>
  458. <tr>
  459. <td>dataAxis.title.right.style</td>
  460. <td>String</td>
  461. <td>undefined</td>
  462. <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>
  463. </tr>
  464. <tr>
  465. <td>dataAxis.format.left.decimals</td>
  466. <td>Number</td>
  467. <td>undefined</td>
  468. <td>Set the number of decimal points used on the the left axis. If set, this will fix the number of decimal places
  469. displayed after the decimal point.
  470. If undefined, trailing zeros will be removed.</td>
  471. </tr>
  472. <tr>
  473. <td>dataAxis.format.right.decimals</td>
  474. <td>Number</td>
  475. <td>undefined</td>
  476. <td>Set the number of decimal points used on the the right axis. If set, this will fix the number of decimal places
  477. displayed after the decimal point.
  478. If undefined, trailing zeros will be removed.</td>
  479. </tr>
  480. <tr>
  481. <td>groups.visibility</td>
  482. <td>Object</td>
  483. <td></td>
  484. <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
  485. this is not communicated across instances of graph2d. Take a look at <a href="../examples/graph2d/14_toggleGroups.html">Example 14</a>
  486. for more explanation.
  487. </td>
  488. </tr>
  489. <tr>
  490. <td>legend</td>
  491. <td>Boolean</td>
  492. <td>false</td>
  493. <td>Toggle the legend with the default settings.</td>
  494. </tr>
  495. <tr>
  496. <td>legend.enabled</td>
  497. <td>Boolean</td>
  498. <td>false</td>
  499. <td>Toggle the legend.</td>
  500. </tr>
  501. <tr>
  502. <td>legend.icons</td>
  503. <td>Boolean</td>
  504. <td>true</td>
  505. <td>Show automatically generated icons on the legend.</td>
  506. </tr>
  507. <tr>
  508. <td>legend.left.visible</td>
  509. <td>Boolean</td>
  510. <td>true</td>
  511. <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>
  512. </tr>
  513. <tr>
  514. <td>legend.left.position</td>
  515. <td>String</td>
  516. <td>'top-left'</td>
  517. <td>Determine the position of the legend coupled to the left axis. Options are 'top-left', 'top-right', 'bottom-left' or 'bottom-right'.</td>
  518. </tr>
  519. <tr>
  520. <td>legend.right.visible</td>
  521. <td>Boolean</td>
  522. <td>true</td>
  523. <td>This toggles the visibility of the legend that is coupled with the right axis.</td>
  524. </tr>
  525. <tr>
  526. <td>legend.right.position</td>
  527. <td>String</td>
  528. <td>'top-right'</td>
  529. <td>Determine the position of the legend coupled to the right axis. Options are 'top-left', 'top-right', 'bottom-left' or 'bottom-right'.</td>
  530. </tr>
  531. </table>
  532. <h3 id="timelineOptions">Timeline Options</h3>
  533. <p>
  534. Graph2d is built upon the framework of the timeline. These options from the timeline can be used with graph2D.
  535. All options are optional.
  536. </p>
  537. <table>
  538. <tr>
  539. <th>Name</th>
  540. <th>Type</th>
  541. <th>Default</th>
  542. <th>Description</th>
  543. </tr>
  544. <tr>
  545. <td>autoResize</td>
  546. <td>boolean</td>
  547. <td>true</td>
  548. <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>
  549. </tr>
  550. <tr>
  551. <td>clickToUse</td>
  552. <td>boolean</td>
  553. <td>false</td>
  554. <td>When a Graph2d is configured to be <code>clickToUse</code>, it will react to mouse and touch events only when active.
  555. 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>
  556. </tr>
  557. <tr>
  558. <td>end</td>
  559. <td>Date | Number | String</td>
  560. <td>none</td>
  561. <td>The initial end date for the axis of the timeline.
  562. If not provided, the latest date present in the items set is taken as
  563. end date.</td>
  564. </tr>
  565. <tr>
  566. <td>height</td>
  567. <td>Number | String</td>
  568. <td>none</td>
  569. <td>The height of the timeline in pixels or as a percentage.
  570. When height is undefined or null, the height of the timeline is automatically
  571. adjusted to fit the contents.
  572. It is possible to set a maximum height using option <code>maxHeight</code>
  573. to prevent the timeline from getting too high in case of automatically
  574. calculated height.
  575. </td>
  576. </tr>
  577. <tr>
  578. <td>locale</td>
  579. <td>String</td>
  580. <td>none</td>
  581. <td>Select a locale for the Graph2d. See section <a href="timeline.html#Localization">Localization</a> for more information.</td>
  582. </tr>
  583. <tr>
  584. <td>locales</td>
  585. <td>Object</td>
  586. <td>none</td>
  587. <td>A map with i18n locales. See section <a href="timeline.html#Localization">Localization</a> for more information.</td>
  588. </tr>
  589. <tr>
  590. <td>max</td>
  591. <td>Date | Number | String</td>
  592. <td>none</td>
  593. <td>Set a maximum Date for the visible range.
  594. It will not be possible to move beyond this maximum.
  595. </td>
  596. </tr>
  597. <tr>
  598. <td>maxHeight</td>
  599. <td>Number | String</td>
  600. <td>none</td>
  601. <td>Specifies the maximum height for the Timeline. Can be a number in pixels or a string like "300px".</td>
  602. </tr>
  603. <tr>
  604. <td>min</td>
  605. <td>Date | Number | String</td>
  606. <td>none</td>
  607. <td>Set a minimum Date for the visible range.
  608. It will not be possible to move beyond this minimum.
  609. </td>
  610. </tr>
  611. <tr>
  612. <td>minHeight</td>
  613. <td>Number | String</td>
  614. <td>none</td>
  615. <td>Specifies the minimum height for the Timeline. Can be a number in pixels or a string like "300px".</td>
  616. </tr>
  617. <tr>
  618. <td>orientation</td>
  619. <td>String</td>
  620. <td>'bottom'</td>
  621. <td>Orientation of the timeline: 'top' or 'bottom' (default). If orientation is 'bottom', the time axis is drawn at the bottom, and if 'top', the axis is drawn on top.</td>
  622. </tr>
  623. <tr>
  624. <td>showCurrentTime</td>
  625. <td>boolean</td>
  626. <td>true</td>
  627. <td>Show a vertical bar at the current time.</td>
  628. </tr>
  629. <tr>
  630. <td>showCustomTime</td>
  631. <td>boolean</td>
  632. <td>false</td>
  633. <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>
  634. </tr>
  635. <tr>
  636. <td>showMajorLabels</td>
  637. <td>boolean</td>
  638. <td>true</td>
  639. <td>By default, the timeline shows both minor and major date labels on the
  640. time axis.
  641. For example the minor labels show minutes and the major labels show hours.
  642. When <code>showMajorLabels</code> is <code>false</code>, no major labels
  643. are shown.</td>
  644. </tr>
  645. <tr>
  646. <td>showMinorLabels</td>
  647. <td>boolean</td>
  648. <td>true</td>
  649. <td>By default, the timeline shows both minor and major date labels on the
  650. time axis.
  651. For example the minor labels show minutes and the major labels show hours.
  652. When <code>showMinorLabels</code> is <code>false</code>, no minor labels
  653. are shown. When both <code>showMajorLabels</code> and
  654. <code>showMinorLabels</code> are false, no horizontal axis will be
  655. visible.</td>
  656. </tr>
  657. <tr>
  658. <td>start</td>
  659. <td>Date | Number | String</td>
  660. <td>none</td>
  661. <td>The initial start date for the axis of the timeline.
  662. If not provided, the earliest date present in the events is taken as start date.</td>
  663. </tr>
  664. <tr>
  665. <td>width</td>
  666. <td>String</td>
  667. <td>'100%'</td>
  668. <td>The width of the timeline in pixels or as a percentage.</td>
  669. </tr>
  670. <tr>
  671. <td>zoomMax</td>
  672. <td>Number</td>
  673. <td>315360000000000</td>
  674. <td>Set a maximum zoom interval for the visible range in milliseconds.
  675. It will not be possible to zoom out further than this maximum.
  676. Default value equals about 10000 years.
  677. </td>
  678. </tr>
  679. <tr>
  680. <td>zoomMin</td>
  681. <td>Number</td>
  682. <td>10</td>
  683. <td>Set a minimum zoom interval for the visible range in milliseconds.
  684. It will not be possible to zoom in further than this minimum.
  685. </td>
  686. </tr>
  687. </table>
  688. <h2 id="Methods">Methods</h2>
  689. <p>
  690. The Graph2d supports the following methods.
  691. </p>
  692. <table>
  693. <tr>
  694. <th>Method</th>
  695. <th>Return Type</th>
  696. <th>Description</th>
  697. </tr>
  698. <tr>
  699. <td>clear([what])</td>
  700. <td>none</td>
  701. <td>
  702. Clear the Graph2d. An object can be passed specifying which sections to clear: items, groups,
  703. and/or options. By Default, items, groups and options are cleared, i.e. <code>what = {items: true, groups: true, options: true}</code>. Example usage:
  704. <pre class="prettyprint lang-js">Graph2d.clear(); // clear items, groups, and options
  705. Graph2d.clear({options: true}); // clear options only
  706. </pre>
  707. </td>
  708. </tr>
  709. <tr>
  710. <td>destroy()</td>
  711. <td>none</td>
  712. <td>Destroy the Graph2d. The Graph2d is removed from memory. all DOM elements and event listeners are cleaned up.
  713. </td>
  714. </tr>
  715. <tr>
  716. <td>getCurrentTime()</td>
  717. <td>Date</td>
  718. <td>Get the current time. Only applicable when option <code>showCurrentTime</code> is true.
  719. </td>
  720. </tr>
  721. <tr>
  722. <td>getCustomTime()</td>
  723. <td>Date</td>
  724. <td>Retrieve the custom time. Only applicable when the option <code>showCustomTime</code> is true.
  725. </td>
  726. </tr>
  727. <tr>
  728. <td>getLegend(groupId, iconWidth, iconHeight)</td>
  729. <td>SVGelement, String, String</td>
  730. <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).
  731. </td>
  732. </tr>
  733. <tr>
  734. <td>getWindow()</td>
  735. <td>Object</td>
  736. <td>Get the current visible window. Returns an object with properties <code>start: Date</code> and <code>end: Date</code>.</td>
  737. </tr>
  738. <tr>
  739. <td>getItemRange()</td>
  740. <td>Object</td>
  741. <td>Get the range of all the items as an object containing <code>min: Date</code> and <code>max: Date</code>.</td>
  742. </tr>
  743. <tr>
  744. <td>fit()</td>
  745. <td>none</td>
  746. <td>Adjust the visible window such that it fits all items.
  747. </td>
  748. </tr>
  749. <tr>
  750. <td>isGroupVisible(groupId)</td>
  751. <td>Boolean</td>
  752. <td>This checks if the visible option of the supplied group (by ID) is true or false.
  753. </td>
  754. </tr>
  755. <tr>
  756. <td>moveTo(time [, options])</td>
  757. <td>none</td>
  758. <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:
  759. <ul>
  760. <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>
  761. </ul>
  762. </td>
  763. </tr>
  764. <tr>
  765. <td>on(event, callback)</td>
  766. <td>none</td>
  767. <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>
  768. </tr>
  769. <tr>
  770. <td>off(event, callback)</td>
  771. <td>none</td>
  772. <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>
  773. </tr>
  774. <tr>
  775. <td>redraw()</td>
  776. <td>none</td>
  777. <td>Force a redraw of the Graph2d. Can be useful to manually redraw when option autoResize=false.
  778. </td>
  779. </tr>
  780. <tr>
  781. <td>setCurrentTime(time)</td>
  782. <td>none</td>
  783. <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.
  784. <code>time</code> can be a Date object, numeric timestamp, or ISO date string.
  785. Only applicable when option <code>showCurrentTime</code> is true.</td>
  786. </tr>
  787. <tr>
  788. <td>setCustomTime(time)</td>
  789. <td>none</td>
  790. <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.
  791. </td>
  792. </tr>
  793. <tr>
  794. <td>setGroups(groups)</td>
  795. <td>none</td>
  796. <td>Set a data set with groups for the Graph2d.
  797. <code>groups</code> can be an Array with Objects,
  798. a DataSet, or a DataView. For each of the groups, the items of the
  799. Graph2d are filtered on the property <code>group</code>, which
  800. must correspond with the id of the group.
  801. </td>
  802. </tr>
  803. <tr>
  804. <td>setItems(items)</td>
  805. <td>none</td>
  806. <td>Set a data set with items for the Graph2d.
  807. <code>items</code> can be an Array with Objects,
  808. a DataSet, or a DataView.
  809. </td>
  810. </tr>
  811. <tr>
  812. <td>setOptions(options)</td>
  813. <td>none</td>
  814. <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.
  815. </td>
  816. </tr>
  817. <tr>
  818. <td>setWindow(start, end)</td>
  819. <td>none</td>
  820. <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>
  821. </tr>
  822. </table>
  823. <h2 id="Events">Events</h2>
  824. <p>
  825. Graph2d fires events when changing the visible window by dragging, when
  826. selecting items, and when dragging the custom time bar.
  827. </p>
  828. <p>
  829. Here an example on how to listen for a <code>rangeChanged</code> event. A listener can be removed via the function <code>off</code>:
  830. </p>
  831. <pre class="prettyprint lang-js">
  832. function onChange (properties) {
  833. alert('changed!');
  834. }
  835. // add event listener
  836. Graph2d.on('rangechanged', onChange);
  837. // do stuff...
  838. // remove event listener
  839. Graph2d.off('rangechanged', onChange);
  840. </pre>
  841. <p>
  842. The following events are available.
  843. </p>
  844. <table>
  845. <colgroup>
  846. <col style="width: 20%;">
  847. <col style="width: 40%;">
  848. <col style="width: 40%;">
  849. </colgroup>
  850. <tr>
  851. <th>name</th>
  852. <th>Description</th>
  853. <th>Properties</th>
  854. </tr>
  855. <tr>
  856. <td>rangechange</td>
  857. <td>Fired repeatedly when the user is dragging the Graph2d window.
  858. </td>
  859. <td>
  860. <ul>
  861. <li><code>start</code> (Number): timestamp of the current start of the window.</li>
  862. <li><code>end</code> (Number): timestamp of the current end of the window.</li>
  863. </ul>
  864. </td>
  865. </tr>
  866. <tr>
  867. <td>rangechanged</td>
  868. <td>Fired once after the user has dragged the Graph2d window.
  869. </td>
  870. <td>
  871. <ul>
  872. <li><code>start</code> (Number): timestamp of the current start of the window.</li>
  873. <li><code>end</code> (Number): timestamp of the current end of the window.</li>
  874. </ul>
  875. </td>
  876. </tr>
  877. <tr>
  878. <td>timechange</td>
  879. <td>Fired repeatedly when the user is dragging the custom time bar.
  880. Only available when the custom time bar is enabled.
  881. </td>
  882. <td>
  883. <ul>
  884. <li><code>time</code> (Date): the current time.</li>
  885. </ul>
  886. </td>
  887. </tr>
  888. <tr>
  889. <td>timechanged</td>
  890. <td>Fired once after the user has dragged the custom time bar.
  891. Only available when the custom time bar is enabled.
  892. </td>
  893. <td>
  894. <ul>
  895. <li><code>time</code> (Date): the current time.</li>
  896. </ul>
  897. </td>
  898. </tr>
  899. </table>
  900. <h2 id="Localization">Localization</h2>
  901. <p>
  902. 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.
  903. </p>
  904. <p>
  905. To set a locale for the Graph2d, specify the option <code>locale</code>:
  906. </p>
  907. <pre class="prettyprint lang-js">var options = {
  908. locale: 'nl'
  909. };
  910. </pre>
  911. <h3>Create a new locale</h3>
  912. To load a locale into the Graph2d not supported by default, one can add a new locale to the option <code>locales</code>:
  913. <pre class="prettyprint lang-js">var options = {
  914. locales: {
  915. // create a new locale
  916. mylocale: {
  917. current: 'current',
  918. time: 'time',
  919. }
  920. },
  921. // use the new locale
  922. locale: 'mylocale'
  923. };
  924. </pre>
  925. <h3 id="available-locales">Available locales</h3>
  926. Graph2d comes with support for the following locales:
  927. <table>
  928. <tr><th>Language</th><th>Code</th></tr>
  929. <tr>
  930. <td>English</td>
  931. <td>
  932. <code>en</code><br>
  933. <code>en_EN</code><br>
  934. <code>en_US</code>
  935. </td>
  936. </tr>
  937. <tr>
  938. <td>Dutch</td>
  939. <td>
  940. <code>nl</code><br>
  941. <code>nl_NL</code><br>
  942. <code>nl_BE</code>
  943. </td>
  944. </tr>
  945. </table>
  946. <h2 id="Styles">Styles</h2>
  947. <p>
  948. All parts of the Graph2d have a class name and a default css style just like the Graph2d.
  949. The styles can be overwritten, which enables full customization of the layout
  950. of the Graph2d.
  951. </p>
  952. <p>
  953. Additionally, Graph2d has 10 preset styles for graphs, which are cycled through when loading groups. These styles can be overwritten
  954. as well, along with defining your own classes to style the graphs! <a href="../examples/graph2d/04_rightAxis.html">Example 4</a> and
  955. <a href="../examples/graph2d/05_bothAxis.html">example 5</a> show the usage of custom styles.
  956. </p>
  957. <h2 id="Data_Policy">Data Policy</h2>
  958. <p>
  959. All code and data is processed and rendered in the browser.
  960. No data is sent to any server.
  961. </p>
  962. </div>
  963. </body>
  964. </html>