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.

977 lines
28 KiB

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