-
Notifications
You must be signed in to change notification settings - Fork 0
/
analysis.php
132 lines (132 loc) · 4.86 KB
/
analysis.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<div class="row">
<div class="col-md-10 mx-auto">
<div class="input-group mt-2 ml-3">
<div class="custom-control custom-radio mr-3">
<input type="radio" name="year" value="2019" id="2019" class="custom-control-input"/>
<label class='custom-control-label' for="2019">This year</label>
</div>
<div class="custom-control custom-radio mr-3">
<input type="radio" name="year" value="2018" id="2018" class="custom-control-input"/>
<label class='custom-control-label' for="2018">Last year</label>
</div>
<div class="custom-control custom-radio">
<input type="radio" name="year" value="all" id="all" class="custom-control-input"/>
<label class='custom-control-label' for="all">All time</label>
</div>
</div><hr>
<canvas id="usersChart" width="400" height="150"></canvas>
</div>
</div><hr>
<div class="row mx-2">
<div class="col-md-6">
<canvas id="questionsChart" width="180" height="150"></canvas>
</div>
<div class="col-md-6">
<canvas id="answersChart" width="180" height="150"></canvas>
</div>
</div>
<hr>
<script src="js/Chart.js"></script>
<script>
function sendRequest(year){
yr = year !== "" || year !== null ? year: "2019";
$.ajax({
url: "apis.php",
type: "POST",
data: {year: yr},
success: function(response){
json = JSON.parse(response);
var ctx = document.getElementById("usersChart").getContext('2d');
var myChart = new Chart(ctx, {
type: "line",
data: {
labels: json.labels,
datasets: [{
label: "Registered users for " + json.datasets.year,
data: json.datasets.users,
backgroundColor: "rgba(0, 0, 230, 0.3)",
fillColor: "rgba(10, 20, 230, 0.6)",
strokeColor: "rgba(120, 201, 255, 0.4)",
pointColor: "#00f",
pointStrokeColor: "#fff",
pointHighlightFill: "#fff",
pointHighlightStroke: "rgba(10,10,220, 0.4)",
borderColor: "rgba(25, 10, 255, 0.5)"
}]
}
});
var cts = document.getElementById("questionsChart").getContext('2d');
var lineChart = new Chart(cts, {
type: "line",
data: {
labels: json.labels,
datasets: [{
label: "All questions - " + json.datasets.year,
data: json.datasets.questions,
fillColor: "rgba(10, 230, 20, 0.6)",
strokeColor: "rgba(120, 201, 255, 0.4)",
pointColor: "#00f",
pointStrokeColor: "#fff",
pointHighlightFill: "#fff",
pointHighlightStroke: "rgba(10,10,220, 0.4)",
borderColor: "teal"
}]
}
});
var chart = document.getElementById("answersChart").getContext('2d');
var lineChart = new Chart(chart, {
type: "line",
data: {
labels: json.labels,
datasets: [{
label: "All answers - " + json.datasets.year,
data: json.datasets.answers,
fillColor: "rgba(10, 230, 20, 0.6)",
strokeColor: "rgba(120, 201, 255, 0.4)",
pointColor: "#00f",
pointStrokeColor: "#fff",
pointHighlightFill: "#fff",
pointHighlightStroke: "rgba(10,10,220, 0.4)",
borderColor: "orange"
}]
}
});
}
})
}
sendRequest("");
$("input:radio").each(function(){
$(this).on("input", function(){
var val = $(this).val();
sendRequest(val)
})
})
// var downvotesChart = new Chart(dvcharts, {
// type: 'bar',
// data: {
// labels: ["Upvotes", "Downvotes"],
// datasets: [{
// label: 'Answer Statistics',
// data: [upvotes2, downvotes2],
// backgroundColor: [
// 'red',
// '#ff5555'
// ],
// borderColor: [
// 'red',
// '#ff5555'
// ],
// borderWidth: 1
// }]
// },
// options: {
// scales: {
// yAxes: [{
// ticks: {
// beginAtZero:true
// }
// }]
// }
// }
// });
</script>