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.

93 lines
2.9 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 | Custom axis range</h2>
  15. <div style="width:700px; font-size:14px; text-align: justify;">
  16. You can define a custom range for the Y axis. Since there are two Y axis, you can define both of them. You can also
  17. only define the min or max values. Since one of the Y axis is slaved to the other one (the right one is slaved to the left one),
  18. you cannot absolutely define the range of the slaved axis because it has to use the same lines. The values you supply are used as guidelines however.
  19. <pre class="prettyprint lang-js">
  20. var options = {
  21. dataAxis: {
  22. customRange: {
  23. left: {
  24. min:-5, max:30
  25. },
  26. right: {
  27. min:-5
  28. }
  29. },
  30. }
  31. };
  32. </pre>
  33. </div>
  34. <br />
  35. <div id="visualization"></div>
  36. <script type="text/javascript">
  37. var container = document.getElementById('visualization');
  38. var groups = new vis.DataSet();
  39. groups.add({id: 0, content: "group0", options: {slots:{slot:1,total:3}}})
  40. groups.add({id: 1, content: "group1", options: {slots:{slot:2,total:3}}})
  41. groups.add({id: 2, content: "group2", options: {slots:{slot:3,total:3}, yAxisOrientation:'right'}})
  42. var items = [
  43. {x: '2014-06-11', y: 10, group:0},
  44. {x: '2014-06-12', y: 25, group:0},
  45. {x: '2014-06-13', y: 30, group:0},
  46. {x: '2014-06-14', y: 10, group:0},
  47. {x: '2014-06-15', y: 15, group:0},
  48. {x: '2014-06-16', y: 30, group:0},
  49. {x: '2014-06-11', y: 12, group:1},
  50. {x: '2014-06-12', y: 15, group:1},
  51. {x: '2014-06-13', y: 34, group:1},
  52. {x: '2014-06-14', y: 24, group:1},
  53. {x: '2014-06-15', y: 5, group:1},
  54. {x: '2014-06-16', y: 12, group:1},
  55. {x: '2014-06-11', y: 22, group:2},
  56. {x: '2014-06-12', y: 14, group:2},
  57. {x: '2014-06-13', y: 24, group:2},
  58. {x: '2014-06-14', y: 21, group:2},
  59. {x: '2014-06-15', y: 30, group:2},
  60. {x: '2014-06-16', y: 18, group:2}
  61. ];
  62. var dataset = new vis.DataSet(items);
  63. var options = {
  64. style:'bar',
  65. barChart: {width:50, align:'center'}, // align: left, center, right
  66. drawPoints: true,
  67. dataAxis: {
  68. customRange: {
  69. left: {
  70. min:-5, max:30
  71. },
  72. right: {
  73. min:-5
  74. }
  75. },
  76. icons:true
  77. },
  78. orientation:'top',
  79. start: '2014-06-10',
  80. end: '2014-06-18'
  81. };
  82. var graph2d = new vis.Graph2d(container, items, options,groups);
  83. </script>
  84. </body>
  85. </html>