index.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. $(function () {
  2. //Widgets count
  3. $('.count-to').countTo();
  4. //Sales count to
  5. $('.sales-count-to').countTo({
  6. formatter: function (value, options) {
  7. return '$' + value.toFixed(2).replace(/(\d)(?=(\d\d\d)+(?!\d))/g, ' ').replace('.', ',');
  8. }
  9. });
  10. initRealTimeChart();
  11. initDonutChart();
  12. initSparkline();
  13. });
  14. var realtime = 'on';
  15. function initRealTimeChart() {
  16. //Real time ==========================================================================================
  17. var plot = $.plot('#real_time_chart', [getRandomData()], {
  18. series: {
  19. shadowSize: 0,
  20. color: 'rgb(0, 188, 212)'
  21. },
  22. grid: {
  23. borderColor: '#f3f3f3',
  24. borderWidth: 1,
  25. tickColor: '#f3f3f3'
  26. },
  27. lines: {
  28. fill: true
  29. },
  30. yaxis: {
  31. min: 0,
  32. max: 100
  33. },
  34. xaxis: {
  35. min: 0,
  36. max: 100
  37. }
  38. });
  39. function updateRealTime() {
  40. plot.setData([getRandomData()]);
  41. plot.draw();
  42. var timeout;
  43. if (realtime === 'on') {
  44. timeout = setTimeout(updateRealTime, 320);
  45. } else {
  46. clearTimeout(timeout);
  47. }
  48. }
  49. updateRealTime();
  50. $('#realtime').on('change', function () {
  51. realtime = this.checked ? 'on' : 'off';
  52. updateRealTime();
  53. });
  54. //====================================================================================================
  55. }
  56. function initSparkline() {
  57. $(".sparkline").each(function () {
  58. var $this = $(this);
  59. $this.sparkline('html', $this.data());
  60. });
  61. }
  62. function initDonutChart() {
  63. Morris.Donut({
  64. element: 'donut_chart',
  65. data: [{
  66. label: 'Chrome',
  67. value: 37
  68. }, {
  69. label: 'Firefox',
  70. value: 30
  71. }, {
  72. label: 'Safari',
  73. value: 18
  74. }, {
  75. label: 'Opera',
  76. value: 12
  77. },
  78. {
  79. label: 'Other',
  80. value: 3
  81. }],
  82. colors: ['rgb(233, 30, 99)', 'rgb(0, 188, 212)', 'rgb(255, 152, 0)', 'rgb(0, 150, 136)', 'rgb(96, 125, 139)'],
  83. formatter: function (y) {
  84. return y + '%'
  85. }
  86. });
  87. }
  88. var data = [], totalPoints = 110;
  89. function getRandomData() {
  90. if (data.length > 0) data = data.slice(1);
  91. while (data.length < totalPoints) {
  92. var prev = data.length > 0 ? data[data.length - 1] : 50, y = prev + Math.random() * 10 - 5;
  93. if (y < 0) { y = 0; } else if (y > 100) { y = 100; }
  94. data.push(y);
  95. }
  96. var res = [];
  97. for (var i = 0; i < data.length; ++i) {
  98. res.push([i, data[i]]);
  99. }
  100. return res;
  101. }