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.

69 lines
2.1 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. If you're not using groups, you can use the
  17. barChart.allowOverlap option to automatically plot the bars next to eachother if they occupy the same timeslot. By default, this option is on, making the bars overlap. If the option is disabled, the overlapping
  18. bars are plotted side by side. Use the toggle below to switch between settings.
  19. <br /><br />
  20. Allow overlap: <input type="checkbox" id="allowOverlap" checked="checked">
  21. </div>
  22. <br />
  23. <div id="visualization"></div>
  24. <script type="text/javascript">
  25. var container = document.getElementById('visualization');
  26. var checkbox = document.getElementById('allowOverlap');
  27. var items = [
  28. {x: '2014-06-11', y: 10},
  29. {x: '2014-06-12', y: 25},
  30. {x: '2014-06-13', y: 30},
  31. {x: '2014-06-14', y: 10},
  32. {x: '2014-06-15', y: 15},
  33. {x: '2014-06-16', y: 30},
  34. {x: '2014-06-11', y: 12},
  35. {x: '2014-06-14', y: 24},
  36. {x: '2014-06-15', y: 5},
  37. {x: '2014-06-16', y: 12}
  38. ];
  39. var dataset = new vis.DataSet(items);
  40. var options = {
  41. style:'bar',
  42. barChart: {width:50, align:'center'}, // align: left, center, right
  43. drawPoints: false,
  44. dataAxis: {
  45. icons:true
  46. },
  47. orientation:'top',
  48. start: '2014-06-10',
  49. end: '2014-06-18'
  50. };
  51. var graph2d = new vis.Graph2d(container, items, options);
  52. checkbox.onchange = toggleOption;
  53. function toggleOption() {
  54. var options = {barChart:{allowOverlap:checkbox.checked}};
  55. graph2d.setOptions(options);
  56. }
  57. </script>
  58. </body>
  59. </html>