1 <html>
 2   <head>
 3     <title>Legal acts by author</title>
 4     <script type="text/javascript" src="https://www.google.com/jsapi"></script>
 5     <script type="text/javascript">
 6       google.load("visualization", "1", {packages:["corechart"]});
 7       google.setOnLoadCallback(drawChart);
 8       function drawChart() {
 9         var data = new google.visualization.DataTable(),
10         chart = new google.visualization.PieChart(document.getElementById('chart_div'));
11         data.addColumn('string', 'Author');
12         data.addColumn('number', 'Number of acts');
13 <?php
14 
15 function loadData($url) {
16   $data = json_decode(file_get_contents($url));
17   $i = 0;
18   $out = '';
19   $others = 0;
20   foreach($data as $item) {
21     if ($item->number_of_documents < 500) { //we group authors with less than 500 acts together
22       $others += $item->number_of_documents;
23     } else {
24       $out .= "        data.setValue($i, 0, '".addslashes($item->author)."');\n";
25       $out .= "        data.setValue($i, 1, ".$item->number_of_documents.");\n";
26       $i++;
27     }
28   }
29   $out .= "        data.setValue($i, 0, 'Other authors');\n";
30   $out .= "        data.setValue($i, 1, ".$others.");\n";
31   $i++;
32   echo "        data.addRows(".$i.");\n";
33   echo $out;
34 }
35 
36 $url = 'http://api.epdb.eu/eurlex/author/?key=YOUR_API_KEY';
37 loadData($url);
38 
39 ?>
40         chart.draw(data, {width: 900, height: 400, title: 'Legal acts by author'});
41       }
42     </script>
43     <style type="text/css">
44       body { background-color:#193F4F; text-align:center;font-family: 'Lucida Grande', 'Lucida Sans Unicode', Arial, Verdana, sans-serif; font-size: 15px }
45       a {color:#fff; }
46       #chart_div { background-color:#fff;color:#333;}
47       #container { background-color:#fff;padding:10px; }
48       #content { width: 920px;margin-left:auto;margin-right:auto; }
49     </style>
50   </head>
51   <body>
52     <div id='content'>
53       <div id='container'>
54         <div id='chart_div' style='width:900px;height:400px;'></div>
55       </div>
56     </div>
57     <div style="color:#fff;margin-top:40px;">
58       This example uses the <a href="http://code.google.com/apis/chart/">Google Chart Tools</a>.<br />
59       Data is taken from the <a href="http://api.epdb.eu">API for European Union legislation</a> by <a href="http://www.buhlrasmussen.eu">Buhl & Rasmussen</a> 2011.
60       The original data source is <a href="http://eur-lex.europa.eu/">EUR-Lex</a>.<br />
61       You can see the <a href="example01.php.html">PHP source-code</a> used to generate this example, and
62       you can find more <a href="/#examples">examples here</a>.
63     </div>
64   </body>
65 </html>