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.

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