index.html 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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: Interactivity</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. var sin = [],
  13. cos = [];
  14. for (var i = 0; i < 14; i += 0.5) {
  15. sin.push([i, Math.sin(i)]);
  16. cos.push([i, Math.cos(i)]);
  17. }
  18. var plot = $.plot("#placeholder", [
  19. { data: sin, label: "sin(x)"},
  20. { data: cos, label: "cos(x)"}
  21. ], {
  22. series: {
  23. lines: {
  24. show: true
  25. },
  26. points: {
  27. show: true
  28. }
  29. },
  30. grid: {
  31. hoverable: true,
  32. clickable: true
  33. },
  34. yaxis: {
  35. min: -1.2,
  36. max: 1.2
  37. }
  38. });
  39. $("<div id='tooltip'></div>").css({
  40. position: "absolute",
  41. display: "none",
  42. border: "1px solid #fdd",
  43. padding: "2px",
  44. "background-color": "#fee",
  45. opacity: 0.80
  46. }).appendTo("body");
  47. $("#placeholder").bind("plothover", function (event, pos, item) {
  48. if ($("#enablePosition:checked").length > 0) {
  49. var str = "(" + pos.x.toFixed(2) + ", " + pos.y.toFixed(2) + ")";
  50. $("#hoverdata").text(str);
  51. }
  52. if ($("#enableTooltip:checked").length > 0) {
  53. if (item) {
  54. var x = item.datapoint[0].toFixed(2),
  55. y = item.datapoint[1].toFixed(2);
  56. $("#tooltip").html(item.series.label + " of " + x + " = " + y)
  57. .css({top: item.pageY+5, left: item.pageX+5})
  58. .fadeIn(200);
  59. } else {
  60. $("#tooltip").hide();
  61. }
  62. }
  63. });
  64. $("#placeholder").bind("plotclick", function (event, pos, item) {
  65. if (item) {
  66. $("#clickdata").text(" - click point " + item.dataIndex + " in " + item.series.label);
  67. plot.highlight(item.series, item.datapoint);
  68. }
  69. });
  70. // Add the Flot version string to the footer
  71. $("#footer").prepend("Flot " + $.plot.version + " &ndash; ");
  72. });
  73. </script>
  74. </head>
  75. <body>
  76. <div id="header">
  77. <h2>Interactivity</h2>
  78. </div>
  79. <div id="content">
  80. <div class="demo-container">
  81. <div id="placeholder" class="demo-placeholder"></div>
  82. </div>
  83. <p>One of the goals of Flot is to support user interactions. Try pointing and clicking on the points.</p>
  84. <p>
  85. <label><input id="enablePosition" type="checkbox" checked="checked"></input>Show mouse position</label>
  86. <span id="hoverdata"></span>
  87. <span id="clickdata"></span>
  88. </p>
  89. <p>A tooltip is easy to build with a bit of jQuery code and the data returned from the plot.</p>
  90. <p><label><input id="enableTooltip" type="checkbox" checked="checked"></input>Enable tooltip</label></p>
  91. </div>
  92. <div id="footer">
  93. Copyright &copy; 2007 - 2014 IOLA and Ole Laursen
  94. </div>
  95. </body>
  96. </html>