-
Notifications
You must be signed in to change notification settings - Fork 2
/
charts.html
147 lines (141 loc) · 3.87 KB
/
charts.html
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
<?php
include_once 'includes/dbh.inc.php';
$year = '2019';
$query = "SELECT * FROM complains where year ='".$year."';";
$t1n = "SELECT count(*) as c from complains where year ='".$year."' and type = 'murdur';";
$t2n = "SELECT count(*) as c from complains where year ='".$year."' and type = 'impersonation';";
$t3n = "SELECT count(*) as c from complains where year ='".$year."' and type = 'impersonation';";
$t4n = "SELECT count(*) as c from complains where year ='".$year."' and type = 'impersonation';";
$t5n = "SELECT count(*) as c from complains where year ='".$year."' and type = 'impersonation';";
$tq1n = mysqli_query($conn,$t1n);
$tq2n = mysqli_query($conn,$t2n);
$tq3n = mysqli_query($conn,$t3n);
$tq4n = mysqli_query($conn,$t4n);
$tq5n = mysqli_query($conn,$t5n);
echo $year;
$c1=0;
$c2=0;
$c3=0;
$c4=0;
$c5=0;
while($row= @mysqli_fetch_array($tq1n,MYSQL_ASSOC)){
$c1= $row['c'];
echo $year;
}
while($row= @mysqli_fetch_array($tq2n,MYSQL_ASSOC)){
$c2= $row['c'];
}
while($row= @mysqli_fetch_array($tq3n,MYSQL_ASSOC)){
$c3= $row['c'];
}
while($row= @mysqli_fetch_array($tq4n,MYSQL_ASSOC)){
$c4= $row['c'];
}
while($row= @mysqli_fetch_array($tq5n,MYSQL_ASSOC)){
$c5= $row['c'];
}
echo('
<!DOCTYPE HTML>
<html>
<head>
<link rel="stylesheet" type="text/css" href="stylesheets/charts.css"/>
<link rel="stylesheet" type="text/css" href="stylesheets/hover.css"/>
<link href="https://fonts.googleapis.com/css?family=Fira+Sans" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Oswald" rel="stylesheet">
<script>
function genChart(){
document.getElementsByClassName("selectopts")[0].style.display="none"
document.getElementById("chartContainer").style.display="block"
document.getElementById("barchartContainer").style.display="block"
let data=[{ y: 22, label: "Bribe" },
{ y: 10, label: "Loot" },
{ y: 8, label: "Murder" },
{ y: 10, label: "Manslaughter" },
{ y: 30, label: "Killing" },
{ y: 10, label: "Shooting" },
{ y: 10, label: "Others" }];
let datapoints=[];
let datapoints2=[];
datapoints2=data;
let total=0;
for(let i=0;i<data.length;i++){
total+=data[i].y
}
for(let i=0;i<data.length;i++){
datapoints.push({y:data[i].y/total*100,label:data[i].label})
}
var chart = new CanvasJS.Chart("chartContainer", {
theme: "light2", // "light1", "light2", "dark1", "dark2"
exportEnabled: true,
animationEnabled: true,
title: {
text: "Heading"
},
data: [{
type: "pie",
startAngle: 25,
toolTipContent: "<b>{label}</b>: {y}%",
showInLegend: "true",
legendText: "{label}",
indexLabelFontSize: 16,
indexLabel: "{label} - {y}%",
dataPoints: datapoints
}]
});
chart.render();
var barchart = new CanvasJS.Chart("barchartContainer", {
animationEnabled: true,
theme: "light2", // "light1", "light2", "dark1", "dark2"
title:{
text: "Electoral crimes"
},
axisY: {
title: "Number of crimes"
},
data: [{
type: "column",
showInLegend: true,
legendMarkerColor: "grey",
legendText: "Number of crimes",
dataPoints: datapoints2
}]
});
barchart.render();
}
</script>
</head>
<body>
<nav class="navabar">
<div class="logo">
<img class="logopic" src="img/votesafelogo.png">
</div>
<ul class="butlist">
<span class="butres">
<li class="hvr-glow">
<a href="">ABOUT</a>
</li>
<li class="hvr-glow">
<a href="">NEWSFEED</a>
</li>
</span>
</ul>
</nav>
<div class="main">
<span class="selectopts">
<span class="dropdown">
<select class="selyr">
<option class="yropt" value="2019">2019</option>
<option class="yropt" value="2018">2018</option>
<option class="yropt" value="2017">2017</option>
</select>
</span>
<span class="getbut">
<button id="generate_chart" onclick="genChart();return;">Get charts</button>
</span>
</span>
<div id="chartContainer" style="height: 400px;"></div>
<div id="barchartContainer" style="height: 400px;"></div>
</div>
<script src="https://canvasjs.com/assets/script/canvasjs.min.js"></script>
</body>
</html>