diff --git a/graphs/graphFunctions.php b/graphs/graphFunctions.php index 0c1ebb853b1b290afa91ed9d249f5d4a5f651cac..c2e603da1b43ec59dbadf10b018c9554020e6db3 100644 --- a/graphs/graphFunctions.php +++ b/graphs/graphFunctions.php @@ -1,7 +1,7 @@ <?php /* Include the `fusioncharts.php` file that contains functions to embed the charts. */ include("fusioncharts-suite-xt/integrations/php/fusioncharts-wrapper/fusioncharts.php"); - +require_once('../API_Twitter/userInfosFunctions.php'); /** * Must have included the JS */ @@ -26,7 +26,7 @@ function lineGraphMean($chartName, $caption, $xAxisName, $yAxisName, $data, $wid $count = count($data); for ($i=0; $i<$count; $i++) { $arrChartData[] = [ - 'label' => $i, + 'label' => $i, 'value' => $data[$i] ]; $mean += $data[$i]; @@ -44,7 +44,7 @@ function lineGraphMean($chartName, $caption, $xAxisName, $yAxisName, $data, $wid "valueOnRight" => "1", "thickness" => "2" ] - ] + ] ]; $arrChartConfig["data"] = $arrChartData; @@ -61,6 +61,48 @@ function lineGraphMean($chartName, $caption, $xAxisName, $yAxisName, $data, $wid echo '<center> <div id="'.$chartName.'">Chart will render here!</div> </center>'; } +function diagramme($favt){ + echo ' + <script type="text/javascript" src="https://cdn.fusioncharts.com/fusioncharts/latest/fusioncharts.js"></script> + <script type="text/javascript" src="https://cdn.fusioncharts.com/fusioncharts/latest/themes/fusioncharts.theme.fusion.js"></script> + <script type="text/javascript"> + FusionCharts.ready(function(){ + var fusioncharts = new FusionCharts({ + type: "bar2d", + renderAt: "diagtwitter", + width: "500", + height: "400", + dataFormat: "json", + dataSource: { + "chart": { + "theme": "fusion", + "caption": "Les meilleurs favoris", + "subCaption": "Twitter", + "yAxisName": "Nombre de followers", + "numberPrefix": "$", + "alignCaptionWithCanvas": "0" + }, + + "data": [' ; + for( $i=0 ; $i < count($favt)-2 ; $i++){ + $name = getUserScreenName($favt[$i]); + $followers = getUserNbFollowers($favt[$i]); + echo ' { + "label": "'.$name.'", + "value": "'.$followers.'" + },'; + } + $name = getUserScreenName($favt[count($favt)-1]); + $followers = getUserNbFollowers($favt[count($favt)-1]); + echo '{ + "label": "'.$name.'", + "value": "'.$followers.'" + }] + } + })}); + fusioncharts.render(); + </script>' ; +} ?> diff --git a/page_user/user.php b/page_user/user.php index da7d1be07e386824d02c1f4f0c1ac78bc3df0f02..2f172f191aa707507779c643acc3f0cfbff034ff 100644 --- a/page_user/user.php +++ b/page_user/user.php @@ -1,12 +1,17 @@ <?php require_once('../facto.php'); require_once('../API_Twitter/userInfosFunctions.php'); +require_once('../graphs/graphFunctions.php'); session_start(); + +ini_set('display_errors', 1); +ini_set('display_startup_errors', 1); +error_reporting(E_ALL); ?> <!DOCTYPE html> -<html lang="zxx"> +<html> <?php head(); ?> @@ -23,12 +28,9 @@ session_start(); <div class="slider-info bg1"> <div class="w3l-overlay"> <div class="banner-text text-center container"> - <table width="400" class="hovertable" align="center" style='text-align:center;background: white' border='1'> - <tr style="background: #3fcbfe;"><th>image</th><th>twitter</th></tr> - <?php - session_start(); + <?php // initializing variables $username = $_SESSION['username']; @@ -50,7 +52,63 @@ session_start(); $result = mysqli_query($db, $fav); $fav = mysqli_fetch_assoc($result); $favt = unserialize($fav['twitter']); + ?> + + + <?php echo '<script type="text/javascript" src="https://cdn.fusioncharts.com/fusioncharts/latest/fusioncharts.js"></script> +<script type="text/javascript" src="https://cdn.fusioncharts.com/fusioncharts/latest/themes/fusioncharts.theme.fusion.js"></script> +<script type="text/javascript"> + FusionCharts.ready(function(){ + var fusioncharts = new FusionCharts({ + type: "bar2d", + renderAt: "diagtwitter", + width: "500", + height: "400", + dataFormat: "json", + dataSource: { + "chart": { + "theme": "fusion", + "caption": "Top 5 Stores by Sales", + "subCaption": "Last month", + "yAxisName": "Sales (In USD)", + "numberPrefix": "$", + "alignCaptionWithCanvas": "0" + }, + + "data": [{ + "label": "Bakersfield Central", + "value": "880000" + }, '; + + for( $i=0 ; $i < min(10,count($favt)-2) ; $i++){ + $name = getUserScreenName($favt[$i]); + $followers = getUserNbFollowers($favt[$i]); + echo ' { + "label": "'.$name.'", + "value": "'.$followers.'" + },'; + } + + $name = getUserScreenName($favt[count($favt)-1]); + $followers = getUserNbFollowers($favt[count($favt)-1]); + echo '{ + "label": "'.$name.'", + "value": "'.$followers.'" + } + ] + } +}); + fusioncharts.render(); + }); +</script>'; +?> + <div id="diagtwitter">Le diagramme twitter s affiche ici ! + </div> + + <table width="400" class="hovertable" align="center" style='text-align:center;background: white' border='1'> + <tr style="background: #3fcbfe;"><th>image</th><th>twitter</th></tr> + <?php $datarow = count($favt); for($i=0;$i<$datarow;$i++){ $twitter = getUserScreenName($favt[$i]);