123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- {% extends 'analytics.html' %}
- <script>
- {% block jquery %}
- var location_id = document.getElementById("location").value;
- var time_interval = document.getElementById("timeInterval").value;
- var endpoint = '/analytics/analytic-data';
- params = {
- "location_id": location_id,
- "time_interval": time_interval
- }
- $.ajax({
- type: "get",
- url: endpoint,
- data: params,
- dataType: 'json',
- success: function(data) {
- $('#barChart').remove();
- $('#bar-chart-container').append('<canvas id="barChart" width="400" height="100" class="mt-2"></canvas>');
- $('#lineChart').remove();
- $('#line-chart-container').append('<canvas id="lineChart" width="400" height="100" class="mt-2"></canvas>');
- var ctx = document.getElementById('lineChart').getContext('2d');
- var ctxBar = document.getElementById('barChart').getContext('2d');
- var myLineChart = new Chart(ctx, {
- type: 'line',
- data: {
- labels: data.label,
- datasets: [
- {
- label: '5 Star',
- data: data.five_star,
- borderColor: 'rgb(75, 192, 192)',
- backgroundColor: 'rgb(75, 192, 192)',
- borderWidth: 3,
- fill: false
- },
- {
- label: '4 Star',
- data: data.four_star,
- borderColor: 'rgb(54, 162, 235)',
- backgroundColor: 'rgb(54, 162, 235)',
- borderWidth: 3,
- fill: false
- },
- {
- label: '3 Star',
- data: data.three_star,
- borderColor: 'rgb(153, 102, 255)',
- backgroundColor: 'rgb(153, 102, 255)',
- borderWidth: 3,
- fill: false
- },
- {
- label: '2 Star',
- data: data.two_star,
- borderColor: 'rgb(255, 159, 64)',
- backgroundColor: 'rgb(255, 159, 64)',
- borderWidth: 3,
- fill: false
- },
- {
- label: '1 Star',
- data: data.one_star,
- borderColor: 'rgb(255, 99, 132)',
- backgroundColor: 'rgb(255, 99, 132)',
- borderWidth: 3,
- fill: false
- },
- ]
- },
- options: {
- scales: {
- xAxes: [{
- gridLines: {
- drawOnChartArea:false
- }
- }],
- yAxes: [{
- ticks: {
- beginAtZero: true
- }
- }]
- }
- }
- });
- var myBarChart = new Chart(ctxBar, {
- type: 'bar',
- data: {
- labels: data.label,
- datasets: [
- {
- label: 'All Reviews',
- data: data.total_reviews,
- borderColor: 'rgb(75, 192, 192)',
- backgroundColor: 'rgb(75, 192, 192)',
- borderWidth: 3,
- fill: false
- }]
- },
- options: {
- scales: {
- yAxes: [{
- ticks: {
- beginAtZero: true
- }
- }],
- xAxes: [{
- gridLines: {
- drawOnChartArea:false
- }
- }]
- }
- }
- });
- },
- error: function(error_data) {
- console.log(error_data);
- }
- });
- {% endblock jquery %}
- </script>
|