index.html 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  5. <title>Flot Examples: Stacking</title>
  6. <link href="../examples.css" rel="stylesheet" type="text/css">
  7. <!--[if lte IE 8]><script language="javascript" type="text/javascript" src="../../excanvas.min.js"></script><![endif]-->
  8. <script language="javascript" type="text/javascript" src="../../jquery.js"></script>
  9. <script language="javascript" type="text/javascript" src="../../jquery.flot.js"></script>
  10. <script language="javascript" type="text/javascript" src="../../jquery.flot.stack.js"></script>
  11. <script type="text/javascript">
  12. $(function() {
  13. var d1 = [];
  14. for (var i = 0; i <= 10; i += 1) {
  15. d1.push([i, parseInt(Math.random() * 30)]);
  16. }
  17. var d2 = [];
  18. for (var i = 0; i <= 10; i += 1) {
  19. d2.push([i, parseInt(Math.random() * 30)]);
  20. }
  21. var d3 = [];
  22. for (var i = 0; i <= 10; i += 1) {
  23. d3.push([i, parseInt(Math.random() * 30)]);
  24. }
  25. var stack = 0,
  26. bars = true,
  27. lines = false,
  28. steps = false;
  29. function plotWithOptions() {
  30. $.plot("#placeholder", [ d1, d2, d3 ], {
  31. series: {
  32. stack: stack,
  33. lines: {
  34. show: lines,
  35. fill: true,
  36. steps: steps
  37. },
  38. bars: {
  39. show: bars,
  40. barWidth: 0.6
  41. }
  42. }
  43. });
  44. }
  45. plotWithOptions();
  46. $(".stackControls button").click(function (e) {
  47. e.preventDefault();
  48. stack = $(this).text() == "With stacking" ? true : null;
  49. plotWithOptions();
  50. });
  51. $(".graphControls button").click(function (e) {
  52. e.preventDefault();
  53. bars = $(this).text().indexOf("Bars") != -1;
  54. lines = $(this).text().indexOf("Lines") != -1;
  55. steps = $(this).text().indexOf("steps") != -1;
  56. plotWithOptions();
  57. });
  58. // Add the Flot version string to the footer
  59. $("#footer").prepend("Flot " + $.plot.version + " &ndash; ");
  60. });
  61. </script>
  62. </head>
  63. <body>
  64. <div id="header">
  65. <h2>Stacking</h2>
  66. </div>
  67. <div id="content">
  68. <div class="demo-container">
  69. <div id="placeholder" class="demo-placeholder"></div>
  70. </div>
  71. <p>With the stack plugin, you can have Flot stack the series. This is useful if you wish to display both a total and the constituents it is made of. The only requirement is that you provide the input sorted on x.</p>
  72. <p class="stackControls">
  73. <button>With stacking</button>
  74. <button>Without stacking</button>
  75. </p>
  76. <p class="graphControls">
  77. <button>Bars</button>
  78. <button>Lines</button>
  79. <button>Lines with steps</button>
  80. </p>
  81. </div>
  82. <div id="footer">
  83. Copyright &copy; 2007 - 2014 IOLA and Ole Laursen
  84. </div>
  85. </body>
  86. </html>