index.html 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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: Adding Annotations</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 d1 = [];
  13. for (var i = 0; i < 20; ++i) {
  14. d1.push([i, Math.sin(i)]);
  15. }
  16. var data = [{ data: d1, label: "Pressure", color: "#333" }];
  17. var markings = [
  18. { color: "#f6f6f6", yaxis: { from: 1 } },
  19. { color: "#f6f6f6", yaxis: { to: -1 } },
  20. { color: "#000", lineWidth: 1, xaxis: { from: 2, to: 2 } },
  21. { color: "#000", lineWidth: 1, xaxis: { from: 8, to: 8 } }
  22. ];
  23. var placeholder = $("#placeholder");
  24. var plot = $.plot(placeholder, data, {
  25. bars: { show: true, barWidth: 0.5, fill: 0.9 },
  26. xaxis: { ticks: [], autoscaleMargin: 0.02 },
  27. yaxis: { min: -2, max: 2 },
  28. grid: { markings: markings }
  29. });
  30. var o = plot.pointOffset({ x: 2, y: -1.2});
  31. // Append it to the placeholder that Flot already uses for positioning
  32. placeholder.append("<div style='position:absolute;left:" + (o.left + 4) + "px;top:" + o.top + "px;color:#666;font-size:smaller'>Warming up</div>");
  33. o = plot.pointOffset({ x: 8, y: -1.2});
  34. placeholder.append("<div style='position:absolute;left:" + (o.left + 4) + "px;top:" + o.top + "px;color:#666;font-size:smaller'>Actual measurements</div>");
  35. // Draw a little arrow on top of the last label to demonstrate canvas
  36. // drawing
  37. var ctx = plot.getCanvas().getContext("2d");
  38. ctx.beginPath();
  39. o.left += 4;
  40. ctx.moveTo(o.left, o.top);
  41. ctx.lineTo(o.left, o.top - 10);
  42. ctx.lineTo(o.left + 10, o.top - 5);
  43. ctx.lineTo(o.left, o.top);
  44. ctx.fillStyle = "#000";
  45. ctx.fill();
  46. // Add the Flot version string to the footer
  47. $("#footer").prepend("Flot " + $.plot.version + " &ndash; ");
  48. });
  49. </script>
  50. </head>
  51. <body>
  52. <div id="header">
  53. <h2>Adding Annotations</h2>
  54. </div>
  55. <div id="content">
  56. <div class="demo-container">
  57. <div id="placeholder" class="demo-placeholder"></div>
  58. </div>
  59. <p>Flot has support for simple background decorations such as lines and rectangles. They can be useful for marking up certain areas. You can easily add any HTML you need with standard DOM manipulation, e.g. for labels. For drawing custom shapes there is also direct access to the canvas.</p>
  60. </div>
  61. <div id="footer">
  62. Copyright &copy; 2007 - 2013 IOLA and Ole Laursen
  63. </div>
  64. </body>
  65. </html>