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.

835 lines
25 KiB

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. <li><a href="#GroupOptions">Group-specific options</a></li>
  35. </ul>
  36. </li>
  37. <li><a href="#Configuration_Options">Configuration Options</a>
  38. <ul>
  39. <li><a href="#graph2dOptions">Graph2d options</a></li>
  40. <li><a href="#timelineOptions">Timeline options</a></li>
  41. </ul>
  42. </li>
  43. <li><a href="#Methods">Methods</a></li>
  44. <li><a href="#Events">Events</a></li>
  45. <li><a href="#Localization">Localization</a></li>
  46. <li><a href="#Styles">Styles</a></li>
  47. <li><a href="#Data_Policy">Data Policy</a></li>
  48. </ul>
  49. <h2 id="Example">Example</h2>
  50. <p>
  51. The following code shows how to create a Graph2d and provide it with data.
  52. More examples can be found in the <a href="../examples">examples</a> directory.
  53. </p>
  54. <pre class="prettyprint lang-html">
  55. &lt;!DOCTYPE HTML&gt;
  56. &lt;html&gt;
  57. &lt;head&gt;
  58. &lt;title&gt;Graph2d | Basic Example&lt;/title&gt;
  59. &lt;style type="text/css"&gt;
  60. body, html {
  61. font-family: sans-serif;
  62. }
  63. &lt;/style&gt;
  64. &lt;script src="../../dist/vis.js"&gt;&lt;/script&gt;
  65. &lt;link href="../../dist/vis.css" rel="stylesheet" type="text/css" /&gt;
  66. &lt;/head&gt;
  67. &lt;body&gt;
  68. &lt;div id="visualization"&gt;&lt;/div&gt;
  69. &lt;script type="text/javascript"&gt;
  70. var container = document.getElementById('visualization');
  71. var items = [
  72. {x: '2014-06-11', y: 10},
  73. {x: '2014-06-12', y: 25},
  74. {x: '2014-06-13', y: 30},
  75. {x: '2014-06-14', y: 10},
  76. {x: '2014-06-15', y: 15},
  77. {x: '2014-06-16', y: 30}
  78. ];
  79. var dataset = new vis.DataSet(items);
  80. var options = {
  81. start: '2014-06-10',
  82. end: '2014-06-18'
  83. };
  84. var Graph2d = new vis.Graph2d(container, dataset, options);
  85. &lt;/script&gt;
  86. &lt;/body&gt;
  87. &lt;/html&gt;
  88. </pre>
  89. <h2 id="Loading">Loading</h2>
  90. <p>
  91. The class name of the Graph2d is <code>vis.Graph2d</code>.
  92. When constructing a Graph2d, an HTML DOM container must be provided to attach
  93. the graph to. Optionally, data an options can be provided.
  94. Data is a vis <code>DataSet</code> or an <code>Array</code>, described in
  95. section <a href="#Data_Format">Data Format</a>.
  96. Options is a name-value map in the JSON format. The available options
  97. are described in section <a href="#Configuration_Options">Configuration Options</a>.
  98. Groups is a vis <code>DataSet</code> containing groups. The available options and the method of construction
  99. are described in section <a href="#Group_Options">Data Format</a>.
  100. </p>
  101. <pre class="prettyprint lang-js">var graph = new vis.Graph2d(container [, data] [, options] [,groups]);</pre>
  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. <h3 id="GroupOptions">Group-specific Options</h3>
  229. The groups have some options that only apply to groups and cannot be set globally. These are listed below.
  230. <pre class="prettyprint lang-js">
  231. var groups = new vis.DataSet();
  232. groups.add({
  233. id: 1,
  234. content: 'Group 1',
  235. options: {
  236. slots: { slot: 1, total: 3}
  237. }
  238. });
  239. </pre>
  240. <table>
  241. <tr>
  242. <th>Name</th>
  243. <th>Type</th>
  244. <th>Required</th>
  245. <th>Description</th>
  246. </tr>
  247. <tr>
  248. <td>slots.slot</td>
  249. <td>Number</td>
  250. <td></td>
  251. <td>The slot the bar chart is plotted in. This has to be used in combination with slots.total. See <a href="../examples/Graph2d/11_barsSideBySideGroups.html">example 11</a> for more information.</td>
  252. </tr>
  253. <tr>
  254. <td>slots.total</td>
  255. <td>Number</td>
  256. <td></td>
  257. <td>The total amount of slots available. This has to be used in combination with slots.slot. See <a href="../examples/Graph2d/11_barsSideBySideGroups.html">example 11</a> for more information.</td>
  258. </tr>
  259. </table>
  260. <h2 id="Configuration_Options">Configuration Options</h2>
  261. <h3 id="graph2dOptions">Graph2d Options</h3>
  262. Options can be used to customize the Graph2d to your purposes. These options can be passed to the Graph2d object either in
  263. the constructor, or by the <code>setOptions</code> function.
  264. <pre class="prettyprint lang-js">
  265. var options = {
  266. width: '100%',
  267. height: '400px',
  268. style: 'surface'
  269. };
  270. </pre>
  271. The options colored in green can also be used as options for the groups. All options are optional.
  272. <table>
  273. <tr>
  274. <th>Name</th>
  275. <th>Type</th>
  276. <th>Default</th>
  277. <th>Description</th>
  278. </tr>
  279. <tr>
  280. <td class="greenField">yAxisOrientation</td>
  281. <td>String</td>
  282. <td>'left'</td>
  283. <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
  284. with an axis, it will not be shown.</td>
  285. </tr>
  286. <tr>
  287. <td>defaultGroup</td>
  288. <td>String</td>
  289. <td>'default'</td>
  290. <td>This is the label for the default, ungrouped items when shown in a legend.</td>
  291. </tr>
  292. <tr>
  293. <td class="greenField">sort</td>
  294. <td>Boolean</td>
  295. <td>true</td>
  296. <td>This determines if the items are sorted automatically.
  297. They are sorted by the x value. If sort is enabled, more optimizations are possible, increasing the performance.</td>
  298. </tr>
  299. <tr>
  300. <td class="greenField">sampling</td>
  301. <td>Boolean</td>
  302. <td>true</td>
  303. <td>If sampling is enabled, Graph2d will automatically determine the amount of points per pixel.
  304. If there are more than 1 point per pixel, not all points will be drawn. Disabling sampling will cause a decrease in performance.</td>
  305. </tr>
  306. <tr>
  307. <td>graphHeight</td>
  308. <td>Number | String</td>
  309. <td>'400px'</td>
  310. <td>This is the height of the graph SVG canvas.
  311. If it is larger than the height of the outer frame, you can drag up and down
  312. the vertical direction as well as the usual horizontal direction.</td>
  313. </tr>
  314. <tr>
  315. <td class="greenField">shaded</td>
  316. <td>Boolean | Object</td>
  317. <td>false</td>
  318. <td>Toggle a shaded area with the default settings.</td>
  319. </tr>
  320. <tr>
  321. <td class="greenField">shaded.enabled</td>
  322. <td>Boolean</td>
  323. <td>false</td>
  324. <td>This toggles the shading.</td>
  325. </tr>
  326. <tr>
  327. <td class="greenField">shaded.orientation</td>
  328. <td>String</td>
  329. <td>'bottom'</td>
  330. <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>
  331. </tr>
  332. <tr>
  333. <td class="greenField">style</td>
  334. <td>String</td>
  335. <td>'line'</td>
  336. <td>This allows the user to define if this should be a linegraph or a barchart. The options are: 'line' or 'bar'.</td>
  337. </tr>
  338. <tr>
  339. <td class="greenField">barChart.width</td>
  340. <td>Number</td>
  341. <td>50</td>
  342. <td>The width of the bars.</td>
  343. </tr>
  344. <tr>
  345. <td class="greenField">barChart.align</td>
  346. <td>String</td>
  347. <td>'center'</td>
  348. <td>The alignment of the bars with regards to the coordinate. The options are 'left', 'right' or 'center'.</td>
  349. </tr>
  350. <tr>
  351. <td class="greenField">barChart.allowOverlap</td>
  352. <td>Boolean</td>
  353. <td>true</td>
  354. <td>When true, bars that have the same x coordinate are plotted on top of eachother (not stacking).
  355. See <a href="../examples/Graph2d/10_barsSideBySide.html">example 10</a> for more information.
  356. When using groups, see <a href="../examples/Graph2d/11_barsSideBySideGroups.html">example 11</a>.
  357. </td>
  358. </tr>
  359. <tr>
  360. <td class="greenField">catmullRom</td>
  361. <td>Boolean | Object</td>
  362. <td>true</td>
  363. <td>Toggle the interpolation with the default settings. For more customization use the JSON format.</td>
  364. </tr>
  365. <tr>
  366. <td class="greenField">catmullRom.enabled</td>
  367. <td>Boolean</td>
  368. <td>true</td>
  369. <td>Toggle the interpolation.</td>
  370. </tr>
  371. <tr>
  372. <td class="greenField">catmullRom.parametrization</td>
  373. <td>String</td>
  374. <td>'centripetal'</td>
  375. <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.
  376. If catmullRom is disabled, linear interpolation is used.</td>
  377. </tr>
  378. <tr>
  379. <td class="greenField">drawPoints</td>
  380. <td>Boolean | Object</td>
  381. <td>true</td>
  382. <td>Toggle the drawing of the datapoints with the default settings.</td>
  383. </tr>
  384. <tr>
  385. <td class="greenField">drawPoints.enabled</td>
  386. <td>Boolean</td>
  387. <td>true</td>
  388. <td>Toggle the drawing of the datapoints.</td>
  389. </tr>
  390. <tr>
  391. <td class="greenField">drawPoints.size</td>
  392. <td>Number</td>
  393. <td>6</td>
  394. <td>Determine the size at which the data points are drawn.</td>
  395. </tr>
  396. <tr>
  397. <td class="greenField">drawPoints.style</td>
  398. <td>String</td>
  399. <td>'square'</td>
  400. <td>Determine the shape of the data points. The options are 'square' or 'circle'.</td>
  401. </tr>
  402. <tr>
  403. <td>dataAxis.showMinorLabels</td>
  404. <td>Boolean</td>
  405. <td>true</td>
  406. <td>Toggle the drawing of the minor labels on the Y axis.</td>
  407. </tr>
  408. <tr>
  409. <td>dataAxis.showMajorLabels</td>
  410. <td>Boolean</td>
  411. <td>true</td>
  412. <td>Toggle the drawing of the major labels on the Y axis.</td>
  413. </tr>
  414. <tr>
  415. <td>dataAxis.icons</td>
  416. <td>Boolean</td>
  417. <td>false</td>
  418. <td>Toggle the drawing of automatically generated icons the Y axis.</td>
  419. </tr>
  420. <tr>
  421. <td>dataAxis.width</td>
  422. <td>Number | String</td>
  423. <td>'40px'</td>
  424. <td>Set the (minimal) width of the yAxis. The axis will resize to accomodate the labels of the Y values.</td>
  425. </tr>
  426. <tr>
  427. <td>dataAxis.visible</td>
  428. <td>Boolean</td>
  429. <td>true</td>
  430. <td>Show or hide the data axis.</td>
  431. </tr>
  432. <tr>
  433. <td>legend</td>
  434. <td>Boolean</td>
  435. <td>false</td>
  436. <td>Toggle the legend with the default settings.</td>
  437. </tr>
  438. <tr>
  439. <td>legend.enabled</td>
  440. <td>Boolean</td>
  441. <td>false</td>
  442. <td>Toggle the legend.</td>
  443. </tr>
  444. <tr>
  445. <td>legend.icons</td>
  446. <td>Boolean</td>
  447. <td>true</td>
  448. <td>Show automatically generated icons on the legend.</td>
  449. </tr>
  450. <tr>
  451. <td>legend.left.visible</td>
  452. <td>Boolean</td>
  453. <td>true</td>
  454. <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>
  455. </tr>
  456. <tr>
  457. <td>legend.left.position</td>
  458. <td>String</td>
  459. <td>'top-left'</td>
  460. <td>Determine the position of the legend coupled to the left axis. Options are 'top-left', 'top-right', 'bottom-left' or 'bottom-right'.</td>
  461. </tr>
  462. <tr>
  463. <td>legend.right.visible</td>
  464. <td>Boolean</td>
  465. <td>true</td>
  466. <td>This toggles the visibility of the legend that is coupled with the right axis.</td>
  467. </tr>
  468. <tr>
  469. <td>legend.right.position</td>
  470. <td>String</td>
  471. <td>'top-right'</td>
  472. <td>Determine the position of the legend coupled to the right axis. Options are 'top-left', 'top-right', 'bottom-left' or 'bottom-right'.</td>
  473. </tr>
  474. </table>
  475. <h3 id="timelineOptions">Timeline Options</h3>
  476. <p>
  477. Graph2d is built upon the framework of the Timeline. All options from the Timeline can be used with Graph2d. The options available for the Timeline are listed here:
  478. </p>
  479. <p>
  480. <a href="timeline.html#Configuration_Options">timeline.html#Configuration_options</a>
  481. </p>
  482. <h2 id="Methods">Methods</h2>
  483. <p>
  484. The Graph2d supports the following methods.
  485. </p>
  486. <table>
  487. <tr>
  488. <th>Method</th>
  489. <th>Return Type</th>
  490. <th>Description</th>
  491. </tr>
  492. <tr>
  493. <td>clear([what])</td>
  494. <td>none</td>
  495. <td>
  496. Clear the Graph2d. An object can be passed specifying which sections to clear: items, groups,
  497. and/or options. By Default, items, groups and options are cleared, i.e. <code>what = {items: true, groups: true, options: true}</code>. Example usage:
  498. <pre class="prettyprint lang-js">Graph2d.clear(); // clear items, groups, and options
  499. Graph2d.clear({options: true}); // clear options only
  500. </pre>
  501. </td>
  502. </tr>
  503. <tr>
  504. <td>destroy()</td>
  505. <td>none</td>
  506. <td>Destroy the Graph2d. The Graph2d is removed from memory. all DOM elements and event listeners are cleaned up.
  507. </td>
  508. </tr>
  509. <tr>
  510. <td>getCustomTime()</td>
  511. <td>Date</td>
  512. <td>Retrieve the custom time. Only applicable when the option <code>showCustomTime</code> is true.
  513. </td>
  514. </tr>
  515. <tr>
  516. <td>setCustomTime(time)</td>
  517. <td>none</td>
  518. <td>Adjust the custom time bar. Only applicable when the option <code>showCustomTime</code> is true. <code>time</code> is a Date object.
  519. </td>
  520. </tr>
  521. <tr>
  522. <td>getLegend(groupId, iconWidth, iconHeight)</td>
  523. <td>SVGelement, String, String</td>
  524. <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).
  525. </td>
  526. </tr>
  527. <tr>
  528. <td>getWindow()</td>
  529. <td>Object</td>
  530. <td>Get the current visible window. Returns an object with properties <code>start: Date</code> and <code>end: Date</code>.</td>
  531. </tr>
  532. <tr>
  533. <td>getItemRange()</td>
  534. <td>Object</td>
  535. <td>Get the range of all the items as an object containing <code>min: Date</code> and <code>max: Date</code>.</td>
  536. </tr>
  537. <tr>
  538. <td>fit()</td>
  539. <td>none</td>
  540. <td>Adjust the visible window such that it fits all items.
  541. </td>
  542. </tr>
  543. <tr>
  544. <td>on(event, callback)</td>
  545. <td>none</td>
  546. <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>
  547. </tr>
  548. <tr>
  549. <td>off(event, callback)</td>
  550. <td>none</td>
  551. <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>
  552. </tr>
  553. <tr>
  554. <td>redraw()</td>
  555. <td>none</td>
  556. <td>Force a redraw of the Graph2d. Can be useful to manually redraw when option autoResize=false.
  557. </td>
  558. </tr>
  559. <tr>
  560. <td>isGroupVisible(groupId)</td>
  561. <td>Boolean</td>
  562. <td>This checks if the visible option of the supplied group (by ID) is true or false.
  563. </td>
  564. </tr>
  565. <tr>
  566. <td>setGroups(groups)</td>
  567. <td>none</td>
  568. <td>Set a data set with groups for the Graph2d.
  569. <code>groups</code> can be an Array with Objects,
  570. a DataSet, or a DataView. For each of the groups, the items of the
  571. Graph2d are filtered on the property <code>group</code>, which
  572. must correspond with the id of the group.
  573. </td>
  574. </tr>
  575. <tr>
  576. <td>setItems(items)</td>
  577. <td>none</td>
  578. <td>Set a data set with items for the Graph2d.
  579. <code>items</code> can be an Array with Objects,
  580. a DataSet, or a DataView.
  581. </td>
  582. </tr>
  583. <tr>
  584. <td>setOptions(options)</td>
  585. <td>none</td>
  586. <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.
  587. </td>
  588. </tr>
  589. <tr>
  590. <td>setWindow(start, end)</td>
  591. <td>none</td>
  592. <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>
  593. </tr>
  594. </table>
  595. <h2 id="Events">Events</h2>
  596. <p>
  597. Graph2d fires events when changing the visible window by dragging, when
  598. selecting items, and when dragging the custom time bar.
  599. </p>
  600. <p>
  601. Here an example on how to listen for a <code>rangeChanged</code> event.
  602. </p>
  603. <pre class="prettyprint lang-js">
  604. Graph2d.on('select', function (properties) {
  605. alert('selected items: ' + properties.nodes);
  606. });
  607. </pre>
  608. <p>
  609. A listener can be removed via the function <code>off</code>:
  610. </p>
  611. <pre class="prettyprint lang-js">
  612. function onChange (properties) {
  613. alert('changed!');
  614. }
  615. // add event listener
  616. Graph2d.on('rangechanged', onChange);
  617. // do stuff...
  618. // remove event listener
  619. Graph2d.off('rangechanged', onChange);
  620. </pre>
  621. <p>
  622. The following events are available.
  623. </p>
  624. <table>
  625. <colgroup>
  626. <col style="width: 20%;">
  627. <col style="width: 40%;">
  628. <col style="width: 40%;">
  629. </colgroup>
  630. <tr>
  631. <th>name</th>
  632. <th>Description</th>
  633. <th>Properties</th>
  634. </tr>
  635. <tr>
  636. <td>rangechange</td>
  637. <td>Fired repeatedly when the user is dragging the Graph2d window.
  638. </td>
  639. <td>
  640. <ul>
  641. <li><code>start</code> (Number): timestamp of the current start of the window.</li>
  642. <li><code>end</code> (Number): timestamp of the current end of the window.</li>
  643. </ul>
  644. </td>
  645. </tr>
  646. <tr>
  647. <td>rangechanged</td>
  648. <td>Fired once after the user has dragged the Graph2d window.
  649. </td>
  650. <td>
  651. <ul>
  652. <li><code>start</code> (Number): timestamp of the current start of the window.</li>
  653. <li><code>end</code> (Number): timestamp of the current end of the window.</li>
  654. </ul>
  655. </td>
  656. </tr>
  657. <tr>
  658. <td>timechange</td>
  659. <td>Fired repeatedly when the user is dragging the custom time bar.
  660. Only available when the custom time bar is enabled.
  661. </td>
  662. <td>
  663. <ul>
  664. <li><code>time</code> (Date): the current time.</li>
  665. </ul>
  666. </td>
  667. </tr>
  668. <tr>
  669. <td>timechanged</td>
  670. <td>Fired once after the user has dragged the custom time bar.
  671. Only available when the custom time bar is enabled.
  672. </td>
  673. <td>
  674. <ul>
  675. <li><code>time</code> (Date): the current time.</li>
  676. </ul>
  677. </td>
  678. </tr>
  679. </table>
  680. <h2 id="Localization">Localization</h2>
  681. <p>
  682. 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.
  683. </p>
  684. <p>
  685. To set a locale for the Graph2d, specify the option <code>locale</code>:
  686. </p>
  687. <pre class="prettyprint lang-js">var options = {
  688. locale: 'nl'
  689. };
  690. </pre>
  691. <h3>Create a new locale</h3>
  692. To load a locale into the Graph2d not supported by default, one can add a new locale to the option <code>locales</code>:
  693. <pre class="prettyprint lang-js">var options = {
  694. locales: {
  695. // create a new locale
  696. mylocale: {
  697. current: 'current',
  698. time: 'time',
  699. }
  700. },
  701. // use the new locale
  702. locale: 'mylocale'
  703. };
  704. </pre>
  705. <h3 id="available-locales">Available locales</h3>
  706. Graph2d comes with support for the following locales:
  707. <table>
  708. <tr><th>Language</th><th>Code</th></tr>
  709. <tr>
  710. <td>English</td>
  711. <td>
  712. <code>en</code><br>
  713. <code>en_EN</code><br>
  714. <code>en_US</code>
  715. </td>
  716. </tr>
  717. <tr>
  718. <td>Dutch</td>
  719. <td>
  720. <code>nl</code><br>
  721. <code>nl_NL</code><br>
  722. <code>nl_BE</code>
  723. </td>
  724. </tr>
  725. </table>
  726. <h2 id="Styles">Styles</h2>
  727. <p>
  728. All parts of the Graph2d have a class name and a default css style just like the Graph2d.
  729. The styles can be overwritten, which enables full customization of the layout
  730. of the Graph2d.
  731. </p>
  732. <p>
  733. Additionally, Graph2d has 10 preset styles for graphs, which are cycled through when loading groups. These styles can be overwritten
  734. as well, along with defining your own classes to style the graphs! <a href="../examples/Graph2d/04_rightAxis.html">Example 4</a> and
  735. <a href="../examples/Graph2d/05_bothAxis.html">example 5</a> show the usage of custom styles.
  736. </p>
  737. <h2 id="Data_Policy">Data Policy</h2>
  738. <p>
  739. All code and data is processed and rendered in the browser.
  740. No data is sent to any server.
  741. </p>
  742. </div>
  743. </body>
  744. </html>