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.

1511 lines
60 KiB

9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  5. <meta charset="utf-8">
  6. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  7. <meta name="viewport" content="width=device-width, initial-scale=1">
  8. <meta name="description" content="">
  9. <meta name="author" content="">
  10. <title>vis.js - A dynamic, browser based visualization library.</title>
  11. <!-- Bootstrap core CSS -->
  12. <link href="../css/bootstrap.css" rel="stylesheet">
  13. <!-- Tipue vendor css -->
  14. <link href="../css/tipuesearch.css" rel="stylesheet">
  15. <link href="../css/style.css" rel="stylesheet">
  16. <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
  17. <!--[if lt IE 9]>
  18. <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
  19. <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
  20. <![endif]-->
  21. <link href="../css/prettify.css" type="text/css" rel="stylesheet"/>
  22. <script type="text/javascript" src="../js/googleAnalytics.js"></script>
  23. <script type="text/javascript" src="../js/prettify/prettify.js"></script>
  24. <script src="../js/smooth-scroll.min.js"></script>
  25. <script language="JavaScript">
  26. smoothScroll.init();
  27. </script>
  28. <style>
  29. tr.subHeader {
  30. font-weight: bold;
  31. font-style: italic;
  32. }
  33. tr.subHeader td {
  34. padding-top: 30px;
  35. }
  36. td.midMethods {
  37. width: 150px;
  38. background-color: #ffffff;
  39. border: 1px solid #dddddd;
  40. }
  41. tr.visible td {
  42. padding: 10px;
  43. }
  44. h2 {
  45. margin-top:50px;
  46. }
  47. td.greenField {
  48. background-color: #b8e030;
  49. }
  50. </style>
  51. <script>
  52. function toggleGettingStarted(aThis) {
  53. var gettingStartedDiv = document.getElementById('gettingStarted');
  54. if (aThis.innerHTML.indexOf("Show") !== -1) {
  55. gettingStartedDiv.className = '';
  56. aThis.innerHTML = 'Hide the getting started again.';
  57. }
  58. else {
  59. gettingStartedDiv.className = 'hidden';
  60. aThis.innerHTML = 'Show the getting started!';
  61. }
  62. }
  63. </script>
  64. <script type="text/javascript" src="../js/toggleTable.js"></script>
  65. </head>
  66. <body onload="prettyPrint();">
  67. <div class="navbar-wrapper">
  68. <div class="container">
  69. <nav class="navbar navbar-inverse navbar-static-top" role="navigation">
  70. <div class="container">
  71. <div class="navbar-header">
  72. <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar"
  73. aria-expanded="false" aria-controls="navbar">
  74. <span class="sr-only">Toggle navigation</span>
  75. <span class="icon-bar"></span>
  76. <span class="icon-bar"></span>
  77. <span class="icon-bar"></span>
  78. </button>
  79. <a class="navbar-brand hidden-sm" href="./index.html">vis.js</a>
  80. </div>
  81. <div id="navbar" class="navbar-collapse collapse">
  82. <ul class="nav navbar-nav">
  83. <li><a href="http://www.visjs.org/index.html#modules">Modules</a></li>
  84. <li><a href="http://www.visjs.org/blog.html">Blog</a></li>
  85. <li><a href="http://www.visjs.org/index.html#download_install">Download</a></li>
  86. <li><a href="http://www.visjs.org/showcase/index.html">Showcase</a></li>
  87. <li><a href="http://www.visjs.org/index.html#contribute">Contribute</a></li>
  88. <li><a href="http://www.visjs.org/featureRequests.html">Feature requests</a></li>
  89. <li><a href="http://www.visjs.org/index.html#licenses">License</a></li>
  90. </ul>
  91. <form class="navbar-form navbar-right" role="search">
  92. <input name="q" id="tipue_search_input" autocomplete="off" type="text" class="form-control" placeholder="Enter keywords">
  93. <button type="submit" class="btn btn-default">Go!</button>
  94. </form>
  95. <div id="search-results-wrapper" class="panel panel-default">
  96. <div class="panel-body">
  97. <div id="tipue_search_content"></div>
  98. </div>
  99. </div>
  100. <div id="keyword-info" class="panel panel-success">
  101. <div class="panel-body">
  102. Found <span id="keyword-count"></span> results. Click <a id="keyword-jumper-button" href="">here</a> to jump to the first keyword occurence!
  103. </div>
  104. </div>
  105. </div>
  106. </div>
  107. </nav>
  108. </div>
  109. </div>
  110. <a href="https://github.com/almende/vis" class="hidden-xs hidden-sm hidden-md"><img
  111. style="position: absolute; top: 0; right: 0; border: 0;"
  112. src="https://camo.githubusercontent.com/38ef81f8aca64bb9a64448d0d70f1308ef5341ab/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f6461726b626c75655f3132313632312e706e67"
  113. alt="Fork me on GitHub"
  114. data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png"></a>
  115. <div class="container full">
  116. <h1>Graph2d</h1>
  117. <p>
  118. Graph2d is an interactive visualization chart to draw data in a 2D graph.
  119. You can freely move and zoom in the graph by dragging and scrolling in the
  120. window.
  121. </p>
  122. <p>
  123. Graph2d uses HTML DOM and SVG for rendering. This allows for flexible
  124. customization using css styling.
  125. </p>
  126. <h2 id="Contents">Contents</h2>
  127. <ul>
  128. <li><a href="#Data_Format">Data Format</a>
  129. <ul>
  130. <li><a href="#items">Items</a></li>
  131. <li><a href="#groups">Groups</a></li>
  132. </ul>
  133. </li>
  134. <li><a href="#Configuration_Options">Configuration Options</a>
  135. <ul>
  136. <li><a href="#graph2dOptions">Graph2d options</a></li>
  137. <li><a href="#timelineOptions">Timeline options</a></li>
  138. </ul>
  139. </li>
  140. <li><a href="#Methods">Methods</a></li>
  141. <li><a href="#Events">Events</a></li>
  142. <li><a href="#Localization">Localization</a></li>
  143. <li><a href="#Time_zone">Time zone</a></li>
  144. <li><a href="#Styles">Styles</a></li>
  145. </ul>
  146. <a class="btn btn-primary" role="button" onclick="toggleGettingStarted(this)">Show the getting started!</a>
  147. <div id="gettingStarted" class="hidden">
  148. <h3>Creating a Graph2d</h3>
  149. <p>
  150. The following code shows how to create a Graph2d and provide it with data.
  151. More examples can be found in the <a href="../../examples">examples</a> directory.</p>
  152. <pre class="prettyprint lang-html options">
  153. &lt;!DOCTYPE HTML&gt;
  154. &lt;html&gt;
  155. &lt;head&gt;
  156. &lt;title&gt;Graph2d or Basic Example&lt;/title&gt;
  157. &lt;style type="text/css"&gt;
  158. body, html {
  159. font-family: sans-serif;
  160. }
  161. &lt;/style&gt;
  162. &lt;script src="../../dist/vis.js"&gt;&lt;/script&gt;
  163. &lt;link href="../../dist/vis.css" rel="stylesheet" type="text/css" /&gt;
  164. &lt;/head&gt;
  165. &lt;body&gt;
  166. &lt;div id="visualization"&gt;&lt;/div&gt;
  167. &lt;script type="text/javascript"&gt;
  168. var container = document.getElementById('visualization');
  169. var items = [
  170. {x: '2014-06-11', y: 10},
  171. {x: '2014-06-12', y: 25},
  172. {x: '2014-06-13', y: 30},
  173. {x: '2014-06-14', y: 10},
  174. {x: '2014-06-15', y: 15},
  175. {x: '2014-06-16', y: 30}
  176. ];
  177. var dataset = new vis.DataSet(items);
  178. var options = {
  179. start: '2014-06-10',
  180. end: '2014-06-18'
  181. };
  182. var Graph2d = new vis.Graph2d(container, dataset, options);
  183. &lt;/script&gt;
  184. &lt;/body&gt;
  185. &lt;/html&gt;
  186. </pre>
  187. <p><a href="http://visjs.org/examples/graph2d/01_basic.html" target="_blank">The result of the code above will be the basic example which is shown here.</a></p>
  188. <h2 id="Loading">Loading</h2>
  189. <p>
  190. The class name of the Graph2d is <code>vis.Graph2d</code>.
  191. When constructing a Graph2d, an HTML DOM container must be provided to attach
  192. the graph to. Optionally, data an options can be provided.
  193. Data is a vis <code>DataSet</code> or an <code>Array</code>, described in
  194. section <a href="#Data_Format">Data Format</a>.
  195. Options is a name-value map in the JSON format. The available options
  196. are described in section <a href="#Configuration_Options">Configuration Options</a>.
  197. Groups is a vis <code>DataSet</code> containing groups. The available options and the method of construction
  198. are described in section <a href="#Data_Format">Data Format</a>.
  199. </p>
  200. <pre class="prettyprint lang-js options">var graph = new vis.Graph2d(container [, data] [, groups] [, options]);</pre>
  201. For backwards compatibility, groups and options can be interchanged.
  202. <p>
  203. Data, options and groups can be set or changed later on using the functions
  204. <code>Graph2d.setItems(data)</code>, <code>Graph2d.setOptions(options)</code> and <code>Graph2d.setGroups(groups)</code>.
  205. </p>
  206. <br>
  207. </div>
  208. <br>
  209. <br>
  210. <h2 id="Data_Format">Data Format</h2>
  211. <p>
  212. Graph2d can load data from an <code>Array</code>, a <code>DataSet</code> (offering 2 way data binding), or a <code>DataView</code> (offering one way data binding).
  213. Objects are added to this DataSet by using the <code>add()</code> function.
  214. <p>
  215. Graph2d can be provided with two types of data:
  216. </p>
  217. <ul>
  218. <li><a href="#items">Items</a> containing a set of points to be displayed.</li>
  219. <li><a href="#groups">Groups</a> containing a set of groups used to group items
  220. together. All items belonging to a group will be drawn as a single graph.</li>
  221. </ul>
  222. <h3 id="items">Items</h3>
  223. <pre class="prettyprint lang-js options">
  224. var items = [
  225. {x: '2014-06-13', y: 30, group: 0},
  226. {x: '2014-06-14', y: 10, group: 0},
  227. {x: '2014-06-15', y: 15, group: 1},
  228. {x: '2014-06-16', y: 30, group: 1},
  229. {x: '2014-06-17', y: 10, group: 1},
  230. {x: '2014-06-18', y: 15, group: 1}
  231. ];
  232. </pre>
  233. <table class="properties">
  234. <tr>
  235. <th>Name</th>
  236. <th>Type</th>
  237. <th>Required</th>
  238. <th>Description</th>
  239. </tr>
  240. <tr>
  241. <td>x</td>
  242. <td>Date</td>
  243. <td>yes</td>
  244. <td>Location on the x-axis.</td>
  245. </tr>
  246. <tr>
  247. <td>y</td>
  248. <td>Number</td>
  249. <td>yes</td>
  250. <td>Location on the y-axis.</td>
  251. </tr>
  252. <tr>
  253. <td>group</td>
  254. <td>Number or string</td>
  255. <td>no</td>
  256. <td>The ID of the group this point belongs to.</td>
  257. </tr>
  258. <tr>
  259. <td>label</td>
  260. <td>Object</td>
  261. <td>no</td>
  262. <td>A label object which will be displayed near to the item. A label object has one requirement - a <b> content </b> property. In addition you can set the <b> xOffset, yOffset and className </b> for further appearance customisations </td>
  263. </tr>
  264. </table>
  265. <h3 id="groups">Groups</h3>
  266. <p>
  267. Like the items, groups are regular JavaScript Arrays and Objects.
  268. Using groups, items can be grouped together.
  269. Items are filtered per group, and displayed as individual graphs. Groups can contain the properties <code>id</code>,
  270. <code>content</code>, <code>className</code> (optional) and <code>options</code> (optional).
  271. </p>
  272. <p>
  273. Groups can be applied to a timeline using the method <code>setGroups</code>.
  274. A table with groups can be created like:
  275. </p>
  276. <pre class="prettyprint lang-js options">
  277. var groups = new vis.DataSet();
  278. groups.add({
  279. id: 1,
  280. content: 'Group 1',
  281. // Optional: a field 'visible'
  282. // Optional: a field 'className'
  283. // Optional: options
  284. })
  285. groups.add({
  286. // more groups...
  287. });
  288. </pre>
  289. <p>
  290. Groups can have the following properties:
  291. </p>
  292. <table class="properties">
  293. <tr>
  294. <th>Name</th>
  295. <th>Type</th>
  296. <th>Required</th>
  297. <th>Description</th>
  298. </tr>
  299. <tr>
  300. <td>id</td>
  301. <td>String or Number</td>
  302. <td>yes</td>
  303. <td>An id for the group. The group will display all items having a
  304. property <code>group</code> which matches the <code>id</code>
  305. of the group.</td>
  306. </tr>
  307. <tr>
  308. <td>content</td>
  309. <td>String</td>
  310. <td>yes</td>
  311. <td>The contents of the group. This can be plain text or html code.</td>
  312. </tr>
  313. <tr>
  314. <td>className</td>
  315. <td>String</td>
  316. <td>no</td>
  317. <td>This field is optional. A className can be used to give groups
  318. an individual css style.
  319. </td>
  320. </tr>
  321. <tr>
  322. <td>style</td>
  323. <td>String</td>
  324. <td>no</td>
  325. <td>This field is optional. A style can be used to give groups
  326. an individual css style, and any style tags specified in style will
  327. override the definition in the className style defined in css.
  328. </td>
  329. </tr>
  330. <tr>
  331. <td>options</td>
  332. <td>Object</td>
  333. <td>no</td>
  334. <td>This field is optional. The options can be used to give a group a specific draw style.
  335. Any options that are colored green in the Configuration Options can be used as options here.
  336. </tr>
  337. <tr>
  338. <td>visible</td>
  339. <td>Boolean</td>
  340. <td>no</td>
  341. <td>This field is optional. If false, this group will not be drawn. By default it is true.
  342. </tr>
  343. </table>
  344. <h2 id="Configuration_Options">Configuration Options</h2>
  345. <h3 id="graph2dOptions">Graph2d Options</h3>
  346. Options can be used to customize the Graph2d to your purposes. These options can be passed to the Graph2d object either in
  347. the constructor, or by the <code>setOptions</code> function.
  348. <pre class="prettyprint lang-js options">
  349. var options = {
  350. width: '100%',
  351. height: '400px',
  352. style: 'surface'
  353. };
  354. </pre>
  355. The options colored in green can also be used as options for the groups. All options are optional.
  356. <table class="options" id="g2dOptions">
  357. <tr>
  358. <th>Name</th>
  359. <th>Type</th>
  360. <th>Default</th>
  361. <th>Description</th>
  362. </tr>
  363. <tr>
  364. <td>defaultGroup</td>
  365. <td>String</td>
  366. <td>'default'</td>
  367. <td>This is the label for the default, ungrouped items when shown in a legend.</td>
  368. </tr>
  369. <tr class='toggle collapsible' onclick="toggleTable('g2dOptions','barChart', this);">
  370. <td class="greenField"><span parent="barChart" class="right-caret"></span> barChart</td>
  371. <td>Object</td>
  372. <td></td>
  373. <td>Define the properties of the barchart style.</td>
  374. </tr>
  375. <tr parent="barChart" class="hidden">
  376. <td class="greenField indent">barChart.align</td>
  377. <td>String</td>
  378. <td>'center'</td>
  379. <td>The alignment of the bars with regards to the coordinate. The options are 'left', 'right' or 'center'.</td>
  380. </tr>
  381. <tr parent="barChart" class="hidden">
  382. <td class="greenField indent">barChart.sideBySide</td>
  383. <td>Boolean</td>
  384. <td>false</td>
  385. <td>If two datapoints of a barchart overlap, they are drawn over eachother by default. If sideBySide is set to true, they will be drawn side by side, within the same width as a single bar..
  386. See <a href="../../examples/graph2d/10_barsSideBySide.html">example 10</a> for more information.
  387. When using groups, see <a href="../../examples/graph2d/11_barsSideBySideGroups.html">example 11</a>.
  388. </td>
  389. </tr>
  390. <tr parent="barChart" class="hidden">
  391. <td class="greenField indent">barChart.width</td>
  392. <td>Number</td>
  393. <td>50</td>
  394. <td>The width of the bars.</td>
  395. </tr>
  396. <tr parent="barChart" class="hidden">
  397. <td class="greenField indent">barChart.minWidth</td>
  398. <td>Number</td>
  399. <td></td>
  400. <td>The minimum width of the bars in pixels: by default the bars get smaller while zooming out to prevent overlap, this value is the minimum width of the bar. Default behavior (when minWidth is not set) is 10% of the bar width.</td>
  401. </tr>
  402. <tr class='toggle collapsible' onclick="toggleTable('g2dOptions','dataAxis', this);">
  403. <td><span parent="dataAxis" class="right-caret"></span> dataAxis</td>
  404. <td>Object</td>
  405. <td></td>
  406. <td>Define the properties of the left and right dataAxis.</td>
  407. </tr>
  408. <tr parent="dataAxis" class="hidden">
  409. <td class="indent">dataAxis.alignZeros</td>
  410. <td>Boolean</td>
  411. <td>true</td>
  412. <td>When using multiple axis, the right one is slaved to the left one. If you need to ensure that the zero-lines are on the same
  413. height, you can turn this option on.</td>
  414. </tr>
  415. <tr parent="dataAxis" class="hidden">
  416. <td class="indent">dataAxis.icons</td>
  417. <td>Boolean</td>
  418. <td>false</td>
  419. <td>Toggle the drawing of automatically generated icons the Y axis.</td>
  420. </tr>
  421. <tr parent="dataAxis" class="hidden">
  422. <td class="indent2">dataAxis.left.format</td>
  423. <td>Function</td>
  424. <td></td>
  425. <td>Insert a custom function on how to format the label. The function will receive a numeric value and has to return a string. Default function is:
  426. <pre class="prettyprint lang-js">
  427. function (value) {
  428. return ''+value.toPrecision(3);
  429. }</pre>
  430. </td>
  431. </tr>
  432. <tr parent="dataAxis" class="hidden">
  433. <td class="indent2">dataAxis.left.range.min</td>
  434. <td>Number</td>
  435. <td>undefined</td>
  436. <td>Set the minimum value of the left y-Axis.</td>
  437. </tr>
  438. <tr parent="dataAxis" class="hidden">
  439. <td class="indent2">dataAxis.left.range.max</td>
  440. <td>Number</td>
  441. <td>undefined</td>
  442. <td>Set the maximum value of the left y-Axis.</td>
  443. </tr>
  444. <tr parent="dataAxis" class="hidden">
  445. <td class="indent2">dataAxis.left.title.style</td>
  446. <td>String</td>
  447. <td>undefined</td>
  448. <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>
  449. </tr>
  450. <tr parent="dataAxis" class="hidden">
  451. <td class="indent2">dataAxis.left.title.text</td>
  452. <td>String</td>
  453. <td>undefined</td>
  454. <td>Set the title for the left axis.</td>
  455. </tr>
  456. <tr parent="dataAxis" class="hidden">
  457. <td class="indent2">dataAxis.right.format</td>
  458. <td>Function</td>
  459. <td></td>
  460. <td>Same explaination as the left side.</td>
  461. </tr>
  462. <tr parent="dataAxis" class="hidden">
  463. <td class="indent2">dataAxis.right.range.min</td>
  464. <td>Number</td>
  465. <td>undefined</td>
  466. <td>Set the minimum value of the right y-Axis.</td>
  467. </tr>
  468. <tr parent="dataAxis" class="hidden">
  469. <td class="indent2">dataAxis.right.range.max</td>
  470. <td>Number</td>
  471. <td>undefined</td>
  472. <td>Set the maximum value of the right y-Axis.</td>
  473. </tr>
  474. <tr parent="dataAxis" class="hidden">
  475. <td class="indent2">dataAxis.right.title.style</td>
  476. <td>String</td>
  477. <td>undefined</td>
  478. <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>
  479. </tr>
  480. <tr parent="dataAxis" class="hidden">
  481. <td class="indent2">dataAxis.right.title.text</td>
  482. <td>String</td>
  483. <td>undefined</td>
  484. <td>Set the title for the right axis.</td>
  485. </tr>
  486. <tr parent="dataAxis" class="hidden">
  487. <td class="indent">dataAxis.showMinorLabels</td>
  488. <td>Boolean</td>
  489. <td>true</td>
  490. <td>Toggle the drawing of the minor labels on the Y axis.</td>
  491. </tr>
  492. <tr parent="dataAxis" class="hidden">
  493. <td class="indent">dataAxis.showMajorLabels</td>
  494. <td>Boolean</td>
  495. <td>true</td>
  496. <td>Toggle the drawing of the major labels on the Y axis.</td>
  497. </tr>
  498. <tr parent="dataAxis" class="hidden">
  499. <td class="indent">dataAxis.visible</td>
  500. <td>Boolean</td>
  501. <td>true</td>
  502. <td>Show or hide the data axis.</td>
  503. </tr>
  504. <tr parent="dataAxis" class="hidden">
  505. <td class="indent">dataAxis.width</td>
  506. <td>Number or String</td>
  507. <td>'40px'</td>
  508. <td>Set the (minimal) width of the yAxis. The axis will resize to accomodate the labels of the Y values.</td>
  509. </tr>
  510. <tr class='toggle collapsible' onclick="toggleTable('g2dOptions','drawPoints', this);">
  511. <td class="greenField"><span parent="drawPoints" class="right-caret"></span> drawPoints</td>
  512. <td>Boolean, Object or Function</td>
  513. <td>true</td>
  514. <td>Defines rendering options for the datapoints.
  515. Three different types of objects can be assigned to this property. See <a href="../../examples/graph2d/19_labels.html">Example 19</a> for an illustration.<br />
  516. 1. <code>Boolean</code>: When true is provided every datapoint will be drawn, false otherwise.<br />
  517. <pre class="prettyprint lang-js">
  518. drawPoints: true // or false
  519. </pre>
  520. 2. <code>Object</code> (the 'rendering' options): If an object is provided it may contain following properties which all can be optional: <code>onRender</code>, <code>className</code><code>size</code> and/or <code>style</code>. For more information check the property's documentation.<br />
  521. <pre class="prettyprint lang-js">
  522. drawPoints: {
  523. size: 3,
  524. style: 'square'
  525. }
  526. </pre>
  527. 3. <code>Function</code>: If a function is provided it will be used as a callback. The function may return values from listing 1 or 2.<br />
  528. <pre class="prettyprint lang-js">
  529. drawPoints: function(item, group) {
  530. ...
  531. }
  532. </pre>
  533. If a rendering property from the rendering option object is missing, the missing property will be fetched from the group's option.
  534. <br />
  535. All of these three options can be defined within the drawPoints properties separately as well.
  536. </td>
  537. </tr>
  538. <tr parent="drawPoints" class="hidden">
  539. <td class="greenField indent">drawPoints.enabled</td>
  540. <td>Boolean</td>
  541. <td>true</td>
  542. <td>Toggles the drawing of the datapoints.</td>
  543. </tr>
  544. <tr parent="drawPoints" class="hidden">
  545. <td class="greenField indent">drawPoints.onRender</td>
  546. <td>function</td>
  547. <td>none</td>
  548. <td>Defines a render function for every datapoint.
  549. If a group has no <code>drawPoints.onRender</code> callback, the graph2d <code>drawPoints.onRender</code> callback will be used.
  550. If neither is defined, the datapoint will be rendered according to the group setting of <code>drawPoints.enabled</code>.
  551. This callback must return <code>true</code> if the datapoint should be rendered, otherwise <code>false</code>.
  552. <pre class="prettyprint lang-js">
  553. drawPoints: {
  554. enabled: true,
  555. onRender: function(item, group, graph2d) {
  556. // only renders items with labels
  557. return item.label != null;
  558. }
  559. }
  560. </pre>
  561. This callback may also return an object containing a <code>size</code> and <code>style</code> property, both are optional, e.g.:
  562. <pre class="prettyprint lang-js">
  563. onRender: function(item, group, graph2d) {
  564. if (item.label == null) {
  565. return false;
  566. }
  567. return {
  568. style: 'circle',
  569. size: 30
  570. };
  571. }
  572. </pre>
  573. The properties <code>className</code>, <code>style</code> and <code>size</code> returned from the callback will be used for rendering the datapoint.
  574. If a property is missing in the rendering option object, the missing property will be fetched from the group's option.
  575. </td>
  576. </tr>
  577. <tr parent="drawPoints" class="hidden">
  578. <td class="greenField indent">drawPoints.size</td>
  579. <td>Number</td>
  580. <td>6</td>
  581. <td>Determine the size at which the data points are drawn.</td>
  582. </tr>
  583. <tr parent="drawPoints" class="hidden">
  584. <td class="greenField indent">drawPoints.style</td>
  585. <td>String</td>
  586. <td>'square'</td>
  587. <td>Determine the shape of the data points. The options are 'square' or 'circle'.</td>
  588. </tr>
  589. <tr>
  590. <td>graphHeight</td>
  591. <td>Number or String</td>
  592. <td>'400px'</td>
  593. <td>This is the height of the graph SVG canvas.
  594. If it is larger than the height of the outer frame, you can drag up and down
  595. the vertical direction as well as the usual horizontal direction.</td>
  596. </tr>
  597. <tr>
  598. <td>groups.visibility</td>
  599. <td>Object</td>
  600. <td></td>
  601. <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
  602. this is not communicated across instances of graph2d. Take a look at <a href="../../examples/graph2d/14_toggleGroups.html">Example 14</a>
  603. for more explanation.
  604. </td>
  605. </tr>
  606. <tr class='toggle collapsible' onclick="toggleTable('g2dOptions','interpolation', this);">
  607. <td class="greenField"><span parent="interpolation" class="right-caret"></span> interpolation</td>
  608. <td>Boolean or Object</td>
  609. <td>true</td>
  610. <td>Toggle the interpolation with the default settings. For more customization use the JSON format.</td>
  611. </tr>
  612. <tr parent="interpolation" class="hidden">
  613. <td class="greenField indent">interpolation.enabled</td>
  614. <td>Boolean</td>
  615. <td>true</td>
  616. <td>Toggle the interpolation.</td>
  617. </tr>
  618. <tr parent="interpolation" class="hidden">
  619. <td class="greenField indent">interpolation.parametrization</td>
  620. <td>String</td>
  621. <td>'centripetal'</td>
  622. <td>Define the type of parametrizaion for the catmullRom interpolation. <a href="../../examples/graph2d/07_scrollingAndSorting.html">Example 7</a> shows the different parametrizations. The options are 'centripetal' (best results), 'chordal' and 'uniform'. Uniform is the computationally cheapest variant.
  623. If interpolation is disabled, linear interpolation is used.</td>
  624. </tr>
  625. <tr class='toggle collapsible' onclick="toggleTable('g2dOptions','legend', this);">
  626. <td><span parent="legend" class="right-caret"></span> legend</td>
  627. <td>Boolean or Object</td>
  628. <td>false</td>
  629. <td>Toggle the legend with the default settings.</td>
  630. </tr>
  631. <tr parent="legend" class="hidden">
  632. <td class="indent">legend.enabled</td>
  633. <td>Boolean</td>
  634. <td>false</td>
  635. <td>Toggle the legend.</td>
  636. </tr>
  637. <tr parent="legend" class="hidden">
  638. <td class="indent">legend.icons</td>
  639. <td>Boolean</td>
  640. <td>true</td>
  641. <td>Show automatically generated icons on the legend.</td>
  642. </tr>
  643. <tr parent="legend" class="hidden">
  644. <td class="indent2">legend.left.visible</td>
  645. <td>Boolean</td>
  646. <td>true</td>
  647. <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>
  648. </tr>
  649. <tr parent="legend" class="hidden">
  650. <td class="indent2">legend.left.position</td>
  651. <td>String</td>
  652. <td>'top-left'</td>
  653. <td>Determine the position of the legend coupled to the left axis. Options are 'top-left', 'top-right', 'bottom-left' or 'bottom-right'.</td>
  654. </tr>
  655. <tr parent="legend" class="hidden">
  656. <td class="indent2">legend.right.visible</td>
  657. <td>Boolean</td>
  658. <td>true</td>
  659. <td>This toggles the visibility of the legend that is coupled with the right axis.</td>
  660. </tr>
  661. <tr parent="legend" class="hidden">
  662. <td class="indent2">legend.right.position</td>
  663. <td>String</td>
  664. <td>'top-right'</td>
  665. <td>Determine the position of the legend coupled to the right axis. Options are 'top-left', 'top-right', 'bottom-left' or 'bottom-right'.</td>
  666. </tr>
  667. <tr>
  668. <td>moment</td>
  669. <td>function</td>
  670. <td>vis.moment</td>
  671. <td>A constructor for creating a moment.js Date. Allows for applying a custom time zone. See section <a href="#Time_zone">Time zone</a> for more information.</td>
  672. </tr>
  673. <tr>
  674. <td class="greenField">sampling</td>
  675. <td>Boolean</td>
  676. <td>true</td>
  677. <td>If sampling is enabled, Graph2d will automatically determine the amount of points per pixel.
  678. If there are more than 1 point per pixel, not all points will be drawn. Disabling sampling will cause a decrease in performance.</td>
  679. </tr>
  680. <tr>
  681. <td class="greenField">sort</td>
  682. <td>Boolean</td>
  683. <td>true</td>
  684. <td>This determines if the items are sorted automatically.
  685. They are sorted by the x value. If sort is enabled, more optimizations are possible, increasing the performance.</td>
  686. </tr>
  687. <tr>
  688. <td>stack</td>
  689. <td>Boolean</td>
  690. <td>true</td>
  691. <td>If stack is enabled, the graphs will be stacked upon each-other when applicable. A group can opt-out of stacking through the "excludeFromStacking" option.</td>
  692. </tr>
  693. <tr class='toggle collapsible' onclick="toggleTable('g2dOptions','shaded', this);">
  694. <td class="greenField"><span parent="shaded" class="right-caret"></span> shaded</td>
  695. <td>Boolean or Object</td>
  696. <td>false</td>
  697. <td>Toggle a shaded area with the default settings.</td>
  698. </tr>
  699. <tr parent="shaded" class="hidden">
  700. <td class="greenField indent">shaded.enabled</td>
  701. <td>Boolean</td>
  702. <td>false</td>
  703. <td>This toggles the shading.</td>
  704. </tr>
  705. <tr parent="shaded" class="hidden">
  706. <td class="greenField indent">shaded.orientation</td>
  707. <td>String</td>
  708. <td>'bottom'</td>
  709. <td>This determines if the shaded area is at the bottom or at the top of the curve, or always towards the zero-axis of the graph.
  710. The options are 'zero', 'bottom', 'top', or the special case of 'group'. If group is chosen, the option groupId is required.
  711. See <a href="../../examples/graph2d/20_shading.html">Example 20</a> what these options look like.
  712. </td>
  713. </tr>
  714. <tr parent="shaded" class="hidden">
  715. <td class="greenField indent">shaded.groupId</td>
  716. <td>String</td>
  717. <td>undefined</td>
  718. <td>The id of the group which should be used as the other shading limit.
  719. </td>
  720. </tr>
  721. <tr parent="shaded" class="hidden">
  722. <td class="greenField indent">shaded.style</td>
  723. <td>String</td>
  724. <td>undefined</td>
  725. <td>Set the style for the shading. This is a css string and it will override the attributes set in the class.</td>
  726. </tr>
  727. <tr parent="shaded" class="hidden">
  728. <td class="greenField indent">style</td>
  729. <td>String</td>
  730. <td>'line'</td>
  731. <td>This allows the user to define if this should be a linegraph, barchart or pointcloud. The options are: 'line', 'bar', 'points'.</td>
  732. </tr>
  733. <tr>
  734. <td class="greenField">yAxisOrientation</td>
  735. <td>String</td>
  736. <td>'left'</td>
  737. <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
  738. with an axis, it will not be shown.</td>
  739. </tr>
  740. <tr>
  741. <td class="greenField">excludeFromLegend</td>
  742. <td>Boolean</td>
  743. <td>false</td>
  744. <td>Group option only. Excludes the group from being listed in the legend.</td>
  745. </tr>
  746. <tr>
  747. <td class="greenField">excludeFromStacking</td>
  748. <td>Boolean</td>
  749. <td>false</td>
  750. <td>Group option only. Excludes the group from being included in the stacking.</td>
  751. </tr>
  752. </table>
  753. <h3 id="timelineOptions">Timeline Options</h3>
  754. <p>
  755. Graph2d is built upon the framework of the timeline. These options from the timeline can be used with graph2D.
  756. All options are optional.
  757. </p>
  758. <table class="options" id="optionTable">
  759. <tr>
  760. <th>Name</th>
  761. <th>Type</th>
  762. <th>Default</th>
  763. <th>Description</th>
  764. </tr>
  765. <tr>
  766. <td>autoResize</td>
  767. <td>Boolean</td>
  768. <td>true</td>
  769. <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>
  770. </tr>
  771. <tr>
  772. <td>configure</td>
  773. <td>boolean or function</td>
  774. <td><code>false</code></td>
  775. <td>When true, a configurator is loaded where all configuration options of the Graph2d can be changed live.
  776. The displayed options can be filtered by providing a filter function. This function is invoked with two arguments: the current <code>option</code> and the <code>path</code> (an Array) of the option within the options object. The option will be displayed when the filter function returns true. For example to only display format options:
  777. <pre class="prettyprint lang-js">
  778. function (option, path) {
  779. return option === 'format' || path.indexOf('format') !== -1;
  780. }</pre>
  781. </td>
  782. </tr>
  783. <tr>
  784. <td>clickToUse</td>
  785. <td>Boolean</td>
  786. <td>false</td>
  787. <td>When a Graph2d is configured to be <code>clickToUse</code>, it will react to mouse and touch events only when active.
  788. 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>
  789. </tr>
  790. <tr>
  791. <td>end</td>
  792. <td>Date or Number or String</td>
  793. <td>none</td>
  794. <td>The initial end date for the axis of the timeline.
  795. If not provided, the latest date present in the items set is taken as
  796. end date.</td>
  797. </tr>
  798. <tr>
  799. <td>format</td>
  800. <td>Object</td>
  801. <td>none</td>
  802. <td>
  803. Apply custom date formatting of the labels on the time axis. The default value of <code>format</code> is:
  804. <pre class="prettyprint lang-js">{
  805. minorLabels: {
  806. millisecond:'SSS',
  807. second: 's',
  808. minute: 'HH:mm',
  809. hour: 'HH:mm',
  810. weekday: 'ddd D',
  811. day: 'D',
  812. month: 'MMM',
  813. year: 'YYYY'
  814. },
  815. majorLabels: {
  816. millisecond:'HH:mm:ss',
  817. second: 'D MMMM HH:mm',
  818. minute: 'ddd D MMMM',
  819. hour: 'ddd D MMMM',
  820. weekday: 'MMMM YYYY',
  821. day: 'MMMM YYYY',
  822. month: 'YYYY',
  823. year: ''
  824. }
  825. }</pre>
  826. For values which not provided in the customized <code>options.format</code>, the default values will be used.
  827. All available formatting syntax is described in the <a href="http://momentjs.com/docs/#/displaying/format/">docs of moment.js</a>.
  828. </td>
  829. </tr>
  830. <tr>
  831. <td>height</td>
  832. <td>Number or String</td>
  833. <td>none</td>
  834. <td>The height of the timeline in pixels or as a percentage.
  835. When height is undefined or null, the height of the timeline is automatically
  836. adjusted to fit the contents.
  837. It is possible to set a maximum height using option <code>maxHeight</code>
  838. to prevent the timeline from getting too high in case of automatically
  839. calculated height.
  840. </td>
  841. </tr>
  842. <tr>
  843. <td>hiddenDates</td>
  844. <td>Object</td>
  845. <td>none</td>
  846. <td>This option allows you to hide specific timespans from the time axis. The dates can be supplied as an object:
  847. <code>{start: '2014-03-21 00:00:00', end: '2014-03-28 00:00:00', [repeat:'daily']}</code> or as an Array of these objects. The repeat argument is optional.
  848. The possible values are (case-sensitive): <code>daily, weekly, monthly, yearly</code>. To hide a weekend, pick any Saturday as start and the following Monday as end
  849. and set repeat to weekly.
  850. </td>
  851. </tr>
  852. <tr>
  853. <td>locale</td>
  854. <td>String</td>
  855. <td>none</td>
  856. <td>Select a locale for the Graph2d. See section <a href="#Localization">Localization</a> for more information.</td>
  857. </tr>
  858. <tr>
  859. <td>locales</td>
  860. <td>Object</td>
  861. <td>none</td>
  862. <td>A map with i18n locales. See section <a href="#Localization">Localization</a> for more information.</td>
  863. </tr>
  864. <tr>
  865. <td>max</td>
  866. <td>Date or Number or String</td>
  867. <td>none</td>
  868. <td>Set a maximum Date for the visible range.
  869. It will not be possible to move beyond this maximum.
  870. </td>
  871. </tr>
  872. <tr>
  873. <td>maxHeight</td>
  874. <td>Number or String</td>
  875. <td>none</td>
  876. <td>Specifies the maximum height for the Timeline. Can be a number in pixels or a string like "300px".</td>
  877. </tr>
  878. <tr>
  879. <td>maxMinorChars</td>
  880. <td>number</td>
  881. <td>7</td>
  882. <td>
  883. Specifies the maximum number of characters that should fit in minor grid labels.
  884. If larger, less and wider grids will be drawn.
  885. </td>
  886. </tr>
  887. <tr>
  888. <td>min</td>
  889. <td>Date or Number or String</td>
  890. <td>none</td>
  891. <td>Set a minimum Date for the visible range.
  892. It will not be possible to move beyond this minimum.
  893. </td>
  894. </tr>
  895. <tr>
  896. <td>minHeight</td>
  897. <td>Number or String</td>
  898. <td>none</td>
  899. <td>Specifies the minimum height for the Timeline. Can be a number in pixels or a string like "300px".</td>
  900. </tr>
  901. <tr>
  902. <td>moveable</td>
  903. <td>boolean</td>
  904. <td><code>true</code></td>
  905. <td>
  906. Specifies whether the Timeline can be moved and zoomed by dragging the window.
  907. See also option <code>zoomable</code>.
  908. </td>
  909. </tr>
  910. <tr>
  911. <td>orientation</td>
  912. <td>String</td>
  913. <td>'bottom'</td>
  914. <td>Orientation of the timeline: 'top', 'bottom' (default), or 'both'. If orientation is 'bottom', the time axis is drawn at the bottom. When 'top', the axis is drawn on top. When 'both', two axes are drawn, both on top and at the bottom.</td>
  915. </tr>
  916. <tr>
  917. <td>showCurrentTime</td>
  918. <td>Boolean</td>
  919. <td>true</td>
  920. <td>Show a vertical bar at the current time.</td>
  921. </tr>
  922. <tr>
  923. <td>showCustomTime</td>
  924. <td>Boolean</td>
  925. <td>false</td>
  926. <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>
  927. </tr>
  928. <tr>
  929. <td>showMajorLabels</td>
  930. <td>Boolean</td>
  931. <td>true</td>
  932. <td>By default, the timeline shows both minor and major date labels on the
  933. time axis.
  934. For example the minor labels show minutes and the major labels show hours.
  935. When <code>showMajorLabels</code> is <code>false</code>, no major labels
  936. are shown.</td>
  937. </tr>
  938. <tr>
  939. <td>showMinorLabels</td>
  940. <td>Boolean</td>
  941. <td>true</td>
  942. <td>By default, the timeline shows both minor and major date labels on the
  943. time axis.
  944. For example the minor labels show minutes and the major labels show hours.
  945. When <code>showMinorLabels</code> is <code>false</code>, no minor labels
  946. are shown. When both <code>showMajorLabels</code> and
  947. <code>showMinorLabels</code> are false, no horizontal axis will be
  948. visible.</td>
  949. </tr>
  950. <tr>
  951. <td>start</td>
  952. <td>Date or Number or String</td>
  953. <td>none</td>
  954. <td>The initial start date for the axis of the timeline.
  955. If not provided, the earliest date present in the events is taken as start date.</td>
  956. </tr>
  957. <tr class='toggle collapsible' onclick="toggleTable('optionTable','timeAxis', this);">
  958. <td><span parent="timeAxis" class="right-caret"></span> timeAxis</td>
  959. <td>Object</td>
  960. <td><code>Object</code></td>
  961. <td>Specify a fixed scale and step size for the time axis.</td>
  962. </tr>
  963. <tr parent="timeAxis" class="hidden">
  964. <td class="indent">timeAxis.scale</td>
  965. <td>String</td>
  966. <td>none</td>
  967. <td>Set a fixed scale for the time axis of the Timeline. Choose from <code>'millisecond'</code>, <code>'second'</code>, <code>'minute'</code>, <code>'hour'</code>, <code>'weekday'</code>, <code>'day'</code>, <code>'month'</code>, <code>'year'</code>. Example usage:
  968. <pre class="prettyprint lang-js options">var options = {
  969. timeAxis: {scale: 'minute', step: 5}
  970. }</pre>
  971. </td>
  972. </tr>
  973. <tr parent="timeAxis" class="hidden">
  974. <td class="indent">timeAxis.step</td>
  975. <td>number</td>
  976. <td><code>1</code></td>
  977. <td>
  978. Set a fixed step size for the time axis. Only applicable when used together with <code>timeAxis.scale</code>.
  979. Choose for example 1, 2, 5, or 10.</td>
  980. </tr>
  981. <tr>
  982. <td>width</td>
  983. <td>String</td>
  984. <td>'100%'</td>
  985. <td>The width of the timeline in pixels or as a percentage.</td>
  986. </tr>
  987. <tr>
  988. <td>zoomable</td>
  989. <td>boolean</td>
  990. <td><code>true</code></td>
  991. <td>
  992. Specifies whether the Timeline can be zoomed by pinching or scrolling in the window.
  993. Only applicable when option <code>moveable</code> is set <code><code>true</code></code>.
  994. </td>
  995. </tr>
  996. <tr>
  997. <td>zoomKey</td>
  998. <td>String</td>
  999. <td><code>''</code></td>
  1000. <td>Specifies whether the Timeline is only zoomed when an additional key is down.
  1001. Available values are '' (does not apply), 'altKey', 'ctrlKey', or 'metaKey'.
  1002. Only applicable when option <code>moveable</code> is set <code><code>true</code></code>.
  1003. </td>
  1004. </tr>
  1005. <tr>
  1006. <td>zoomMax</td>
  1007. <td>Number</td>
  1008. <td>315360000000000</td>
  1009. <td>Set a maximum zoom interval for the visible range in milliseconds.
  1010. It will not be possible to zoom out further than this maximum.
  1011. Default value equals about 10000 years.
  1012. </td>
  1013. </tr>
  1014. <tr>
  1015. <td>zoomMin</td>
  1016. <td>Number</td>
  1017. <td>10</td>
  1018. <td>Set a minimum zoom interval for the visible range in milliseconds.
  1019. It will not be possible to zoom in further than this minimum.
  1020. </td>
  1021. </tr>
  1022. </table>
  1023. <h2 id="Methods">Methods</h2>
  1024. <p>
  1025. The Graph2d supports the following methods.
  1026. </p>
  1027. <table class="methods">
  1028. <tr>
  1029. <th>Method</th>
  1030. <th>Return Type</th>
  1031. <th>Description</th>
  1032. </tr>
  1033. <tr>
  1034. <td>destroy()</td>
  1035. <td>none</td>
  1036. <td>Destroy the Graph2d. The Graph2d is removed from memory. all DOM elements and event listeners are cleaned up.
  1037. </td>
  1038. </tr>
  1039. <tr>
  1040. <td>fit()</td>
  1041. <td>none</td>
  1042. <td>Adjust the visible window such that it fits all items.
  1043. </td>
  1044. </tr>
  1045. <tr>
  1046. <td>getCurrentTime()</td>
  1047. <td>Date</td>
  1048. <td>Get the current time. Only applicable when option <code>showCurrentTime</code> is true.
  1049. </td>
  1050. </tr>
  1051. <tr>
  1052. <td>getCustomTime()</td>
  1053. <td>Date</td>
  1054. <td>Retrieve the custom time. Only applicable when the option <code>showCustomTime</code> is true.
  1055. </td>
  1056. </tr>
  1057. <tr>
  1058. <td>getDataRange()</td>
  1059. <td>Object</td>
  1060. <td>Get the range of all the items as an object containing <code>min: Date</code> and <code>max: Date</code>.</td>
  1061. </tr>
  1062. <tr id="getEventProperties">
  1063. <td>getEventProperties(event)</td>
  1064. <td>Object</td>
  1065. <td>
  1066. Returns an Object with relevant properties from an event:
  1067. <ul>
  1068. <li><code>pageX</code> (Number): absolute horizontal position of the click event.</li>
  1069. <li><code>pageY</code> (Number): absolute vertical position of the click event.</li>
  1070. <li><code>x</code> (Number): relative horizontal position of the click event.</li>
  1071. <li><code>y</code> (Number): relative vertical position of the click event.</li>
  1072. <li><code>time</code> (Date): Date of the clicked event.</li>
  1073. <li><code>value</code> (Number[]): The data value of the click event. The array contains one value when there is one data axis visible, and two values when there are two visible data axes.</li>
  1074. <li><code>what</code> (String or null): name of the clicked thing: <code>background</code>, <code>axis</code>, <code>dat-axis</code>, <code>custom-time</code>, or <code>current-time</code>, <code>legend</code>.</li>
  1075. <li><code>event</code> (Object): the original click event.</li>
  1076. </ul>
  1077. </td>
  1078. </tr>
  1079. <tr>
  1080. <td>getLegend(groupId, iconWidth, iconHeight)</td>
  1081. <td>SVGelement, String, String</td>
  1082. <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).
  1083. </td>
  1084. </tr>
  1085. <tr>
  1086. <td>getWindow()</td>
  1087. <td>Object</td>
  1088. <td>Get the current visible window. Returns an object with properties <code>start: Date</code> and <code>end: Date</code>.</td>
  1089. </tr>
  1090. <tr>
  1091. <td>isGroupVisible(groupId)</td>
  1092. <td>Boolean</td>
  1093. <td>This checks if the visible option of the supplied group (by ID) is true or false.
  1094. </td>
  1095. </tr>
  1096. <tr>
  1097. <td>moveTo(time [, options])</td>
  1098. <td>none</td>
  1099. <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:
  1100. <ul>
  1101. <li><code>animate: boolean or 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>
  1102. </ul>
  1103. </td>
  1104. </tr>
  1105. <tr>
  1106. <td>on(event, callback)</td>
  1107. <td>none</td>
  1108. <td>Create an event listener. The callback function is invoked every time the event is triggered. Available 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>
  1109. </tr>
  1110. <tr>
  1111. <td>off(event, callback)</td>
  1112. <td>none</td>
  1113. <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>
  1114. </tr>
  1115. <tr>
  1116. <td>redraw()</td>
  1117. <td>none</td>
  1118. <td>Force a redraw of the Graph2d. Can be useful to manually redraw when option autoResize=false.
  1119. </td>
  1120. </tr>
  1121. <tr>
  1122. <td>setCurrentTime(time)</td>
  1123. <td>none</td>
  1124. <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.
  1125. <code>time</code> can be a Date object, numeric timestamp, or ISO date string.
  1126. Only applicable when option <code>showCurrentTime</code> is true.</td>
  1127. </tr>
  1128. <tr>
  1129. <td>setCustomTime(time)</td>
  1130. <td>none</td>
  1131. <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.
  1132. </td>
  1133. </tr>
  1134. <tr>
  1135. <td>setGroups(groups)</td>
  1136. <td>none</td>
  1137. <td>Set a data set with groups for the Graph2d.
  1138. <code>groups</code> can be an Array with Objects,
  1139. a DataSet, or a DataView. For each of the groups, the items of the
  1140. Graph2d are filtered on the property <code>group</code>, which
  1141. must correspond with the id of the group.
  1142. </td>
  1143. </tr>
  1144. <tr>
  1145. <td>setItems(items)</td>
  1146. <td>none</td>
  1147. <td>Set a data set with items for the Graph2d.
  1148. <code>items</code> can be an Array with Objects,
  1149. a DataSet, or a DataView.
  1150. </td>
  1151. </tr>
  1152. <tr>
  1153. <td>setOptions(options)</td>
  1154. <td>none</td>
  1155. <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.
  1156. </td>
  1157. </tr>
  1158. <tr>
  1159. <td>setWindow(start, end)</td>
  1160. <td>none</td>
  1161. <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>
  1162. </tr>
  1163. </table>
  1164. <h2 id="Events">Events</h2>
  1165. <p>
  1166. Graph2d fires events when changing the visible window by dragging, when
  1167. selecting items, and when dragging the custom time bar.
  1168. </p>
  1169. <p>
  1170. Here an example on how to listen for a <code>rangeChanged</code> event. A listener can be removed via the function <code>off</code>:
  1171. </p>
  1172. <pre class="prettyprint lang-js">
  1173. function onChange (properties) {
  1174. alert('changed!');
  1175. }
  1176. // add event listener
  1177. Graph2d.on('rangechanged', onChange);
  1178. // do stuff...
  1179. // remove event listener
  1180. Graph2d.off('rangechanged', onChange);
  1181. </pre>
  1182. <p>
  1183. The following events are available.
  1184. </p>
  1185. <table class="events">
  1186. <tr>
  1187. <th>Name</th>
  1188. <th>Properties</th>
  1189. <th>Description</th>
  1190. </tr>
  1191. <tr>
  1192. <td>currentTimeTick</td>
  1193. <td>Fired when the current time bar redraws. The rate depends on the zoom level.</td>
  1194. </tr>
  1195. <tr>
  1196. <td>click</td>
  1197. <td>
  1198. Passes a properties object as returned by the method <a href="#getEventProperties"><code>Graph2d.getEventProperties(event)</code></a>.
  1199. </td>
  1200. <td>Fired when clicked inside the Graph2d.
  1201. </td>
  1202. </tr>
  1203. <tr>
  1204. <td>contextmenu</td>
  1205. <td>
  1206. Passes a properties object as returned by the method <a href="#getEventProperties"><code>Graph2d.getEventProperties(event)</code></a>.
  1207. </td>
  1208. <td>Fired when right-clicked inside the Graph2d. Note that in order to prevent the context menu from showing up, default behavior of the event must be stopped:
  1209. <pre class="prettyprint lang-js options">graph2d.on('contextmenu', function (props) {
  1210. alert('Right click!');
  1211. props.event.preventDefault();
  1212. });
  1213. </pre>
  1214. </td>
  1215. </tr>
  1216. <tr>
  1217. <td>doubleClick</td>
  1218. <td>
  1219. Passes a properties object as returned by the method <a href="#getEventProperties"><code>Graph2d.getEventProperties(event)</code></a>.
  1220. </td>
  1221. <td>Fired when double clicked inside the Graph2d.
  1222. </td>
  1223. </tr>
  1224. <tr>
  1225. <td>changed</td>
  1226. <td>
  1227. Has no properties.
  1228. </td>
  1229. <td>Fired once after each graph redraw.
  1230. </td>
  1231. </tr>
  1232. <tr>
  1233. <td>rangechange</td>
  1234. <td>
  1235. <ul>
  1236. <li><code>start</code> (Number): timestamp of the current start of the window.</li>
  1237. <li><code>end</code> (Number): timestamp of the current end of the window.</li>
  1238. </ul>
  1239. </td>
  1240. <td>Fired repeatedly when the user is dragging the Graph2d window.
  1241. </td>
  1242. </tr>
  1243. <tr>
  1244. <td>rangechanged</td>
  1245. <td>
  1246. <ul>
  1247. <li><code>start</code> (Number): timestamp of the current start of the window.</li>
  1248. <li><code>end</code> (Number): timestamp of the current end of the window.</li>
  1249. </ul>
  1250. </td>
  1251. <td>Fired once after the user has dragged the Graph2d window.
  1252. </td>
  1253. </tr>
  1254. <tr>
  1255. <td>timechange</td>
  1256. <td>
  1257. <ul>
  1258. <li><code>time</code> (Date): the current time.</li>
  1259. </ul>
  1260. </td>
  1261. <td>Fired repeatedly when the user is dragging the custom time bar.
  1262. Only available when the custom time bar is enabled.
  1263. </td>
  1264. </tr>
  1265. <tr>
  1266. <td>timechanged</td>
  1267. <td>
  1268. <ul>
  1269. <li><code>time</code> (Date): the current time.</li>
  1270. </ul>
  1271. </td>
  1272. <td>Fired once after the user has dragged the custom time bar.
  1273. Only available when the custom time bar is enabled.
  1274. </td>
  1275. </tr>
  1276. </table>
  1277. <h2 id="Localization">Localization</h2>
  1278. <p>
  1279. 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.
  1280. </p>
  1281. <p>
  1282. To set a locale for the Graph2d, specify the option <code>locale</code>:
  1283. </p>
  1284. <pre class="prettyprint lang-js">var options = {
  1285. locale: 'nl'
  1286. };
  1287. </pre>
  1288. <h3>Create a new locale</h3>
  1289. To load a locale into the Graph2d not supported by default, one can add a new locale to the option <code>locales</code>:
  1290. <pre class="prettyprint lang-js">var options = {
  1291. locales: {
  1292. // create a new locale
  1293. mylocale: {
  1294. current: 'current',
  1295. time: 'time',
  1296. }
  1297. },
  1298. // use the new locale
  1299. locale: 'mylocale'
  1300. };
  1301. </pre>
  1302. <h3 id="available-locales">Available locales</h3>
  1303. Graph2d comes with support for the following locales:
  1304. <table>
  1305. <tr><td>Language</td><td>Code</td></tr>
  1306. <tr>
  1307. <td>English</td>
  1308. <td>
  1309. <code>en</code><br>
  1310. <code>en_EN</code><br>
  1311. <code>en_US</code>
  1312. </td>
  1313. </tr>
  1314. <tr>
  1315. <td>Dutch</td>
  1316. <td>
  1317. <code>nl</code><br>
  1318. <code>nl_NL</code><br>
  1319. <code>nl_BE</code>
  1320. </td>
  1321. </tr>
  1322. </table>
  1323. <h2 id="Time_zone">Time zone</h2>
  1324. <p>
  1325. By default, the Timeline displays time in local time. To display a Timeline in an other time zone or in UTC, the date constructor can be overloaded via the configuration option <code>moment</code>, which by default is the constructor function of moment.js. More information about UTC with moment.js can be found in the docs: <a href="http://momentjs.com/docs/#/parsing/utc/">http://momentjs.com/docs/#/parsing/utc/</a>.
  1326. </p>
  1327. <p>
  1328. Examples:
  1329. </p>
  1330. <pre class="prettyprint lang-js">// display in UTC
  1331. var options = {
  1332. moment: function(date) {
  1333. return vis.moment(date).utc();
  1334. }
  1335. };
  1336. // display in UTC +08:00
  1337. var options = {
  1338. moment: function(date) {
  1339. return vis.moment(date).utcOffset('+08:00');
  1340. }
  1341. };
  1342. </pre>
  1343. <h2 id="Styles">Styles</h2>
  1344. <p>
  1345. All parts of the Graph2d have a class name and a default css style just like the Graph2d.
  1346. The styles can be overwritten, which enables full customization of the layout
  1347. of the Graph2d.
  1348. </p>
  1349. <p>
  1350. Additionally, Graph2d has 10 preset styles for graphs, which are cycled through when loading groups. These styles can be overwritten
  1351. as well, along with defining your own classes to style the graphs! <a href="../../examples/graph2d/04_rightAxis.html">Example 4</a> and
  1352. <a href="../../examples/graph2d/05_bothAxis.html">example 5</a> show the usage of custom styles.
  1353. </p>
  1354. </div>
  1355. <!-- Bootstrap core JavaScript
  1356. ================================================== -->
  1357. <!-- Placed at the end of the document so the pages load faster -->
  1358. <script src="../js/jquery.min.js"></script>
  1359. <script src="../js/bootstrap.min.js"></script>
  1360. <!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
  1361. <script src="../js/ie10-viewport-bug-workaround.js"></script>
  1362. <!-- jquery extensions -->
  1363. <script src="../js/jquery.highlight.js"></script>
  1364. <script src="../js/jquery.url.min.js"></script>
  1365. <!-- Tipue vendor js -->
  1366. <script src="../js/tipuesearch.config.js"></script>
  1367. <script src="../js/tipuesearch.js"></script>
  1368. <!-- controller -->
  1369. <script src="../js/main.js"></script>