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.

73 lines
2.7 KiB

  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <title>Graph2d | Bar Graphs Side by Side 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. <script>(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)})(window,document,'script','//www.google-analytics.com/analytics.js','ga');ga('create', 'UA-61231638-1', 'auto');ga('send', 'pageview');</script></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. You can use the
  17. barChart.handleOverlap option to automatically plot the bars next to eachother or stacked on top of eachother if they occupy the same timeslot. By default, this option is on, the bars overlap.
  18. Use the dropdown box to experiment with the options. The stacked only really makes sense when using groups as is shown in the <a href="./11_barsSideBySideGroups.html">next example</a>.
  19. <br /><br />
  20. Handle overlap: <select id="dropdownID">
  21. <option value="overlap">overlap</option>
  22. <option value="sideBySide">sideBySide</option>
  23. <option value="stack">stack</option>
  24. </select><br/>
  25. </div>
  26. <br />
  27. <div id="visualization"></div>
  28. <script type="text/javascript">
  29. var container = document.getElementById('visualization');
  30. var items = [
  31. {x: '2014-06-11', y: 10},
  32. {x: '2014-06-12', y: 25},
  33. {x: '2014-06-13', y: 30},
  34. {x: '2014-06-14', y: 10},
  35. {x: '2014-06-15', y: 15},
  36. {x: '2014-06-16', y: 30},
  37. {x: '2014-06-11', y: -12},
  38. {x: '2014-06-14', y: 24},
  39. {x: '2014-06-15', y: 5},
  40. {x: '2014-06-16', y: 12}
  41. ];
  42. var dataset = new vis.DataSet(items);
  43. var options = {
  44. style:'bar',
  45. barChart: {width:50, align:'center'}, // align: left, center, right
  46. drawPoints: false,
  47. dataAxis: {
  48. icons:true
  49. },
  50. orientation:'top',
  51. start: '2014-06-10',
  52. end: '2014-06-18'
  53. };
  54. var graph2d = new vis.Graph2d(container, items, options);
  55. var dropdown = document.getElementById("dropdownID");
  56. dropdown.onchange = update;
  57. function update() {
  58. var options = {barChart:{handleOverlap:dropdown.value}};
  59. graph2d.setOptions(options);
  60. }
  61. </script>
  62. </body>
  63. </html>