flot-data.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /*
  2. Template Name: Monster Admin
  3. Author: Themedesigner
  4. Email: niravjoshi87@gmail.com
  5. File: js
  6. */
  7. // Real Time chart
  8. var data = [],
  9. totalPoints = 300;
  10. function getRandomData() {
  11. if (data.length > 0) data = data.slice(1);
  12. // Do a random walk
  13. while (data.length < totalPoints) {
  14. var prev = data.length > 0 ? data[data.length - 1] : 50,
  15. y = prev + Math.random() * 10 - 5;
  16. if (y < 0) {
  17. y = 0;
  18. } else if (y > 100) {
  19. y = 100;
  20. }
  21. data.push(y);
  22. }
  23. // Zip the generated y values with the x values
  24. var res = [];
  25. for (var i = 0; i < data.length; ++i) {
  26. res.push([i, data[i]])
  27. }
  28. return res;
  29. }
  30. // Set up the control widget
  31. var updateInterval = 30;
  32. $("#updateInterval").val(updateInterval).change(function() {
  33. var v = $(this).val();
  34. if (v && !isNaN(+v)) {
  35. updateInterval = +v;
  36. if (updateInterval < 1) {
  37. updateInterval = 1;
  38. } else if (updateInterval > 3000) {
  39. updateInterval = 3000;
  40. }
  41. $(this).val("" + updateInterval);
  42. }
  43. });
  44. var plot = $.plot("#placeholder", [getRandomData()], {
  45. series: {
  46. shadowSize: 0 // Drawing is faster without shadows
  47. },
  48. yaxis: {
  49. min: 0,
  50. max: 100
  51. },
  52. xaxis: {
  53. show: false
  54. },
  55. colors: ["#55ce63"],
  56. grid: {
  57. color: "#AFAFAF",
  58. hoverable: true,
  59. borderWidth: 0,
  60. backgroundColor: '#FFF'
  61. },
  62. tooltip: true,
  63. tooltipOpts: {
  64. content: "Y: %y",
  65. defaultTheme: false
  66. }
  67. });
  68. function update() {
  69. plot.setData([getRandomData()]);
  70. // Since the axes don't change, we don't need to call plot.setupGrid()
  71. plot.draw();
  72. setTimeout(update, updateInterval);
  73. }
  74. update();
  75. //Flot Line Chart
  76. $(document).ready(function() {
  77. console.log("document ready");
  78. var offset = 0;
  79. plot();
  80. function plot() {
  81. var sin = [],
  82. cos = [];
  83. for (var i = 0; i < 12; i += 0.2) {
  84. sin.push([i, Math.sin(i + offset)]);
  85. cos.push([i, Math.cos(i + offset)]);
  86. }
  87. var options = {
  88. series: {
  89. lines: {
  90. show: true
  91. },
  92. points: {
  93. show: true
  94. }
  95. },
  96. grid: {
  97. hoverable: true //IMPORTANT! this is needed for tooltip to work
  98. },
  99. yaxis: {
  100. min: -1.2,
  101. max: 1.2
  102. },
  103. colors: ["#009efb", "#55ce63"],
  104. grid: {
  105. color: "#AFAFAF",
  106. hoverable: true,
  107. borderWidth: 0,
  108. backgroundColor: '#FFF'
  109. },
  110. tooltip: true,
  111. tooltipOpts: {
  112. content: "'%s' of %x.1 is %y.4",
  113. shifts: {
  114. x: -60,
  115. y: 25
  116. }
  117. }
  118. };
  119. var plotObj = $.plot($("#flot-line-chart"), [{
  120. data: sin,
  121. label: "sin(x)",
  122. }, {
  123. data: cos,
  124. label: "cos(x)"
  125. }], options);
  126. }
  127. });