PHP/JavaScript webapp to analyse spending habits
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

tracking.html 3.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  5. <title>Flot Examples</title>
  6. <link href="layout.css" rel="stylesheet" type="text/css"></link>
  7. <!--[if IE]><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 language="javascript" type="text/javascript" src="../jquery.flot.crosshair.js"></script>
  11. </head>
  12. <body>
  13. <h1>Flot Examples</h1>
  14. <div id="placeholder" style="width:600px;height:300px"></div>
  15. <p>You can add crosshairs that'll track the mouse position, either
  16. on both axes or as here on only one.</p>
  17. <p>If you combine it with listening on hover events, you can use
  18. it to track the intersection on the curves by interpolating
  19. the data points (look at the legend).</p>
  20. <p id="hoverdata"></p>
  21. <script id="source" language="javascript" type="text/javascript">
  22. var plot;
  23. $(function () {
  24. var sin = [], cos = [];
  25. for (var i = 0; i < 14; i += 0.1) {
  26. sin.push([i, Math.sin(i)]);
  27. cos.push([i, Math.cos(i)]);
  28. }
  29. plot = $.plot($("#placeholder"),
  30. [ { data: sin, label: "sin(x) = -0.00"},
  31. { data: cos, label: "cos(x) = -0.00" } ], {
  32. series: {
  33. lines: { show: true }
  34. },
  35. crosshair: { mode: "x" },
  36. grid: { hoverable: true, autoHighlight: false },
  37. yaxis: { min: -1.2, max: 1.2 }
  38. });
  39. var legends = $("#placeholder .legendLabel");
  40. legends.each(function () {
  41. // fix the widths so they don't jump around
  42. $(this).css('width', $(this).width());
  43. });
  44. var updateLegendTimeout = null;
  45. var latestPosition = null;
  46. function updateLegend() {
  47. updateLegendTimeout = null;
  48. var pos = latestPosition;
  49. var axes = plot.getAxes();
  50. if (pos.x < axes.xaxis.min || pos.x > axes.xaxis.max ||
  51. pos.y < axes.yaxis.min || pos.y > axes.yaxis.max)
  52. return;
  53. var i, j, dataset = plot.getData();
  54. for (i = 0; i < dataset.length; ++i) {
  55. var series = dataset[i];
  56. // find the nearest points, x-wise
  57. for (j = 0; j < series.data.length; ++j)
  58. if (series.data[j][0] > pos.x)
  59. break;
  60. // now interpolate
  61. var y, p1 = series.data[j - 1], p2 = series.data[j];
  62. if (p1 == null)
  63. y = p2[1];
  64. else if (p2 == null)
  65. y = p1[1];
  66. else
  67. y = p1[1] + (p2[1] - p1[1]) * (pos.x - p1[0]) / (p2[0] - p1[0]);
  68. legends.eq(i).text(series.label.replace(/=.*/, "= " + y.toFixed(2)));
  69. }
  70. }
  71. $("#placeholder").bind("plothover", function (event, pos, item) {
  72. latestPosition = pos;
  73. if (!updateLegendTimeout)
  74. updateLegendTimeout = setTimeout(updateLegend, 50);
  75. });
  76. });
  77. </script>
  78. </body>
  79. </html>