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.

81 lines
2.6 KiB

  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <title>Graph2d | Bar Graph Example</title>
  5. <style type="text/css">
  6. body, html {
  7. font-family: sans-serif;
  8. }
  9. </style>
  10. <script src="../../dist/vis.js"></script>
  11. <link href="../../dist/vis.css" rel="stylesheet" type="text/css" />
  12. </head>
  13. <body>
  14. <h2>Graph2d | Bar Graphs Side by Side Example</h2>
  15. <div style="width:700px; font-size:14px; text-align: justify;">
  16. When using Bar graphs, it can often be the case that there are multiple bars on the same timepoint. This may not always be the desired result. Since groups are plotted one at a time, the allowOverlap option does
  17. not work here. For groups you can use the "slots" option.
  18. <pre class="prettyprint lang-js">
  19. var options = {
  20. slots: {
  21. slot: 1,
  22. total:3
  23. }
  24. };
  25. </pre>
  26. <br /><br />
  27. The slots tell the group where to plot it's bar. Each group is given a slot and the total amount of slots. Using this, the bars are plotted side by side neatly.
  28. </div>
  29. <br />
  30. <div id="visualization"></div>
  31. <script type="text/javascript">
  32. var container = document.getElementById('visualization');
  33. var groups = new vis.DataSet();
  34. groups.add({id: 0, content: "group0", options: {slots:{slot:1,total:3}}})
  35. groups.add({id: 1, content: "group1", options: {slots:{slot:2,total:3}}})
  36. groups.add({id: 2, content: "group2", options: {slots:{slot:3,total:3}}})
  37. var items = [
  38. {x: '2014-06-11', y: 10, group:0},
  39. {x: '2014-06-12', y: 25, group:0},
  40. {x: '2014-06-13', y: 30, group:0},
  41. {x: '2014-06-14', y: 10, group:0},
  42. {x: '2014-06-15', y: 15, group:0},
  43. {x: '2014-06-16', y: 30, group:0},
  44. {x: '2014-06-11', y: 12, group:1},
  45. {x: '2014-06-12', y: 15, group:1},
  46. {x: '2014-06-13', y: 34, group:1},
  47. {x: '2014-06-14', y: 24, group:1},
  48. {x: '2014-06-15', y: 5, group:1},
  49. {x: '2014-06-16', y: 12, group:1},
  50. {x: '2014-06-11', y: 22, group:2},
  51. {x: '2014-06-12', y: 14, group:2},
  52. {x: '2014-06-13', y: 24, group:2},
  53. {x: '2014-06-14', y: 21, group:2},
  54. {x: '2014-06-15', y: 30, group:2},
  55. {x: '2014-06-16', y: 18, group:2}
  56. ];
  57. var dataset = new vis.DataSet(items);
  58. var options = {
  59. style:'bar',
  60. barChart: {width:50, align:'center'}, // align: left, center, right
  61. drawPoints: true,
  62. dataAxis: {
  63. icons:true
  64. },
  65. orientation:'top',
  66. start: '2014-06-10',
  67. end: '2014-06-18'
  68. };
  69. var graph2d = new vis.Graph2d(container, items, options,groups);
  70. </script>
  71. </body>
  72. </html>