index.html 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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: Visitors</title>
  6. <link href="../examples.css" rel="stylesheet" type="text/css">
  7. <script language="javascript" type="text/javascript" src="../../source/jquery.js"></script>
  8. <script language="javascript" type="text/javascript" src="../../lib/globalize.js"></script>
  9. <script language="javascript" type="text/javascript" src="../../source/jquery.canvaswrapper.js"></script>
  10. <script language="javascript" type="text/javascript" src="../../source/jquery.colorhelpers.js"></script>
  11. <script language="javascript" type="text/javascript" src="../../source/jquery.flot.js"></script>
  12. <script language="javascript" type="text/javascript" src="../../source/jquery.flot.saturated.js"></script>
  13. <script language="javascript" type="text/javascript" src="../../source/jquery.flot.browser.js"></script>
  14. <script language="javascript" type="text/javascript" src="../../source/jquery.flot.drawSeries.js"></script>
  15. <script language="javascript" type="text/javascript" src="../../source/jquery.flot.errorbars.js"></script>
  16. <script language="javascript" type="text/javascript" src="../../source/jquery.flot.uiConstants.js"></script>
  17. <script language="javascript" type="text/javascript" src="../../source/jquery.flot.logaxis.js"></script>
  18. <script language="javascript" type="text/javascript" src="../../source/jquery.flot.symbol.js"></script>
  19. <script language="javascript" type="text/javascript" src="../../source/jquery.flot.flatdata.js"></script>
  20. <script language="javascript" type="text/javascript" src="../../source/jquery.flot.navigate.js"></script>
  21. <script language="javascript" type="text/javascript" src="../../source/jquery.flot.fillbetween.js"></script>
  22. <script language="javascript" type="text/javascript" src="../../source/jquery.flot.stack.js"></script>
  23. <script language="javascript" type="text/javascript" src="../../source/jquery.flot.touchNavigate.js"></script>
  24. <script language="javascript" type="text/javascript" src="../../source/jquery.flot.hover.js"></script>
  25. <script language="javascript" type="text/javascript" src="../../source/jquery.flot.touch.js"></script>
  26. <script language="javascript" type="text/javascript" src="../../source/jquery.flot.time.js"></script>
  27. <script language="javascript" type="text/javascript" src="../../source/jquery.flot.axislabels.js"></script>
  28. <script language="javascript" type="text/javascript" src="../../source/jquery.flot.selection.js"></script>
  29. <script language="javascript" type="text/javascript" src="../../source/jquery.flot.composeImages.js"></script>
  30. <script language="javascript" type="text/javascript" src="../../source/jquery.flot.legend.js"></script>
  31. <script type="text/javascript">
  32. $(function() {
  33. var d = [[1196463600000, 0], [1196550000000, 0], [1196636400000, 0], [1196722800000, 77], [1196809200000, 3636], [1196895600000, 3575], [1196982000000, 2736], [1197068400000, 1086], [1197154800000, 676], [1197241200000, 1205], [1197327600000, 906], [1197414000000, 710], [1197500400000, 639], [1197586800000, 540], [1197673200000, 435], [1197759600000, 301], [1197846000000, 575], [1197932400000, 481], [1198018800000, 591], [1198105200000, 608], [1198191600000, 459], [1198278000000, 234], [1198364400000, 1352], [1198450800000, 686], [1198537200000, 279], [1198623600000, 449], [1198710000000, 468], [1198796400000, 392], [1198882800000, 282], [1198969200000, 208], [1199055600000, 229], [1199142000000, 177], [1199228400000, 374], [1199314800000, 436], [1199401200000, 404], [1199487600000, 253], [1199574000000, 218], [1199660400000, 476], [1199746800000, 462], [1199833200000, 448], [1199919600000, 442], [1200006000000, 403], [1200092400000, 204], [1200178800000, 194], [1200265200000, 327], [1200351600000, 374], [1200438000000, 507], [1200524400000, 546], [1200610800000, 482], [1200697200000, 283], [1200783600000, 221], [1200870000000, 483], [1200956400000, 523], [1201042800000, 528], [1201129200000, 483], [1201215600000, 452], [1201302000000, 270], [1201388400000, 222], [1201474800000, 439], [1201561200000, 559], [1201647600000, 521], [1201734000000, 477], [1201820400000, 442], [1201906800000, 252], [1201993200000, 236], [1202079600000, 525], [1202166000000, 477], [1202252400000, 386], [1202338800000, 409], [1202425200000, 408], [1202511600000, 237], [1202598000000, 193], [1202684400000, 357], [1202770800000, 414], [1202857200000, 393], [1202943600000, 353], [1203030000000, 364], [1203116400000, 215], [1203202800000, 214], [1203289200000, 356], [1203375600000, 399], [1203462000000, 334], [1203548400000, 348], [1203634800000, 243], [1203721200000, 126], [1203807600000, 157], [1203894000000, 288]];
  34. // first correct the timestamps - they are recorded as the daily
  35. // midnights in UTC+0100, but Flot always displays dates in UTC
  36. // so we have to add one hour to hit the midnights in the plot
  37. for (var i = 0; i < d.length; ++i) {
  38. d[i][0] += 60 * 60 * 1000;
  39. }
  40. // helper for returning the weekends in a period
  41. function weekendAreas(axes) {
  42. var markings = [],
  43. d = new Date(axes.xaxis.min);
  44. // go to the first Saturday
  45. d.setUTCDate(d.getUTCDate() - ((d.getUTCDay() + 1) % 7))
  46. d.setUTCSeconds(0);
  47. d.setUTCMinutes(0);
  48. d.setUTCHours(0);
  49. var i = d.getTime();
  50. // when we don't set yaxis, the rectangle automatically
  51. // extends to infinity upwards and downwards
  52. do {
  53. markings.push({ xaxis: { from: i, to: i + 2 * 24 * 60 * 60 * 1000 } });
  54. i += 7 * 24 * 60 * 60 * 1000;
  55. } while (i < axes.xaxis.max);
  56. return markings;
  57. }
  58. var options = {
  59. xaxis: {
  60. mode: "time",
  61. timeBase: "milliseconds",
  62. tickLength: 5,
  63. gridLines: false
  64. },
  65. selection: {
  66. mode: "x"
  67. },
  68. grid: {
  69. markings: weekendAreas
  70. }
  71. };
  72. var plot = $.plot("#placeholder", [d], options);
  73. var overview = $.plot("#overview", [d], {
  74. series: {
  75. lines: {
  76. show: true,
  77. lineWidth: 1
  78. },
  79. shadowSize: 0
  80. },
  81. xaxis: {
  82. ticks: [],
  83. mode: "time"
  84. },
  85. yaxis: {
  86. ticks: [],
  87. min: 0,
  88. autoScaleMargin: 0.1
  89. },
  90. selection: {
  91. mode: "x"
  92. }
  93. });
  94. // now connect the two
  95. $("#placeholder").bind("plotselected", function (event, ranges) {
  96. // do the zooming
  97. $.each(plot.getXAxes(), function(_, axis) {
  98. var opts = axis.options;
  99. opts.min = ranges.xaxis.from;
  100. opts.max = ranges.xaxis.to;
  101. });
  102. plot.setupGrid();
  103. plot.draw();
  104. plot.clearSelection();
  105. // don't fire event on the overview to prevent eternal loop
  106. overview.setSelection(ranges, true);
  107. });
  108. $("#overview").bind("plotselected", function (event, ranges) {
  109. plot.setSelection(ranges);
  110. });
  111. // Add the Flot version string to the footer
  112. $("#footer").prepend("Flot " + $.plot.version + " &ndash; ");
  113. });
  114. </script>
  115. </head>
  116. <body>
  117. <div id="header">
  118. <h2>Visitors</h2>
  119. </div>
  120. <div id="content">
  121. <div class="demo-container">
  122. <div id="placeholder" class="demo-placeholder"></div>
  123. </div>
  124. <div class="demo-container" style="height:150px;">
  125. <div id="overview" class="demo-placeholder"></div>
  126. </div>
  127. <p>This plot shows visitors per day to the Flot homepage, with weekends colored.</p>
  128. <p>The smaller plot is linked to the main plot, so it acts as an overview. Try dragging a selection on either plot, and watch the behavior of the other.</p>
  129. </div>
  130. <div id="footer">
  131. Copyright &copy; 2007 - 2014 IOLA and Ole Laursen
  132. </div>
  133. </body>
  134. </html>