dashboard2.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. $(document).ready(function () {
  2. "use strict";
  3. //gauge chart
  4. $(".mtbutton").on("click", function () {
  5. var randomNum = Math.floor((Math.random() * 100));
  6. $('#gaugeDemo .gauge-arrow').trigger('updateGauge', randomNum);
  7. });
  8. $('#gaugeDemo .gauge-arrow').cmGauge();
  9. //extra-chart
  10. var chart = new Chartist.Line('#ct-extra', {
  11. labels: ['1', '2', '3', '4', '5', '6'],
  12. series: [
  13. [1, -2, 5, 3, 0, 2.5]
  14. ]
  15. }, {
  16. showArea: true,
  17. showPoint: true,
  18. height: 100,
  19. chartPadding: {
  20. left: -20,
  21. top: 10,
  22. },
  23. axisX: {
  24. showLabel: false,
  25. showGrid: true
  26. },
  27. axisY: {
  28. showLabel: false,
  29. showGrid: false
  30. },
  31. fullWidth: true,
  32. plugins: [
  33. Chartist.plugins.tooltip()
  34. ]
  35. });
  36. //ct-main-balance-chart
  37. var chart = new Chartist.Line('#ct-main-bal', {
  38. labels: ['1', '2', '3', '4', '5', '6', '7', '8', '9'],
  39. series: [
  40. [1, 2, 5, 3, 4, 2.5, 5, 3, 1],
  41. [1, 4, 2, 5, 2, 5.5, 3, 4, 1]
  42. ]
  43. }, {
  44. showArea: true,
  45. showPoint: true,
  46. height: 100,
  47. chartPadding: {
  48. left: -20,
  49. top: 10,
  50. },
  51. axisX: {
  52. showLabel: false,
  53. showGrid: false
  54. },
  55. axisY: {
  56. showLabel: false,
  57. showGrid: false
  58. },
  59. fullWidth: true,
  60. plugins: [
  61. Chartist.plugins.tooltip()
  62. ]
  63. });
  64. //ct-bar-chart
  65. new Chartist.Bar('#ct-bar-chart', {
  66. labels: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
  67. series: [
  68. [5, 4, 3, 7, 5, 2, 3]
  69. ]
  70. }, {
  71. axisX: {
  72. showLabel: false,
  73. showGrid: false,
  74. // On the x-axis start means top and end means bottom
  75. position: 'start'
  76. },
  77. chartPadding: {
  78. top: -20,
  79. },
  80. axisY: {
  81. showLabel: false,
  82. showGrid: false,
  83. offset: 0
  84. },
  85. fullWidth: true,
  86. height: 65,
  87. plugins: [
  88. Chartist.plugins.tooltip()
  89. ]
  90. });
  91. // Morris donut chart
  92. Morris.Donut({
  93. element: 'morris-donut-chart',
  94. data: [{
  95. label: "Jan",
  96. value: 15,
  97. }, {
  98. label: "Feb",
  99. value: 15,
  100. }, {
  101. label: "Mar",
  102. value: 35,
  103. }, {
  104. label: "Apr",
  105. value: 105
  106. }],
  107. resize: true,
  108. backgroundColor: '#353c48',
  109. labelColor: '#96a2b4',
  110. colors: ['#ff7676', '#2cabe3', '#53e69d', '#7bcef3']
  111. });
  112. // Real Time chart
  113. var data = [],
  114. totalPoints = 300;
  115. function getRandomData() {
  116. if (data.length > 0) data = data.slice(1);
  117. // Do a random walk
  118. while (data.length < totalPoints) {
  119. var prev = data.length > 0 ? data[data.length - 1] : 50,
  120. y = prev + Math.random() * 10 - 5;
  121. if (y < 0) {
  122. y = 0;
  123. } else if (y > 100) {
  124. y = 100;
  125. }
  126. data.push(y);
  127. }
  128. // Zip the generated y values with the x values
  129. var res = [];
  130. for (var i = 0; i < data.length; ++i) {
  131. res.push([i, data[i]])
  132. }
  133. return res;
  134. }
  135. // Set up the control widget
  136. var updateInterval = 30;
  137. $("#updateInterval").val(updateInterval).change(function () {
  138. var v = $(this).val();
  139. if (v && !isNaN(+v)) {
  140. updateInterval = +v;
  141. if (updateInterval < 1) {
  142. updateInterval = 1;
  143. } else if (updateInterval > 3000) {
  144. updateInterval = 3000;
  145. }
  146. $(this).val("" + updateInterval);
  147. }
  148. });
  149. var plot = $.plot("#placeholder", [getRandomData()], {
  150. series: {
  151. shadowSize: 0 // Drawing is faster without shadows
  152. },
  153. yaxis: {
  154. min: 0,
  155. max: 100
  156. },
  157. xaxis: {
  158. show: false
  159. },
  160. colors: ["#fff"],
  161. grid: {
  162. color: "rgba(255, 255, 255, 0.3)",
  163. hoverable: true,
  164. borderWidth: 0
  165. },
  166. tooltip: true,
  167. tooltipOpts: {
  168. content: "Y: %y",
  169. defaultTheme: false
  170. }
  171. });
  172. function update() {
  173. plot.setData([getRandomData()]);
  174. // Since the axes don't change, we don't need to call plot.setupGrid()
  175. plot.draw();
  176. setTimeout(update, updateInterval);
  177. }
  178. $(window).resize(function () {
  179. $.plot($('#placeholder'), [getRandomData()]);
  180. });
  181. update();
  182. });