Posted in PHP
series: [{ name: 'Visitor', data: [ <?php foreach($ga->getResults() as $result): echo $result->getVisits().','; endforeach; ?> ] } ] }Hasil akhir ketika ditampilkan di browser kurang lebih seperti ini: [caption id="" align="aligncenter" width="409"] Total Visitor by Browser[/caption] Berikut ini adalah source code lengkapnya:
<?php define('ga_email','email'); define('ga_password','password'); define('ga_profile_id', 'id_profile'); require 'gapi.class.php'; $ga = new gapi(ga_email,ga_password); $filter = 'ga:pagePath==~/category/java/'; $ga->requestReportData(ga_profile_id,array('browser'),array('visits'),'-visits',$filter); ?> <!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Visitor by Browser</title> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script> <script type="text/javascript"> $(function () { var chart; $(document).ready(function() { chart = new Highcharts.Chart({ chart: { renderTo: 'container', type: 'bar' }, title: { text: 'Visitor by Browser' }, xAxis: { categories: [ <?php foreach($ga->getResults() as $result): echo "'".$result."',"; endforeach; ?> ] }, yAxis: { min: 0, title: { text: 'Total Visitor by Browser' } }, legend: { backgroundColor: '#FFFFFF', reversed: true }, tooltip: { formatter: function() { return ''+ this.series.name +': '+ this.y +''; } }, plotOptions: { series: { stacking: 'normal' } }, series: [{ name: 'Visitor', data: [ <?php foreach($ga->getResults() as $result): echo $result->getVisits().','; endforeach; ?> ] } ] }); }); }); </script> </head> <body> <script src="http://code.highcharts.com/highcharts.js"></script> <script src="http://code.highcharts.com/modules/exporting.js"></script> <div id="container" style="width: 400px; height: 400px; margin: 0 auto"></div> </body> </html>Semoga bermanfaat