index.html 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. <script language="javascript" type="text/javascript" src="../../source/jquery.js"></script>
  8. <script language="javascript" type="text/javascript" src="../../source/jquery.canvaswrapper.js"></script>
  9. <script language="javascript" type="text/javascript" src="../../source/jquery.colorhelpers.js"></script>
  10. <script language="javascript" type="text/javascript" src="../../source/jquery.flot.js"></script>
  11. <script language="javascript" type="text/javascript" src="../../source/jquery.flot.saturated.js"></script>
  12. <script language="javascript" type="text/javascript" src="../../source/jquery.flot.browser.js"></script>
  13. <script language="javascript" type="text/javascript" src="../../source/jquery.flot.drawSeries.js"></script>
  14. <script language="javascript" type="text/javascript" src="../../source/jquery.flot.errorbars.js"></script>
  15. <script language="javascript" type="text/javascript" src="../../source/jquery.flot.uiConstants.js"></script>
  16. <script language="javascript" type="text/javascript" src="../../source/jquery.flot.logaxis.js"></script>
  17. <script language="javascript" type="text/javascript" src="../../source/jquery.flot.symbol.js"></script>
  18. <script language="javascript" type="text/javascript" src="../../source/jquery.flot.flatdata.js"></script>
  19. <script language="javascript" type="text/javascript" src="../../source/jquery.flot.navigate.js"></script>
  20. <script language="javascript" type="text/javascript" src="../../source/jquery.flot.fillbetween.js"></script>
  21. <script language="javascript" type="text/javascript" src="../../source/jquery.flot.stack.js"></script>
  22. <script language="javascript" type="text/javascript" src="../../source/jquery.flot.touchNavigate.js"></script>
  23. <script language="javascript" type="text/javascript" src="../../source/jquery.flot.hover.js"></script>
  24. <script language="javascript" type="text/javascript" src="../../source/jquery.flot.touch.js"></script>
  25. <script language="javascript" type="text/javascript" src="../../source/jquery.flot.time.js"></script>
  26. <script language="javascript" type="text/javascript" src="../../source/jquery.flot.axislabels.js"></script>
  27. <script language="javascript" type="text/javascript" src="../../source/jquery.flot.selection.js"></script>
  28. <script language="javascript" type="text/javascript" src="../../source/jquery.flot.composeImages.js"></script>
  29. <script language="javascript" type="text/javascript" src="../../source/jquery.flot.legend.js"></script>
  30. <script type="text/javascript">
  31. $(function() {
  32. function generate(start, end, fn) {
  33. var res = [];
  34. for (var i = 0; i <= 40; ++i) {
  35. var x = start + i / 40 * (end - start);
  36. res.push([x, fn(x)]);
  37. }
  38. return res;
  39. }
  40. var data = [
  41. { data: generate(0, 10, function (x) { return Math.sqrt(x);}), xaxis: 1, yaxis:1, lines: { show: true, fill: true }},
  42. { data: generate(0, 10, function (x) { return Math.sin(x);}), xaxis: 1, yaxis:2, points: { show: true }},
  43. { data: generate(0, 10, function (x) { return (x < 3 || x > 5) ? Math.cos(x) : null;}), xaxis: 1, yaxis:3 },
  44. { data: generate(2, 10, function (x) { return Math.tan(x);}), xaxis: 2, yaxis: 4, lines: { show: true, steps: true }},
  45. { data: generate(5, 15, function (x) { return 30 * Math.sin(x/2+3);}), xaxis: 3, yaxis: 5, bars: {show: true, fill: true, barWidth:0.1, align: "center"}}
  46. ];
  47. var plot = $.plot("#placeholder", data, {
  48. xaxes: [
  49. { position: 'bottom' },
  50. { position: 'bottom'},
  51. { position: 'top'}
  52. ],
  53. yaxes: [
  54. { position: 'left' },
  55. { position: 'left' },
  56. { position: 'right' },
  57. { position: 'left' },
  58. { position: 'right' }
  59. ]
  60. });
  61. // Create a div for each axis
  62. $.each(plot.getAxes(), function (i, axis) {
  63. if (!axis.show)
  64. return;
  65. var box = axis.box;
  66. $("<div class='axisTarget' style='position:absolute; left:" + box.left + "px; top:" + box.top + "px; width:" + box.width + "px; height:" + box.height + "px'></div>")
  67. .data("axis.direction", axis.direction)
  68. .data("axis.n", axis.n)
  69. .css({ backgroundColor: "#f00", opacity: 0, cursor: "pointer" })
  70. .appendTo(plot.getPlaceholder())
  71. .hover(
  72. function () { $(this).css({ opacity: 0.10 }) },
  73. function () { $(this).css({ opacity: 0 }) }
  74. )
  75. .click(function () {
  76. $("#click").text("You clicked the " + axis.direction + axis.n + "axis!")
  77. });
  78. });
  79. // Add the Flot version string to the footer
  80. $("#footer").prepend("Flot " + $.plot.version + " &ndash; ");
  81. });
  82. </script>
  83. </head>
  84. <body>
  85. <div id="header">
  86. <h2>Interacting with axes</h2>
  87. </div>
  88. <div id="content">
  89. <div class="demo-container">
  90. <div id="placeholder" class="demo-placeholder"></div>
  91. </div>
  92. <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>
  93. <p>Try clicking an axis.</p>
  94. <p id="click"></p>
  95. </div>
  96. <div id="footer">
  97. Copyright &copy; 2007 - 2014 IOLA and Ole Laursen
  98. </div>
  99. </body>
  100. </html>