1
0

app_demo_dashboard.js 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. "use strict";
  2. var app_demo_dashboard = {
  3. rickshaw: function(){
  4. if($("#dashboard-chart-line").length > 0){
  5. // line chart
  6. var data1 = [
  7. {x: 0, y:14},{x: 1, y:12},{x: 2, y:18},{x: 3, y:17},{x: 4, y:15}, {x: 5, y:11},{x: 6, y:15},{x: 7, y:13},{x: 8, y:16},{x: 9, y:18,},{x: 10, y:16},
  8. {x: 11, y:18},{x: 12, y:16},{x: 13, y:15},{x: 14, y:15},{x: 15, y:15}, {x: 16, y:17},{x: 17, y:16},{x: 18, y:19},{x: 19, y:20},{x: 20, y:22,},{x: 21, y:23},
  9. {x: 22, y:21},{x: 23, y:18},{x: 24, y:19},{x: 25, y:15},{x: 26, y:16}, {x: 27, y:17},{x: 28, y:19},{x: 29, y:22},{x: 30, y:24}
  10. ];
  11. var data2 = [
  12. {x: 0, y:12},{x: 1, y:10},{x: 2, y:14},{x: 3, y:15},{x: 4, y:11}, {x: 5, y:9},{x: 6, y:14},{x: 7, y:12},{x: 8, y:13},{x: 9, y:16,},{x: 10, y:15},
  13. {x: 11, y:16},{x: 12, y:13},{x: 13, y:10},{x: 14, y:8},{x: 15, y:11}, {x: 16, y:13},{x: 17, y:15},{x: 18, y:16},{x: 19, y:19},{x: 20, y:20,},{x: 21, y:19},
  14. {x: 22, y:17},{x: 23, y:14},{x: 24, y:15},{x: 25, y:12},{x: 26, y:14}, {x: 27, y:13},{x: 28, y:15},{x: 29, y:18},{x: 30, y:21}
  15. ];
  16. var rlp = new Rickshaw.Graph({
  17. element: document.getElementById("dashboard-chart-line"),
  18. renderer: 'lineplot',
  19. min: 5,
  20. max: 25,
  21. padding: {top: 10},
  22. series: [{data: data1, color: '#2D3349', name: "Purchase click"},{data: data2, color: '#76AB3C', name: "Sales"}]
  23. });
  24. var xTicks = new Rickshaw.Graph.Axis.X({
  25. graph: rlp,
  26. orientation: "bottom",
  27. element: document.querySelector("#xaxis")
  28. });
  29. var yTicks = new Rickshaw.Graph.Axis.Y({
  30. graph: rlp,
  31. orientation: "left",
  32. element: document.querySelector("#yaxis")
  33. });
  34. new Rickshaw.Graph.HoverDetail({
  35. graph: rlp,
  36. formatter: function(series, x, y) {
  37. var swatch = '<span class="detail_swatch" style="background-color: ' + series.color + '"></span>';
  38. var content = swatch + series.name + ": " + parseInt(y) + '<br>';
  39. return content;
  40. }
  41. });
  42. rlp.render();
  43. var rlp_resize = function () {
  44. rlp.configure({
  45. width: $("#dashboard-chart-line").width(),
  46. height: $("#dashboard-chart-line").height()
  47. });
  48. rlp.render();
  49. }
  50. window.addEventListener('resize', rlp_resize);
  51. rlp_resize();
  52. // eof lineplot
  53. }
  54. },
  55. chartjs: function(){
  56. if($("#chartjs_doughnut").length === 0) return false;
  57. window.chartColors = {
  58. red: 'rgb(239, 64, 67)',
  59. orange: 'rgb(246, 159, 0)',
  60. yellow: 'rgb(242, 255, 37)',
  61. green: 'rgb(118, 171, 60)',
  62. blue: 'rgb(79, 181, 221)',
  63. purple: 'rgb(153, 102, 255)',
  64. grey: 'rgb(231,233,237)'
  65. };
  66. window.randomScalingFactor = function() {
  67. return (Math.random() > 0.5 ? 1.0 : -1.0) * Math.round(Math.random() * 100);
  68. }
  69. var MONTHS = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
  70. var config = {
  71. type: 'line',
  72. data: {
  73. labels: MONTHS,
  74. datasets: [{
  75. label: "Sales",
  76. backgroundColor: window.chartColors.red,
  77. borderColor: window.chartColors.red,
  78. data: [
  79. randomScalingFactor(),
  80. randomScalingFactor(),
  81. randomScalingFactor(),
  82. randomScalingFactor(),
  83. randomScalingFactor(),
  84. randomScalingFactor(),
  85. randomScalingFactor(),
  86. randomScalingFactor(),
  87. randomScalingFactor(),
  88. randomScalingFactor(),
  89. randomScalingFactor(),
  90. randomScalingFactor()
  91. ],
  92. fill: false,
  93. }]
  94. },
  95. options: {
  96. responsive: true,
  97. maintainAspectRatio: false,
  98. title:{
  99. display:false,
  100. text:'Chart.js Line Chart'
  101. },
  102. tooltips: {
  103. mode: 'index',
  104. intersect: false,
  105. },
  106. hover: {
  107. mode: 'nearest',
  108. intersect: true
  109. },
  110. scales: {
  111. xAxes: [{
  112. display: true,
  113. scaleLabel: {
  114. display: true,
  115. labelString: 'Month'
  116. }
  117. }],
  118. yAxes: [{
  119. display: true,
  120. scaleLabel: {
  121. display: true,
  122. labelString: 'Value'
  123. }
  124. }]
  125. }
  126. }
  127. };
  128. var config_doughnut = {
  129. type: 'doughnut',
  130. data: {
  131. datasets: [{
  132. data: [
  133. 55,
  134. 35,
  135. 10
  136. ],
  137. backgroundColor: [
  138. window.chartColors.red,
  139. window.chartColors.green,
  140. window.chartColors.blue
  141. ],
  142. label: 'Dataset 1'
  143. }],
  144. labels: [
  145. "Search Engine",
  146. "Social Media",
  147. "Direct",
  148. ]
  149. },
  150. options: {
  151. responsive: true
  152. }
  153. };
  154. window.onload = function() {
  155. var ctx_line = document.getElementById("chartjs_line").getContext("2d");
  156. window.myLine = new Chart(ctx_line, config);
  157. var ctx_doughnut = document.getElementById("chartjs_doughnut").getContext("2d");
  158. window.myDoughnut = new Chart(ctx_doughnut, config_doughnut);
  159. };
  160. },
  161. map: function(){
  162. if($("#dashboard-map").length > 0){
  163. var data = [];
  164. data.names = ["Shopnumone","Best Shoptwo","Third Awesome","Alltranding","Shop Name"];
  165. data.sales = ["135","121","107","83","77"];
  166. $("#dashboard-map").vectorMap({
  167. map: "us_aea_en",
  168. backgroundColor: "#FFF",
  169. regionsSelectable: false,
  170. regionStyle: {
  171. selected: {fill: "#2D3349"},
  172. initial: {fill: "#DBE0E4"}
  173. },
  174. markers: [
  175. [61.18, -149.53],
  176. [21.18, -157.49],
  177. [40.66, -73.56],
  178. [41.52, -87.37],
  179. [35.22, -80.84]
  180. ],
  181. markerStyle: {
  182. initial: {
  183. fill: '#2D3349',
  184. stroke: '#2D3349'
  185. }
  186. },
  187. onMarkerTipShow: function(event, label, index){
  188. label.html(
  189. '<b>'+data.names[index]+'</b><br/>'+
  190. '<b>Sales: </b>'+data.sales[index]+'</br>'
  191. );
  192. }
  193. });
  194. }
  195. }
  196. };
  197. $(function(){
  198. app_demo_dashboard.rickshaw();
  199. app_demo_dashboard.chartjs();
  200. app_demo_dashboard.map();
  201. });