location-wise-reviews.html 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. {% extends 'user-base.html' %}
  2. {% block content %}
  3. <canvas class="my-4" id="myChart" width="900" height="300"></canvas>
  4. <!--<div class="row">-->
  5. <!-- <canvas class="my-4" id="googleLineChart" width="900" height="300"></canvas>-->
  6. <!-- <canvas class="my-4" id="googlePieChart" width="900" height="300"></canvas>-->
  7. <!--</div>-->
  8. <div style="display: flex">
  9. <div id="bar-chart-container" style="position: relative; width: 70%;">
  10. <canvas id="googleLineChart" width="900" height="300"></canvas>
  11. </div>
  12. <div id="pie-chart-container" style="position: relative; width: 30%;">
  13. <canvas id="googlePieChart" width="200" height="150"></canvas>
  14. </div>
  15. </div>
  16. <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script>
  17. <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.3/Chart.bundle.min.js" integrity="sha256-TQq84xX6vkwR0Qs1qH5ADkP+MvH0W+9E7TdHJsoIQiM=" crossorigin="anonymous"></script>
  18. <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.1/Chart.min.js"></script>
  19. <script>
  20. var ctx = document.getElementById("myChart");
  21. var google_line_ctx = document.getElementById("googleLineChart");
  22. var google_pie_ctx = document.getElementById("googlePieChart");
  23. var location_id = document.getElementById("location_id").value;
  24. console.log(location_id.value)
  25. var endpoint = '/user/api/analytics/all-platform';
  26. params = {
  27. "location_id":location_id.trim()
  28. }
  29. console.log(params)
  30. $.ajax({
  31. type: "get",
  32. url: endpoint,
  33. data: params,
  34. dataType: 'json',
  35. success: function(data) {
  36. console.log(data)
  37. // All data together in a bar chart..
  38. var myBarChart = new Chart(ctx, {
  39. type: 'bar',
  40. data: {
  41. labels: data.google.labels,
  42. datasets: [
  43. {
  44. label: 'Google',
  45. data: data.google.total_review,
  46. borderColor: 'rgb(255, 204, 0)',
  47. backgroundColor: 'rgb(255, 204, 0)',
  48. borderWidth: 1,
  49. fill: false
  50. },
  51. {
  52. label: 'Facebook',
  53. data: data.facebook.total_review,
  54. borderColor: 'rgb(0, 51, 204)',
  55. backgroundColor: 'rgb(0, 51, 204)',
  56. borderWidth: 1,
  57. fill: false
  58. },
  59. {
  60. label: 'Yelp',
  61. data: data.yelp.total_review,
  62. borderColor: 'rgb(204, 51, 0)',
  63. backgroundColor: 'rgb(204, 51, 0)',
  64. borderWidth: 1,
  65. fill: false
  66. }]
  67. },
  68. options: {
  69. scales: {
  70. yAxes: [{
  71. ticks: {
  72. beginAtZero: true
  73. }
  74. }],
  75. xAxes: [{
  76. gridLines: {
  77. drawOnChartArea:false
  78. }
  79. }]
  80. },
  81. title: {
  82. display: true,
  83. fontSize: 16,
  84. text: "Review of this month in all platforms."
  85. }
  86. }
  87. });
  88. // Google review charts
  89. // Google line chart
  90. var myGoogleLineChart = new Chart(google_line_ctx, {
  91. type: 'line',
  92. data: {
  93. labels: data.google.labels,
  94. datasets: [
  95. {
  96. label: '1*',
  97. data: data.google.star_rating[0],
  98. borderColor: 'rgb(255, 204, 0)',
  99. backgroundColor: 'rgb(255, 204, 0)',
  100. borderWidth: 1,
  101. lineTension: 0,
  102. fill: false
  103. },
  104. {
  105. label: '2*',
  106. data: data.google.star_rating[1],
  107. borderColor: 'rgb(0, 51, 204)',
  108. backgroundColor: 'rgb(0, 51, 204)',
  109. borderWidth: 1,
  110. lineTension: 0,
  111. fill: false
  112. },
  113. {
  114. label: '3*',
  115. data: data.google.star_rating[2],
  116. borderColor: 'rgb(204, 51, 0)',
  117. backgroundColor: 'rgb(204, 51, 0)',
  118. borderWidth: 1,
  119. lineTension: 0,
  120. fill: false
  121. },
  122. {
  123. label: '4*',
  124. data: data.google.star_rating[3],
  125. borderColor: 'rgb(0, 51, 204)',
  126. backgroundColor: 'rgb(0, 51, 204)',
  127. borderWidth: 1,
  128. lineTension: 0,
  129. fill: false
  130. },
  131. {
  132. label: '5*',
  133. data: data.google.star_rating[4],
  134. borderColor: 'rgb(204, 51, 0)',
  135. backgroundColor: 'rgb(204, 51, 0)',
  136. borderWidth: 1,
  137. lineTension: 0,
  138. fill: false,
  139. }]
  140. },
  141. options: {
  142. borderJoinStyle: "bevel",
  143. scales: {
  144. yAxes: [{
  145. ticks: {
  146. beginAtZero: true
  147. }
  148. }],
  149. xAxes: [{
  150. gridLines: {
  151. drawOnChartArea:false
  152. }
  153. }]
  154. },
  155. title: {
  156. display: true,
  157. fontSize: 16,
  158. text: "Monthly review in Google."
  159. }
  160. }
  161. });
  162. // Google pie chart
  163. var myGooglePieChart = new Chart(google_pie_ctx, {
  164. type: 'pie',
  165. data: {
  166. labels: data.google.curr_month.label,
  167. datasets: [
  168. {
  169. data: data.google.curr_month.total,
  170. backgroundColor: [
  171. 'rgb(255, 99, 132)',
  172. 'rgb(255, 159, 64)',
  173. 'rgb(153, 102, 255)',
  174. 'rgb(54, 162, 235)',
  175. 'rgb(75, 192, 192)'
  176. ]
  177. }]
  178. },
  179. options: {
  180. title: {
  181. display: true,
  182. fontSize: 16,
  183. text: 'This is google reviews'
  184. }
  185. }
  186. });
  187. },
  188. error: function(error_data) {
  189. console.log(error_data);
  190. }
  191. });
  192. </script>
  193. {% endblock content %}