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.

1455 lines
58 KiB

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