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.

855 lines
26 KiB

  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. <h2 id="Contents">Contents</h2>
  23. <ul>
  24. <li><a href="#Overview">Overview</a></li>
  25. <li><a href="#Loading">Loading</a></li>
  26. <li><a href="#Data_Format">Data Format</a>
  27. <ul>
  28. <li><a href="#items">Items</a></li>
  29. <li><a href="#groups">Groups</a></li>
  30. </ul>
  31. </li>
  32. <li><a href="#Configuration_Options">Configuration Options</a>
  33. <ul>
  34. <li><a href="#graph2dOptions">Graph2D options</a></li>
  35. <li><a href="#timelineOptions">Timeline options</a></li>
  36. </ul>
  37. </li>
  38. <li><a href="#Methods">Methods</a></li>
  39. <li><a href="#Events">Events</a></li>
  40. <li><a href="#Data_Policy">Data Policy</a></li>
  41. </ul>
  42. <h2 id="Example">Example</h2>
  43. <p>
  44. The following code shows how to create a Graph2D and provide it with data.
  45. More examples can be found in the <a href="../examples">examples</a> directory.
  46. </p>
  47. <pre class="prettyprint lang-html">
  48. &lt;!DOCTYPE HTML&gt;
  49. &lt;html&gt;
  50. &lt;head&gt;
  51. &lt;title&gt;Graph2D | Basic Example&lt;/title&gt;
  52. &lt;style type="text/css"&gt;
  53. body, html {
  54. font-family: sans-serif;
  55. }
  56. &lt;/style&gt;
  57. &lt;script src="../../dist/vis.js"&gt;&lt;/script&gt;
  58. &lt;link href="../../dist/vis.css" rel="stylesheet" type="text/css" /&gt;
  59. &lt;/head&gt;
  60. &lt;body&gt;
  61. &lt;div id="visualization"&gt;&lt;/div&gt;
  62. &lt;script type="text/javascript"&gt;
  63. var container = document.getElementById('visualization');
  64. var items = [
  65. {x: '2014-06-11', y: 10},
  66. {x: '2014-06-12', y: 25},
  67. {x: '2014-06-13', y: 30},
  68. {x: '2014-06-14', y: 10},
  69. {x: '2014-06-15', y: 15},
  70. {x: '2014-06-16', y: 30}
  71. ];
  72. var dataset = new vis.DataSet(items);
  73. var options = {
  74. start: '2014-06-10',
  75. end: '2014-06-18'
  76. };
  77. var graph2d = new vis.Graph2D(container, dataset, options);
  78. &lt;/script&gt;
  79. &lt;/body&gt;
  80. &lt;/html&gt;
  81. </pre>
  82. <h2 id="Loading">Loading</h2>
  83. <p>
  84. The class name of the Graph2D is <code>vis.Graph2D</code>.
  85. When constructing a Graph2D, an HTML DOM container must be provided to attach
  86. the graph to. Optionally, data an options can be provided.
  87. Data is a vis <code>DataSet</code> or an <code>Array</code>, described in
  88. section <a href="#Data_Format">Data Format</a>.
  89. Options is a name-value map in the JSON format. The available options
  90. are described in section <a href="#Configuration_Options">Configuration Options</a>.
  91. Groups is a vis <code>DataSet</code> containing groups. The available options and the method of construction
  92. are described in section <a href="#Group_Options">Data Format</a>.
  93. </p>
  94. <pre class="prettyprint lang-js">var graph = new vis.Graph2D(container [, data] [, options] [,groups]);</pre>
  95. <p>
  96. Data, options and groups can be set or changed later on using the functions
  97. <code>Graph2D.setData(data)</code>, <code>Graph2D.setOptions(options)</code> and <code>Graph2D.setGroups(groups)</code>.
  98. </p>
  99. <h2 id="Data_Format">Data Format</h2>
  100. <p>
  101. Graph2D can load data from an <code>Array</code>, a <code>DataSet</code> or a <code>DataView</code>.
  102. JSON objects are added to this DataSet by using the <code>add()</code> function.
  103. Data points must have properties <code>x</code>, <code>y</code>, and <code>z</code>,
  104. and can optionally have a property <code>style</code> and <code>filter</code>.
  105. <p>
  106. Graph2D can be provided with two types of data:
  107. </p>
  108. <ul>
  109. <li><a href="#items">Items</a> containing a set of points to be displayed.</li>
  110. <li><a href="#groups">Groups</a> containing a set of groups used to group items
  111. together. All items belonging to a group will be drawn as a single graph.</li>
  112. </ul>
  113. <h3 id="items">Items</h3>
  114. <pre class="prettyprint lang-js">
  115. var items = [
  116. {x: '2014-06-13', y: 30, group: 0},
  117. {x: '2014-06-14', y: 10, group: 0},
  118. {x: '2014-06-15', y: 15, group: 1},
  119. {x: '2014-06-16', y: 30, group: 1},
  120. {x: '2014-06-17', y: 10, group: 1},
  121. {x: '2014-06-18', y: 15, group: 1}
  122. ];
  123. </pre>
  124. <table>
  125. <tr>
  126. <th>Name</th>
  127. <th>Type</th>
  128. <th>Required</th>
  129. <th>Description</th>
  130. </tr>
  131. <tr>
  132. <td>x</td>
  133. <td>number</td>
  134. <td>yes</td>
  135. <td>Location on the x-axis.</td>
  136. </tr>
  137. <tr>
  138. <td>y</td>
  139. <td>number</td>
  140. <td>yes</td>
  141. <td>Location on the y-axis.</td>
  142. </tr>
  143. </tr>
  144. <tr>
  145. <td>group</td>
  146. <td>number | string</td>
  147. <td>no</td>
  148. <td>The ID of the group this point belongs to.</td>
  149. </tr>
  150. </table>
  151. <h3 id="Groups">Groups</h3>
  152. <p>
  153. Like the items, groups are regular JavaScript Arrays and Objects.
  154. Using groups, items can be grouped together.
  155. Items are filtered per group, and displayed as individual graphs. Groups can contain the properties <code>id</code>,
  156. <code>content</code>, <code>className</code> (optional) and <code>options</code> (optional).
  157. </p>
  158. <p>
  159. Groups can be applied to a timeline using the method <code>setGroups</code>.
  160. A table with groups can be created like:
  161. </p>
  162. <pre class="prettyprint lang-js">
  163. var groups = new vis.DataSet();
  164. groups.add({
  165. id: 1,
  166. content: 'Group 1'
  167. // Optional: a field 'className'
  168. // Optional: options
  169. })
  170. groups.add({
  171. // more groups...
  172. });
  173. </pre>
  174. <p>
  175. Groups can have the following properties:
  176. </p>
  177. <table>
  178. <tr>
  179. <th>Name</th>
  180. <th>Type</th>
  181. <th>Required</th>
  182. <th>Description</th>
  183. </tr>
  184. <tr>
  185. <td>id</td>
  186. <td>String | Number</td>
  187. <td>yes</td>
  188. <td>An id for the group. The group will display all items having a
  189. property <code>group</code> which matches the <code>id</code>
  190. of the group.</td>
  191. </tr>
  192. <tr>
  193. <td>content</td>
  194. <td>String</td>
  195. <td>yes</td>
  196. <td>The contents of the group. This can be plain text or html code.</td>
  197. </tr>
  198. <tr>
  199. <td>className</td>
  200. <td>String</td>
  201. <td>no</td>
  202. <td>This field is optional. A className can be used to give groups
  203. an individual css style.
  204. </td>
  205. </tr>
  206. <tr>
  207. <td>options</td>
  208. <td>JSON object</td>
  209. <td>no</td>
  210. <td>This field is optional. The options can be used to give a group a specific draw style.
  211. Any options that are colored green in the Configuration Options can be used as options here.
  212. </tr>
  213. </table>
  214. <h2 id="Configuration_Options">Configuration Options</h2>
  215. <h3 id="graph2dOptions">Graph2D Options</h3>
  216. Options can be used to customize the Graph2D to your purposes. These options can be passed to the Graph2D object either in
  217. the constructor, or by the <code>setOptions</code> function.
  218. <pre class="prettyprint lang-js">
  219. var options = {
  220. width: '100%',
  221. height: '400px',
  222. style: 'surface'
  223. };
  224. </pre>
  225. The options colored in green can also be used as options for the groups. All options are optional.
  226. <table>
  227. <tr>
  228. <th>Name</th>
  229. <th>Type</th>
  230. <th>Default</th>
  231. <th>Description</th>
  232. </tr>
  233. <tr>
  234. <td class="greenField">yAxisOrientation</td>
  235. <td>String</td>
  236. <td>'left'</td>
  237. <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
  238. with an axis, it will not be shown.</td>
  239. </tr>
  240. <tr>
  241. <td>defaultGroup</td>
  242. <td>String</td>
  243. <td>'default'</td>
  244. <td>This is the label for the default, ungrouped items when shown in a legend.</td>
  245. </tr>
  246. <tr>
  247. <td class="greenField">sort</td>
  248. <td>Boolean</td>
  249. <td>true</td>
  250. <td>This determines if the items are sorted automatically.
  251. They are sorted by the x value. If sort is enabled, more optimizations are possible, increasing the performance.</td>
  252. </tr>
  253. <tr>
  254. <td class="greenField">sampling</td>
  255. <td>Boolean</td>
  256. <td>true</td>
  257. <td>If sampling is enabled, graph2D will automatically determine the amount of points per pixel.
  258. If there are more than 1 point per pixel, not all points will be drawn. Disabling sampling will cause a decrease in performance.</td>
  259. </tr>
  260. <tr>
  261. <td>graphHeight</td>
  262. <td>Number | String</td>
  263. <td>'400px'</td>
  264. <td>This is the height of the graph SVG canvas.
  265. If it is larger than the height of the outer frame, you can drag up and down
  266. the vertical direction as well as the usual horizontal direction.</td>
  267. </tr>
  268. <tr>
  269. <td class="greenField">shaded</td>
  270. <td>Boolean | Object</td>
  271. <td>false</td>
  272. <td>Toggle a shaded area with the default settings.</td>
  273. </tr>
  274. <tr>
  275. <td class="greenField">shaded.enabled</td>
  276. <td>Boolean</td>
  277. <td>false</td>
  278. <td>This toggles the shading.</td>
  279. </tr>
  280. <tr>
  281. <td class="greenField">shaded.orientation</td>
  282. <td>String</td>
  283. <td>'bottom'</td>
  284. <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>
  285. </tr>
  286. <tr>
  287. <td class="greenField">style</td>
  288. <td>String</td>
  289. <td>'line'</td>
  290. <td>This allows the user to define if this should be a linegraph or a barchart. The options are: 'line' or 'bar'.</td>
  291. </tr>
  292. <tr>
  293. <td class="greenField">barChart.width</td>
  294. <td>Number</td>
  295. <td>50</td>
  296. <td>The width of the bars.</td>
  297. </tr>
  298. <tr>
  299. <td class="greenField">barChart.align</td>
  300. <td>String</td>
  301. <td>'center'</td>
  302. <td>The alignment of the bars with regards to the coordinate. The options are 'left', 'right' or 'center'.</td>
  303. </tr>
  304. <tr>
  305. <td class="greenField">catmullRom</td>
  306. <td>Boolean | Object</td>
  307. <td>true</td>
  308. <td>Toggle the interpolation with the default settings. For more customization use the JSON format.</td>
  309. </tr>
  310. <tr>
  311. <td class="greenField">catmullRom.enabled</td>
  312. <td>Boolean</td>
  313. <td>true</td>
  314. <td>Toggle the interpolation.</td>
  315. </tr>
  316. <tr>
  317. <td class="greenField">catmullRom.parametrization</td>
  318. <td>String</td>
  319. <td>'centripetal'</td>
  320. <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.
  321. If catmullRom is disabled, linear interpolation is used.</td>
  322. </tr>
  323. <tr>
  324. <td class="greenField">drawPoints</td>
  325. <td>Boolean | Object</td>
  326. <td>true</td>
  327. <td>Toggle the drawing of the datapoints with the default settings.</td>
  328. </tr>
  329. <tr>
  330. <td class="greenField">drawPoints.enabled</td>
  331. <td>Boolean</td>
  332. <td>true</td>
  333. <td>Toggle the drawing of the datapoints.</td>
  334. </tr>
  335. <tr>
  336. <td class="greenField">drawPoints.size</td>
  337. <td>Number</td>
  338. <td>6</td>
  339. <td>Determine the size at which the data points are drawn.</td>
  340. </tr>
  341. <tr>
  342. <td class="greenField">drawPoints.style</td>
  343. <td>String</td>
  344. <td>'square'</td>
  345. <td>Determine the shape of the data points. The options are 'square' or 'circle'.</td>
  346. </tr>
  347. <tr>
  348. <td>dataAxis.showMinorLabels</td>
  349. <td>Boolean</td>
  350. <td>true</td>
  351. <td>Toggle the drawing of the minor labels on the Y axis.</td>
  352. </tr>
  353. <tr>
  354. <td>dataAxis.showMajorLabels</td>
  355. <td>Boolean</td>
  356. <td>true</td>
  357. <td>Toggle the drawing of the major labels on the Y axis.</td>
  358. </tr>
  359. <tr>
  360. <td>dataAxis.icons</td>
  361. <td>Boolean</td>
  362. <td>false</td>
  363. <td>Toggle the drawing of automatically generated icons the Y axis.</td>
  364. </tr>
  365. <tr>
  366. <td>dataAxis.width</td>
  367. <td>Number | String</td>
  368. <td>'40px'</td>
  369. <td>Set the (minimal) width of the yAxis. The axis will resize to accomodate the labels of the Y values.</td>
  370. </tr>
  371. <tr>
  372. <td>dataAxis.visible</td>
  373. <td>Boolean</td>
  374. <td>true</td>
  375. <td>Show or hide the data axis.</td>
  376. </tr>
  377. <tr>
  378. <td>legend</td>
  379. <td>Boolean</td>
  380. <td>false</td>
  381. <td>Toggle the legend with the default settings.</td>
  382. </tr>
  383. <tr>
  384. <td>legend.enabled</td>
  385. <td>Boolean</td>
  386. <td>false</td>
  387. <td>Toggle the legend.</td>
  388. </tr>
  389. <tr>
  390. <td>legend.icons</td>
  391. <td>Boolean</td>
  392. <td>true</td>
  393. <td>Show automatically generated icons on the legend.</td>
  394. </tr>
  395. <tr>
  396. <td>legend.left.visible</td>
  397. <td>Boolean</td>
  398. <td>true</td>
  399. <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>
  400. </tr>
  401. <tr>
  402. <td>legend.left.position</td>
  403. <td>String</td>
  404. <td>'top-left'</td>
  405. <td>Determine the position of the legend coupled to the left axis. Options are 'top-left', 'top-right', 'bottom-left' or 'bottom-right'.</td>
  406. </tr>
  407. <tr>
  408. <td>legend.right.visible</td>
  409. <td>Boolean</td>
  410. <td>true</td>
  411. <td>This toggles the visibility of the legend that is coupled with the right axis.</td>
  412. </tr>
  413. <tr>
  414. <td>legend.right.position</td>
  415. <td>String</td>
  416. <td>'top-right'</td>
  417. <td>Determine the position of the legend coupled to the right axis. Options are 'top-left', 'top-right', 'bottom-left' or 'bottom-right'.</td>
  418. </tr>
  419. </table>
  420. <h3 id="timelineOptions">Timeline Options</h3>
  421. <p>
  422. Graph2D is built upon the framework of the timeline. These options from the timeline can be used with graph2D.
  423. All options are optional.
  424. </p>
  425. <table>
  426. <tr>
  427. <th>Name</th>
  428. <th>Type</th>
  429. <th>Default</th>
  430. <th>Description</th>
  431. </tr>
  432. <tr>
  433. <td>autoResize</td>
  434. <td>boolean</td>
  435. <td>true</td>
  436. <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>
  437. </tr>
  438. <tr>
  439. <td>end</td>
  440. <td>Date | Number | String</td>
  441. <td>none</td>
  442. <td>The initial end date for the axis of the timeline.
  443. If not provided, the latest date present in the items set is taken as
  444. end date.</td>
  445. </tr>
  446. <tr>
  447. <td>height</td>
  448. <td>Number | String</td>
  449. <td>none</td>
  450. <td>The height of the timeline in pixels or as a percentage.
  451. When height is undefined or null, the height of the timeline is automatically
  452. adjusted to fit the contents.
  453. It is possible to set a maximum height using option <code>maxHeight</code>
  454. to prevent the timeline from getting too high in case of automatically
  455. calculated height.
  456. </td>
  457. </tr>
  458. <tr>
  459. <td>margin.axis</td>
  460. <td>Number</td>
  461. <td>20</td>
  462. <td>The minimal margin in pixels between items and the time axis.</td>
  463. </tr>
  464. <tr>
  465. <td>margin.item</td>
  466. <td>Number</td>
  467. <td>10</td>
  468. <td>The minimal margin in pixels between items.</td>
  469. </tr>
  470. <tr>
  471. <td>max</td>
  472. <td>Date | Number | String</td>
  473. <td>none</td>
  474. <td>Set a maximum Date for the visible range.
  475. It will not be possible to move beyond this maximum.
  476. </td>
  477. </tr>
  478. <tr>
  479. <td>maxHeight</td>
  480. <td>Number | String</td>
  481. <td>none</td>
  482. <td>Specifies the maximum height for the Timeline. Can be a number in pixels or a string like "300px".</td>
  483. </tr>
  484. <tr>
  485. <td>min</td>
  486. <td>Date | Number | String</td>
  487. <td>none</td>
  488. <td>Set a minimum Date for the visible range.
  489. It will not be possible to move beyond this minimum.
  490. </td>
  491. </tr>
  492. <tr>
  493. <td>minHeight</td>
  494. <td>Number | String</td>
  495. <td>none</td>
  496. <td>Specifies the minimum height for the Timeline. Can be a number in pixels or a string like "300px".</td>
  497. </tr>
  498. <tr>
  499. <td>orientation</td>
  500. <td>String</td>
  501. <td>'bottom'</td>
  502. <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>
  503. </tr>
  504. <tr>
  505. <td>showCurrentTime</td>
  506. <td>boolean</td>
  507. <td>true</td>
  508. <td>Show a vertical bar at the current time.</td>
  509. </tr>
  510. <tr>
  511. <td>showCustomTime</td>
  512. <td>boolean</td>
  513. <td>false</td>
  514. <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>
  515. </tr>
  516. <tr>
  517. <td>showMajorLabels</td>
  518. <td>boolean</td>
  519. <td>true</td>
  520. <td>By default, the timeline shows both minor and major date labels on the
  521. time axis.
  522. For example the minor labels show minutes and the major labels show hours.
  523. When <code>showMajorLabels</code> is <code>false</code>, no major labels
  524. are shown.</td>
  525. </tr>
  526. <tr>
  527. <td>showMinorLabels</td>
  528. <td>boolean</td>
  529. <td>true</td>
  530. <td>By default, the timeline shows both minor and major date labels on the
  531. time axis.
  532. For example the minor labels show minutes and the major labels show hours.
  533. When <code>showMinorLabels</code> is <code>false</code>, no minor labels
  534. are shown. When both <code>showMajorLabels</code> and
  535. <code>showMinorLabels</code> are false, no horizontal axis will be
  536. visible.</td>
  537. </tr>
  538. <tr>
  539. <td>start</td>
  540. <td>Date | Number | String</td>
  541. <td>none</td>
  542. <td>The initial start date for the axis of the timeline.
  543. If not provided, the earliest date present in the events is taken as start date.</td>
  544. </tr>
  545. <tr>
  546. <td>width</td>
  547. <td>String</td>
  548. <td>'100%'</td>
  549. <td>The width of the timeline in pixels or as a percentage.</td>
  550. </tr>
  551. <tr>
  552. <td>zoomMax</td>
  553. <td>Number</td>
  554. <td>315360000000000</td>
  555. <td>Set a maximum zoom interval for the visible range in milliseconds.
  556. It will not be possible to zoom out further than this maximum.
  557. Default value equals about 10000 years.
  558. </td>
  559. </tr>
  560. <tr>
  561. <td>zoomMin</td>
  562. <td>Number</td>
  563. <td>10</td>
  564. <td>Set a minimum zoom interval for the visible range in milliseconds.
  565. It will not be possible to zoom in further than this minimum.
  566. </td>
  567. </tr>
  568. </table>
  569. <h2 id="Methods">Methods</h2>
  570. <p>
  571. The Graph2D supports the following methods.
  572. </p>
  573. <table>
  574. <tr>
  575. <th>Method</th>
  576. <th>Return Type</th>
  577. <th>Description</th>
  578. </tr>
  579. <tr>
  580. <td>clear([what])</td>
  581. <td>none</td>
  582. <td>
  583. Clear the Graph2D. An object can be passed specifying which sections to clear: items, groups,
  584. and/or options. By Default, items, groups and options are cleared, i.e. <code>what = {items: true, groups: true, options: true}</code>. Example usage:
  585. <pre class="prettyprint lang-js">Graph2D.clear(); // clear items, groups, and options
  586. Graph2D.clear({options: true}); // clear options only
  587. </pre>
  588. </td>
  589. </tr>
  590. <tr>
  591. <td>destroy()</td>
  592. <td>none</td>
  593. <td>Destroy the Graph2D. The Graph2D is removed from memory. all DOM elements and event listeners are cleaned up.
  594. </td>
  595. </tr>
  596. <tr>
  597. <td>getCustomTime()</td>
  598. <td>Date</td>
  599. <td>Retrieve the custom time. Only applicable when the option <code>showCustomTime</code> is true.
  600. </td>
  601. </tr>
  602. <tr>
  603. <td>setCustomTime(time)</td>
  604. <td>none</td>
  605. <td>Adjust the custom time bar. Only applicable when the option <code>showCustomTime</code> is true. <code>time</code> is a Date object.
  606. </td>
  607. </tr>
  608. <tr>
  609. <td>getWindow()</td>
  610. <td>Object</td>
  611. <td>Get the current visible window. Returns an object with properties <code>start: Date</code> and <code>end: Date</code>.</td>
  612. </tr>
  613. <tr>
  614. <td>on(event, callback)</td>
  615. <td>none</td>
  616. <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>
  617. </tr>
  618. <tr>
  619. <td>off(event, callback)</td>
  620. <td>none</td>
  621. <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>
  622. </tr>
  623. <tr>
  624. <td>redraw()</td>
  625. <td>none</td>
  626. <td>Force a redraw of the Graph2D. Can be useful to manually redraw when option autoResize=false.
  627. </td>
  628. </tr>
  629. <tr>
  630. <td>setGroups(groups)</td>
  631. <td>none</td>
  632. <td>Set a data set with groups for the Graph2D.
  633. <code>groups</code> can be an Array with Objects,
  634. a DataSet, or a DataView. For each of the groups, the items of the
  635. Graph2D are filtered on the property <code>group</code>, which
  636. must correspond with the id of the group.
  637. </td>
  638. </tr>
  639. <tr>
  640. <td>setItems(items)</td>
  641. <td>none</td>
  642. <td>Set a data set with items for the Graph2D.
  643. <code>items</code> can be an Array with Objects,
  644. a DataSet, or a DataView.
  645. </td>
  646. </tr>
  647. <tr>
  648. <td>setOptions(options)</td>
  649. <td>none</td>
  650. <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.
  651. </td>
  652. </tr>
  653. <tr>
  654. <td>setWindow(start, end)</td>
  655. <td>none</td>
  656. <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>
  657. </tr>
  658. </table>
  659. <h2 id="Events">Events</h2>
  660. <p>
  661. Graph2D fires events when changing the visible window by dragging, when
  662. selecting items, and when dragging the custom time bar.
  663. </p>
  664. <p>
  665. Here an example on how to listen for a <code>rangeChanged</code> event.
  666. </p>
  667. <pre class="prettyprint lang-js">
  668. Graph2D.on('select', function (properties) {
  669. alert('selected items: ' + properties.nodes);
  670. });
  671. </pre>
  672. <p>
  673. A listener can be removed via the function <code>off</code>:
  674. </p>
  675. <pre class="prettyprint lang-js">
  676. function onChange (properties) {
  677. alert('changed!');
  678. }
  679. // add event listener
  680. Graph2D.on('rangechanged', onChange);
  681. // do stuff...
  682. // remove event listener
  683. Graph2D.off('rangechanged', onChange);
  684. </pre>
  685. <p>
  686. The following events are available.
  687. </p>
  688. <table>
  689. <colgroup>
  690. <col style="width: 20%;">
  691. <col style="width: 40%;">
  692. <col style="width: 40%;">
  693. </colgroup>
  694. <tr>
  695. <th>name</th>
  696. <th>Description</th>
  697. <th>Properties</th>
  698. </tr>
  699. <tr>
  700. <td>rangechange</td>
  701. <td>Fired repeatedly when the user is dragging the Graph2D window.
  702. </td>
  703. <td>
  704. <ul>
  705. <li><code>start</code> (Number): timestamp of the current start of the window.</li>
  706. <li><code>end</code> (Number): timestamp of the current end of the window.</li>
  707. </ul>
  708. </td>
  709. </tr>
  710. <tr>
  711. <td>rangechanged</td>
  712. <td>Fired once after the user has dragged the Graph2D window.
  713. </td>
  714. <td>
  715. <ul>
  716. <li><code>start</code> (Number): timestamp of the current start of the window.</li>
  717. <li><code>end</code> (Number): timestamp of the current end of the window.</li>
  718. </ul>
  719. </td>
  720. </tr>
  721. <tr>
  722. <td>timechange</td>
  723. <td>Fired repeatedly when the user is dragging the custom time bar.
  724. Only available when the custom time bar is enabled.
  725. </td>
  726. <td>
  727. <ul>
  728. <li><code>time</code> (Date): the current time.</li>
  729. </ul>
  730. </td>
  731. </tr>
  732. <tr>
  733. <td>timechanged</td>
  734. <td>Fired once after the user has dragged the custom time bar.
  735. Only available when the custom time bar is enabled.
  736. </td>
  737. <td>
  738. <ul>
  739. <li><code>time</code> (Date): the current time.</li>
  740. </ul>
  741. </td>
  742. </tr>
  743. </table>
  744. <h2 id="Styles">Styles</h2>
  745. <p>
  746. All parts of the Graph2D have a class name and a default css style just like the Timeline.
  747. The styles can be overwritten, which enables full customization of the layout
  748. of the Graph2D.
  749. </p>
  750. <p>
  751. Additionally, Graph2D has 10 preset styles for graphs, which are cycled through when loading groups. These styles can be overwritten
  752. as well, along with defining your own classes to style the graphs! <a href="../examples/graph2d/04_rightAxis.html">Example 4</a> and
  753. <a href="../examples/graph2d/05_bothAxis.html">example 5</a> show the usage of custom styles.
  754. </p>
  755. <h2 id="Data_Policy">Data Policy</h2>
  756. <p>
  757. All code and data is processed and rendered in the browser.
  758. No data is sent to any server.
  759. </p>
  760. </div>
  761. </body>
  762. </html>