-
Notifications
You must be signed in to change notification settings - Fork 0
/
offer_report.php
72 lines (56 loc) · 2.1 KB
/
offer_report.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
<!doctype html>
<html>
<head>
<title>Offer Report</title>
<link href="css/reports.css" type="text/css" rel="stylesheet">
</head>
<body >
<a href="product_report.php"><button class="btn" name="add">Product Reports</button></a>
<?Php
require "config.php";// Database connection
if($stmt = mysqli_query($conn,("SELECT offer_name, sales FROM offer_report"))){
echo "No of records : ". mysqli_num_rows($stmt) ."<br>";
$php_data_array = Array(); // create PHP array
echo "<table>
<tr> <th>Offer</th><th>Sales</th></tr>";
while ($row = mysqli_fetch_row($stmt)) {
echo "<tr><td>$row[0]</td><td>$row[1]</td></tr>";
$php_data_array[] = $row; // Adding to array
}
echo "</table>";
}else{
echo "somethimg went wrong" . mysqli_error();
}
echo "<script>
var my_2d = ".json_encode($php_data_array)."
</script>";
?>
<div id="chart_div"></div>
<br><br>
<div style="position:relative;width:100%">
<div id="chart_div" style="position:absolute;right:0px;top:100px;width: 400px; height: 300px;"></div>
</div>
</body>
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script>
google.charts.load('current', {'packages':['corechart']});
// Draw the pie chart when Charts is loaded.
google.charts.setOnLoadCallback(draw_my_chart);
// Callback that draws the pie chart
function draw_my_chart() {
// Create the data table .
var data = new google.visualization.DataTable();
data.addColumn('string', 'offer_name');
data.addColumn('number', 'sales');
for(i = 0; i < my_2d.length; i++)
data.addRow([my_2d[i][0], parseInt(my_2d[i][1])]);
// above row adds the JavaScript two dimensional array data into required chart format
var options = {title:'Offers Performance of the month',
width:600,
height:500};
// Instantiate and draw the chart
var chart = new google.visualization.PieChart(document.getElementById('chart_div'));
chart.draw(data, options);
}
</script>
</html>