annotations.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*=========================================================================================
  2. File Name: annotation.js
  3. Description: Flot annotation chart
  4. ----------------------------------------------------------------------------------------
  5. Item Name: Robust - Responsive Admin Theme
  6. Version: 1.2
  7. Author: PIXINVENT
  8. Author URL: http://www.themeforest.net/user/pixinvent
  9. ==========================================================================================*/
  10. // Annotation chart
  11. // ------------------------------
  12. $(window).on("load", function(){
  13. var d1 = [];
  14. for (var i = 0; i < 20; ++i) {
  15. d1.push([i, Math.sin(i)]);
  16. }
  17. var data = [{ data: d1, label: "Pressure", color: "#3F51B5" }];
  18. var markings = [
  19. { color: "#f6f6f6", yaxis: { from: 1 } },
  20. { color: "#f6f6f6", yaxis: { to: -1 } },
  21. { color: "#000", lineWidth: 1, xaxis: { from: 2, to: 2 } },
  22. { color: "#000", lineWidth: 1, xaxis: { from: 8, to: 8 } }
  23. ];
  24. var placeholder = $("#annotation");
  25. var plot = $.plot(placeholder, data, {
  26. bars: { show: true, barWidth: 0.5, fill: true, lineWidth: 0, fillColor: { colors: [ { opacity: 0.5 }, { opacity: 0.8 } ] } },
  27. xaxis: { ticks: [], autoscaleMargin: 0.02 },
  28. yaxis: { min: -2, max: 2 },
  29. grid: {
  30. borderWidth: 1,
  31. borderColor: "#e9e9e9",
  32. color: '#999',
  33. minBorderMargin: 20,
  34. labelMargin: 10,
  35. margin: {
  36. top: 8,
  37. bottom: 20,
  38. left: 20
  39. },
  40. markings: markings
  41. },
  42. });
  43. var o = plot.pointOffset({ x: 2, y: -1.2});
  44. // Append it to the placeholder that Flot already uses for positioning
  45. placeholder.append("<div style='position:absolute;left:" + (o.left + 4) + "px;top:" + o.top + "px;color:#666;font-size:smaller'>Warming up</div>");
  46. o = plot.pointOffset({ x: 8, y: -1.2});
  47. placeholder.append("<div style='position:absolute;left:" + (o.left + 4) + "px;top:" + o.top + "px;color:#666;font-size:smaller'>Actual measurements</div>");
  48. // Draw a little arrow on top of the last label to demonstrate canvas
  49. // drawing
  50. var ctx = plot.getCanvas().getContext("2d");
  51. ctx.beginPath();
  52. o.left += 4;
  53. ctx.moveTo(o.left, o.top);
  54. ctx.lineTo(o.left, o.top - 10);
  55. ctx.lineTo(o.left + 10, o.top - 5);
  56. ctx.lineTo(o.left, o.top);
  57. ctx.fillStyle = "#000";
  58. ctx.fill();
  59. });