-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.php
executable file
·137 lines (107 loc) · 5.18 KB
/
index.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
133
134
135
136
137
<!doctype html>
<?php
// including FusionCharts PHP wrapper
require 'fusioncharts/fusioncharts.php';
// including PHP Library for MongoDB
require 'vendor\autoload.php';
$dbconn = new MongoDB\Client;
// validating DB connection
if(!$dbconn) {
exit("There was an error establishing database connection");
}
?>
<html>
<head>
<title>Creating Charts using PHP and MongoDB</title>
<!-- including FusionCharts core package JS files -->
<script src="fusioncharts/fusioncharts.js"></script>
<script src="fusioncharts/fusioncharts.theme.fint.js"></script>
</head>
<body>
<?php
// retrieving data from the database
$db = $dbconn->myProject;
$myObj = $db->chartData->find();
//convert MongoCursor into an array
$data=iterator_to_array($myObj);
// sorting the data
asort($data);
if ($data) {
$categoryArray=array();
$dataseries1=array();
$dataseries2=array();
foreach ($data as $dataset) {
array_push($categoryArray, array(
"label" => $dataset["month"]
));
array_push($dataseries1, array(
"value" => $dataset["petrol"]
));
array_push($dataseries2, array(
"value" => $dataset["diesel"]
));
}
$arrData = array(
"chart" => array(
"caption"=> "Comparison of Petrol and Diesel price",
"xAxisname"=>"Month",
"yAxisname"=>"Price",
"numberPrefix"=>"$",
"paletteColors"=> "#876EA1, #72D7B2",
"useplotgradientcolor"=> "0",
"plotBorderAlpha"=> "0",
"bgColor"=> "#FFFFFFF",
"canvasBgColor"=> "#FFFFFF",
"showCanvasBorder"=> "0",
"showBorder"=> "0",
"divLineAlpha"=> "40",
"divLineColor"=> "#DCDCDC",
"alternateHGridColor"=> "#DCDCDC",
"alternateHGridAlpha"=> "15",
"showValues"=> "0",
"labelDisplay"=> "auto",
"baseFont"=> "Assistant",
"baseFontColor"=> "#000000",
"outCnvBaseFont"=> "Assistant",
"outCnvBaseFontColor"=> "#000000",
"baseFontSize"=> "13",
"outCnvBaseFontSize"=> "13",
"labelFontColor"=> "#000000",
"captionFontColor"=> "#153957",
"captionFontBold"=> "1",
"captionFontSize"=> "20",
"subCaptionFontColor"=> "#153957",
"subCaptionfontSize"=> "17",
"subCaptionFontBold"=> "0",
"captionPadding"=> "20",
"valueFontBold"=> "0",
"showAxisLines"=> "1",
"yAxisLineColor"=> "#DCDCDC",
"xAxisLineColor"=> "#DCDCDC",
"xAxisLineAlpha"=> "15",
"yAxisLineAlpha"=> "15",
"toolTipPadding"=> "7",
"toolTipBorderColor"=> "#DCDCDC",
"toolTipBorderThickness"=> "0",
"toolTipBorderRadius"=> "2",
"showShadow"=> "0",
"toolTipBgColor"=> "#153957",
"toolTipBgAlpha"=> "90",
"toolTipColor"=> "#FFFFFF",
"legendBorderAlpha"=> "0",
"legendShadow"=> "0",
"legendItemFontSize"=> "14"
)
);
$arrData["categories"]=array(array("category"=>$categoryArray));
// creating dataset object
$arrData["dataset"] = array(array("seriesName"=> "Petrol_price", "data"=>$dataseries1), array("seriesName"=> "Diesel_price", "data"=>$dataseries2));
$jsonEncodedData = json_encode($arrData);
$msChart = new FusionCharts("msline", "demochart", "600", "400", "chart-container", "json", $jsonEncodedData);
// calling render method to render the chart
$msChart->render();
}
?>
<div id="chart-container">Fusion Charts will render here</div>
</body>
</html>