-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDashboard_7.php
More file actions
150 lines (134 loc) · 4.69 KB
/
Dashboard_7.php
File metadata and controls
150 lines (134 loc) · 4.69 KB
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
148
149
150
<html>
<head>
<link rel="stylesheet" href="./CSS/Sidebar.css">
<link rel="stylesheet" href="./CSS/MainBody.css">
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<script src="https://cdn.jsdelivr.net/npm/chartjs-plugin-zoom@1.2.1/dist/chartjs-plugin-zoom.min.js"></script>
<style>
.slider {
accent-color: purple;
width: 300px;
}
.controls {
margin-top: 20px;
}
</style>
</head>
<body>
<?php
include('./DBConnection.php');
$query = $conn->query("SELECT topic, intensity FROM data");
$topics = [];
foreach ($query as $data) {
$topics[] = $data['topic'];
$intensity[] = $data['intensity'];
}
$uniqueTopics = array_unique($topics);
sort($uniqueTopics);
?>
<div id="mySidenav" class="sidenav">
<a href="javascript:void(0)" class="closebtn" onclick="closeNav()">×</a>
<a href="./index.php">Intensity Over Years [Line Chart]</a>
<a href="./Dashboard_2.php">Likelihood Over Years [Line Chart]</a>
<a href="./Dashboard_3.php">Relevance Over Years [Line Chart]</a>
<a href="./Dashboard_4.php">Intensity Over Country [Bar Chart]</a>
<a href="./Dashboard_5.php">Likelihood Over Country [Bar Chart]</a>
<a href="./Dashboard_6.php">Relevance Over Country [Bar Chart]</a>
<a href="./Dashboard_7.php">Distribution of Topics [Pie Chart]</a>
<a href="./Dashboard_8.php">Distribution of Ssector [Pie Chart]</a>
<a href="./Dashboard_9.php">Intensity VS Likelihood [Scatter Chart]</a>
</div>
<span style="font-size:30px;cursor:pointer" onclick="openNav()">☰ Nitish Project</span>
<br><br>
<center>
<div id="d1">
<div class="filter">
<b><label style="font-family: 'Lato', sans-serif; background-color: #F5F6FA;">Filters</label></b>
<div class="custom-select">
<select id="start">
<option>Select Start Topic</option>
<?php foreach ($uniqueTopics as $c): ?>
<option value="<?php echo $c; ?>"><?php echo $c; ?></option>
<?php endforeach; ?>
</select>
<select id="end">
<option>Select End Topic</option>
<?php foreach ($uniqueTopics as $c): ?>
<option value="<?php echo $c; ?>"><?php echo $c; ?></option>
<?php endforeach; ?>
</select>
</div>
<button onclick="applyFilter()" class="btncss">Apply Filter</button>
</div>
<br>
<div id="page1" style="width: 1200px; height: 500px;">
<canvas id="myChart"></canvas>
</div>
</div>
</center>
<script>
var labels = <?php echo json_encode($uniqueTopics); ?>;
var data = <?php echo json_encode($intensity); ?>;
function openNav() {
document.getElementById("mySidenav").style.width = "250px";
}
function closeNav() {
document.getElementById("mySidenav").style.width = "0";
}
const ctx = document.getElementById('myChart').getContext('2d');
let chart = new Chart(ctx, {
type: 'pie',
data: {
labels: labels,
datasets: [{
label: 'Distribution of Topics Over Intensity',
data: data,
backgroundColor: [
'rgb(255, 99, 132)',
'rgb(54, 162, 235)',
'rgb(255, 205, 86)',
'rgb(75, 192, 192)',
'rgb(153, 102, 255)',
'rgb(255, 159, 64)'
],
hoverOffset: 4
}]
},
options: {
responsive: true,
plugins: {
zoom: {
pan: {
enabled: true,
mode: 'x'
},
zoom: {
enabled: true,
mode: 'x'
}
}
}
}
});
function applyFilter() {
const start = document.getElementById('start').value.trim();
const end = document.getElementById('end').value.trim();
if (start === "" || end === "") {
alert('Please select both start topic and end topic.');
return;
}
const filteredLabels = [];
const filteredData = [];
for (let i = 0; i < labels.length; i++) {
if (labels[i] >= start && labels[i] <= end) {
filteredLabels.push(labels[i]);
filteredData.push(data[i]);
}
}
chart.data.labels = filteredLabels;
chart.data.datasets[0].data = filteredData;
chart.update();
}
</script>
</body>
</html>