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.

selection.html 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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.selection.js"></script>
  11. </head>
  12. <body>
  13. <h1>Flot Examples</h1>
  14. <div id="placeholder" style="width:600px;height:300px"></div>
  15. <p>1000 kg. CO<sub>2</sub> emissions per year per capita for various countries (source: <a href="http://en.wikipedia.org/wiki/List_of_countries_by_carbon_dioxide_emissions_per_capita">Wikipedia</a>).</p>
  16. <p>Flot supports selections through the selection plugin.
  17. You can enable rectangular selection
  18. or one-dimensional selection if the user should only be able to
  19. select on one axis. Try left-click and drag on the plot above
  20. where selection on the x axis is enabled.</p>
  21. <p>You selected: <span id="selection"></span></p>
  22. <p>The plot command returns a plot object you can use to control
  23. the selection. Click the buttons below.</p>
  24. <p><input id="clearSelection" type="button" value="Clear selection" />
  25. <input id="setSelection" type="button" value="Select year 1994" /></p>
  26. <p>Selections are really useful for zooming. Just replot the
  27. chart with min and max values for the axes set to the values
  28. in the "plotselected" event triggered. Enable the checkbox
  29. below and select a region again.</p>
  30. <p><input id="zoom" type="checkbox">Zoom to selection.</input></p>
  31. <script id="source" language="javascript" type="text/javascript">
  32. $(function () {
  33. var data = [
  34. {
  35. label: "United States",
  36. data: [[1990, 18.9], [1991, 18.7], [1992, 18.4], [1993, 19.3], [1994, 19.5], [1995, 19.3], [1996, 19.4], [1997, 20.2], [1998, 19.8], [1999, 19.9], [2000, 20.4], [2001, 20.1], [2002, 20.0], [2003, 19.8], [2004, 20.4]]
  37. },
  38. {
  39. label: "Russia",
  40. data: [[1992, 13.4], [1993, 12.2], [1994, 10.6], [1995, 10.2], [1996, 10.1], [1997, 9.7], [1998, 9.5], [1999, 9.7], [2000, 9.9], [2001, 9.9], [2002, 9.9], [2003, 10.3], [2004, 10.5]]
  41. },
  42. {
  43. label: "United Kingdom",
  44. data: [[1990, 10.0], [1991, 11.3], [1992, 9.9], [1993, 9.6], [1994, 9.5], [1995, 9.5], [1996, 9.9], [1997, 9.3], [1998, 9.2], [1999, 9.2], [2000, 9.5], [2001, 9.6], [2002, 9.3], [2003, 9.4], [2004, 9.79]]
  45. },
  46. {
  47. label: "Germany",
  48. data: [[1990, 12.4], [1991, 11.2], [1992, 10.8], [1993, 10.5], [1994, 10.4], [1995, 10.2], [1996, 10.5], [1997, 10.2], [1998, 10.1], [1999, 9.6], [2000, 9.7], [2001, 10.0], [2002, 9.7], [2003, 9.8], [2004, 9.79]]
  49. },
  50. {
  51. label: "Denmark",
  52. data: [[1990, 9.7], [1991, 12.1], [1992, 10.3], [1993, 11.3], [1994, 11.7], [1995, 10.6], [1996, 12.8], [1997, 10.8], [1998, 10.3], [1999, 9.4], [2000, 8.7], [2001, 9.0], [2002, 8.9], [2003, 10.1], [2004, 9.80]]
  53. },
  54. {
  55. label: "Sweden",
  56. data: [[1990, 5.8], [1991, 6.0], [1992, 5.9], [1993, 5.5], [1994, 5.7], [1995, 5.3], [1996, 6.1], [1997, 5.4], [1998, 5.4], [1999, 5.1], [2000, 5.2], [2001, 5.4], [2002, 6.2], [2003, 5.9], [2004, 5.89]]
  57. },
  58. {
  59. label: "Norway",
  60. data: [[1990, 8.3], [1991, 8.3], [1992, 7.8], [1993, 8.3], [1994, 8.4], [1995, 5.9], [1996, 6.4], [1997, 6.7], [1998, 6.9], [1999, 7.6], [2000, 7.4], [2001, 8.1], [2002, 12.5], [2003, 9.9], [2004, 19.0]]
  61. }
  62. ];
  63. var options = {
  64. series: {
  65. lines: { show: true },
  66. points: { show: true }
  67. },
  68. legend: { noColumns: 2 },
  69. xaxis: { tickDecimals: 0 },
  70. yaxis: { min: 0 },
  71. selection: { mode: "x" }
  72. };
  73. var placeholder = $("#placeholder");
  74. placeholder.bind("plotselected", function (event, ranges) {
  75. $("#selection").text(ranges.xaxis.from.toFixed(1) + " to " + ranges.xaxis.to.toFixed(1));
  76. var zoom = $("#zoom").attr("checked");
  77. if (zoom)
  78. plot = $.plot(placeholder, data,
  79. $.extend(true, {}, options, {
  80. xaxis: { min: ranges.xaxis.from, max: ranges.xaxis.to }
  81. }));
  82. });
  83. placeholder.bind("plotunselected", function (event) {
  84. $("#selection").text("");
  85. });
  86. var plot = $.plot(placeholder, data, options);
  87. $("#clearSelection").click(function () {
  88. plot.clearSelection();
  89. });
  90. $("#setSelection").click(function () {
  91. plot.setSelection({ x1: 1994, x2: 1995 });
  92. });
  93. });
  94. </script>
  95. </body>
  96. </html>