index.html 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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: Interacting with axes</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 type="text/javascript">
  11. $(function() {
  12. function generate(start, end, fn) {
  13. var res = [];
  14. for (var i = 0; i <= 100; ++i) {
  15. var x = start + i / 100 * (end - start);
  16. res.push([x, fn(x)]);
  17. }
  18. return res;
  19. }
  20. var data = [
  21. { data: generate(0, 10, function (x) { return Math.sqrt(x);}), xaxis: 1, yaxis:1 },
  22. { data: generate(0, 10, function (x) { return Math.sin(x);}), xaxis: 1, yaxis:2 },
  23. { data: generate(0, 10, function (x) { return Math.cos(x);}), xaxis: 1, yaxis:3 },
  24. { data: generate(2, 10, function (x) { return Math.tan(x);}), xaxis: 2, yaxis: 4 }
  25. ];
  26. var plot = $.plot("#placeholder", data, {
  27. xaxes: [
  28. { position: 'bottom' },
  29. { position: 'top'}
  30. ],
  31. yaxes: [
  32. { position: 'left' },
  33. { position: 'left' },
  34. { position: 'right' },
  35. { position: 'left' }
  36. ]
  37. });
  38. // Create a div for each axis
  39. $.each(plot.getAxes(), function (i, axis) {
  40. if (!axis.show)
  41. return;
  42. var box = axis.box;
  43. $("<div class='axisTarget' style='position:absolute; left:" + box.left + "px; top:" + box.top + "px; width:" + box.width + "px; height:" + box.height + "px'></div>")
  44. .data("axis.direction", axis.direction)
  45. .data("axis.n", axis.n)
  46. .css({ backgroundColor: "#f00", opacity: 0, cursor: "pointer" })
  47. .appendTo(plot.getPlaceholder())
  48. .hover(
  49. function () { $(this).css({ opacity: 0.10 }) },
  50. function () { $(this).css({ opacity: 0 }) }
  51. )
  52. .click(function () {
  53. $("#click").text("You clicked the " + axis.direction + axis.n + "axis!")
  54. });
  55. });
  56. // Add the Flot version string to the footer
  57. $("#footer").prepend("Flot " + $.plot.version + " &ndash; ");
  58. });
  59. </script>
  60. </head>
  61. <body>
  62. <div id="header">
  63. <h2>Interacting with axes</h2>
  64. </div>
  65. <div id="content">
  66. <div class="demo-container">
  67. <div id="placeholder" class="demo-placeholder"></div>
  68. </div>
  69. <p>With multiple axes, you sometimes need to interact with them. A simple way to do this is to draw the plot, deduce the axis placements and insert a couple of divs on top to catch events.</p>
  70. <p>Try clicking an axis.</p>
  71. <p id="click"></p>
  72. </div>
  73. <div id="footer">
  74. Copyright &copy; 2007 - 2014 IOLA and Ole Laursen
  75. </div>
  76. </body>
  77. </html>