be_pages_crypto_dashboard.js 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. /*
  2. * Document : be_pages_crypto_dashboard.js
  3. * Author : pixelcave
  4. * Description: Custom JS code used in Crypto Dashboard Page
  5. */
  6. var BePagesCryptoDashboard = function() {
  7. // Crypto Charts, for more examples you can check out http://www.chartjs.org/docs
  8. var initChartsCrypto = function () {
  9. // Set Global Chart.js configuration
  10. Chart.defaults.global.defaultFontColor = '#555555';
  11. Chart.defaults.scale.gridLines.color = "transparent";
  12. Chart.defaults.global.elements.point.radius = 5;
  13. Chart.defaults.global.elements.point.hoverRadius = 7;
  14. Chart.defaults.global.tooltips.cornerRadius = 3;
  15. Chart.defaults.global.legend.labels.boxWidth = 15;
  16. Chart.defaults.global.legend.display = false;
  17. // Get Chart Containers
  18. var chartBitcoinCon = jQuery('.js-chartjs-bitcoin');
  19. var chartEthereumCon = jQuery('.js-chartjs-ethereum');
  20. var chartLitecoinCon = jQuery('.js-chartjs-litecoin');
  21. // Helper Classes
  22. var chartBitcoin, chartEthereum, chartLitecoin;
  23. // Set up labels
  24. var chartCryptolabels = [];
  25. for (i = 0; i < 30; i++) {
  26. chartCryptolabels[i] = (i === 29) ? '1 day ago' : (30 - i) + ' days ago';
  27. }
  28. // Cryto Data
  29. chartBitcoinData = [10500, 10400, 9500, 8268, 10218, 8250, 8707, 9284, 9718, 9950, 9879, 10147, 10883, 11071, 11332, 11584, 11878, 13540, 16501, 16007, 15142, 14869, 16762, 17276, 16808, 16678, 16771, 12900, 13100, 14000];
  30. chartEthereumData = [500, 525, 584, 485, 470, 320, 380, 580, 620, 785, 795, 801, 799, 750, 900, 920, 930, 1300, 1250, 1150, 1365, 1258, 980, 870, 860, 925, 999, 1050, 1090, 1100];
  31. chartLitecoinData = [300, 320, 330, 331, 335, 340, 358, 310, 220, 180, 190, 195, 203, 187, 198, 258, 270, 340, 356, 309, 218, 230, 242, 243, 250, 210, 205, 226, 214, 250];
  32. // Init Bitcoin Chart on Tab Shown
  33. jQuery('a[href="#crypto-coins-btc"]', 'ul#crypto-tabs').on('shown.bs.tab', function(e) {
  34. // if already exists destroy it
  35. if (chartBitcoin) {
  36. chartBitcoin.destroy();
  37. }
  38. // Init Chart
  39. chartBitcoin = new Chart(chartBitcoinCon, {
  40. type: 'line',
  41. data: {
  42. labels: chartCryptolabels,
  43. datasets: [
  44. {
  45. label: 'Bitcoin Price',
  46. fill: true,
  47. backgroundColor: 'rgba(255,193,7,.25)',
  48. borderColor: 'rgba(255,193,7,1)',
  49. pointBackgroundColor: 'rgba(255,193,7,1)',
  50. pointBorderColor: '#fff',
  51. pointHoverBackgroundColor: '#fff',
  52. pointHoverBorderColor: 'rgba(255,193,7,1)',
  53. data: chartBitcoinData
  54. }
  55. ]
  56. },
  57. options: {
  58. maintainAspectRatio: false,
  59. scales: {
  60. yAxes: [{
  61. ticks: {
  62. suggestedMin: 6000,
  63. suggestedMax: 20000
  64. }
  65. }]
  66. },
  67. tooltips: {
  68. intersect: false,
  69. callbacks: {
  70. label: function(tooltipItems, data) {
  71. return ' $' + tooltipItems.yLabel;
  72. }
  73. }
  74. }
  75. }
  76. });
  77. });
  78. // Init Ethereum Chart on Tab Shown
  79. jQuery('a[href="#crypto-coins-eth"]', 'ul#crypto-tabs').on('shown.bs.tab', function(e) {
  80. // if already exists destroy it
  81. if (chartEthereum) {
  82. chartEthereum.destroy();
  83. }
  84. // Init Chart
  85. chartEthereum = new Chart(chartEthereumCon, {
  86. type: 'line',
  87. data: {
  88. labels: chartCryptolabels,
  89. datasets: [
  90. {
  91. label: 'Ethereum Price',
  92. fill: true,
  93. backgroundColor: 'rgba(111,124,186, .25)',
  94. borderColor: 'rgba(111,124,186, 1)',
  95. pointBackgroundColor: 'rgba(111,124,186, 1)',
  96. pointBorderColor: '#fff',
  97. pointHoverBackgroundColor: '#fff',
  98. pointHoverBorderColor: 'rgba(111,124,186, 1)',
  99. data: chartEthereumData
  100. }
  101. ]
  102. },
  103. options: {
  104. maintainAspectRatio: false,
  105. scales: {
  106. yAxes: [{
  107. ticks: {
  108. suggestedMin: 0,
  109. suggestedMax: 1500
  110. }
  111. }]
  112. },
  113. tooltips: {
  114. intersect: false,
  115. callbacks: {
  116. label: function(tooltipItems, data) {
  117. return ' $' + tooltipItems.yLabel;
  118. }
  119. }
  120. }
  121. }
  122. });
  123. });
  124. // Init Litecoin Chart on Tab Shown
  125. jQuery('a[href="#crypto-coins-ltc"]', 'ul#crypto-tabs').on('shown.bs.tab', function(e) {
  126. // if already exists destroy it
  127. if (chartLitecoin) {
  128. chartLitecoin.destroy();
  129. }
  130. // Init Chart
  131. chartLitecoin = new Chart(chartLitecoinCon, {
  132. type: 'line',
  133. data: {
  134. labels: chartCryptolabels,
  135. datasets: [
  136. {
  137. label: 'Litecoin Price',
  138. fill: true,
  139. backgroundColor: 'rgba(181,181,181,.25)',
  140. borderColor: 'rgba(181,181,181,1)',
  141. pointBackgroundColor: 'rgba(181,181,181,1)',
  142. pointBorderColor: '#fff',
  143. pointHoverBackgroundColor: '#fff',
  144. pointHoverBorderColor: 'rgba(181,181,181,1)',
  145. data: chartLitecoinData
  146. }
  147. ]
  148. },
  149. options: {
  150. maintainAspectRatio: false,
  151. scales: {
  152. yAxes: [{
  153. ticks: {
  154. suggestedMin: 0,
  155. suggestedMax: 400
  156. }
  157. }]
  158. },
  159. tooltips: {
  160. intersect: false,
  161. callbacks: {
  162. label: function(tooltipItems, data) {
  163. return ' $' + tooltipItems.yLabel;
  164. }
  165. }
  166. }
  167. }
  168. });
  169. });
  170. // Shown Bitcoin Tab which will trigger the first init of the chart
  171. jQuery('a[href="#crypto-coins-btc"]', 'ul#crypto-tabs').tab('show');
  172. };
  173. return {
  174. init: function () {
  175. // Init Crypto charts
  176. initChartsCrypto();
  177. }
  178. };
  179. }();
  180. // Initialize when page loads
  181. jQuery(function(){ BePagesCryptoDashboard.init(); });