PHP/JavaScript webapp to analyse spending habits
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.

zooming.html 3.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  5. <title>Flot Examples</title>
  6. <link href="layout.css" rel="stylesheet" type="text/css"></link>
  7. <!--[if IE]><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.selection.js"></script>
  11. </head>
  12. <body>
  13. <h1>Flot Examples</h1>
  14. <div style="float:left">
  15. <div id="placeholder" style="width:500px;height:300px"></div>
  16. </div>
  17. <div id="miniature" style="float:left;margin-left:20px;margin-top:50px">
  18. <div id="overview" style="width:166px;height:100px"></div>
  19. <p id="overviewLegend" style="margin-left:10px"></p>
  20. </div>
  21. <p style="clear:left"> The selection support makes
  22. pretty advanced zooming schemes possible. With a few lines of code,
  23. the small overview plot to the right has been connected to the large
  24. plot. Try selecting a rectangle on either of them.</p>
  25. <script id="source">
  26. $(function () {
  27. // setup plot
  28. function getData(x1, x2) {
  29. var d = [];
  30. for (var i = 0; i <= 100; ++i) {
  31. var x = x1 + i * (x2 - x1) / 100;
  32. d.push([x, Math.sin(x * Math.sin(x))]);
  33. }
  34. return [
  35. { label: "sin(x sin(x))", data: d }
  36. ];
  37. }
  38. var options = {
  39. legend: { show: false },
  40. series: {
  41. lines: { show: true },
  42. points: { show: true }
  43. },
  44. yaxis: { ticks: 10 },
  45. selection: { mode: "xy" }
  46. };
  47. var startData = getData(0, 3 * Math.PI);
  48. var plot = $.plot($("#placeholder"), startData, options);
  49. // setup overview
  50. var overview = $.plot($("#overview"), startData, {
  51. legend: { show: true, container: $("#overviewLegend") },
  52. series: {
  53. lines: { show: true, lineWidth: 1 },
  54. shadowSize: 0
  55. },
  56. xaxis: { ticks: 4 },
  57. yaxis: { ticks: 3, min: -2, max: 2 },
  58. grid: { color: "#999" },
  59. selection: { mode: "xy" }
  60. });
  61. // now connect the two
  62. $("#placeholder").bind("plotselected", function (event, ranges) {
  63. // clamp the zooming to prevent eternal zoom
  64. if (ranges.xaxis.to - ranges.xaxis.from < 0.00001)
  65. ranges.xaxis.to = ranges.xaxis.from + 0.00001;
  66. if (ranges.yaxis.to - ranges.yaxis.from < 0.00001)
  67. ranges.yaxis.to = ranges.yaxis.from + 0.00001;
  68. // do the zooming
  69. plot = $.plot($("#placeholder"), getData(ranges.xaxis.from, ranges.xaxis.to),
  70. $.extend(true, {}, options, {
  71. xaxis: { min: ranges.xaxis.from, max: ranges.xaxis.to },
  72. yaxis: { min: ranges.yaxis.from, max: ranges.yaxis.to }
  73. }));
  74. // don't fire event on the overview to prevent eternal loop
  75. overview.setSelection(ranges, true);
  76. });
  77. $("#overview").bind("plotselected", function (event, ranges) {
  78. plot.setSelection(ranges);
  79. });
  80. });
  81. </script>
  82. </body>
  83. </html>