Advertisement
cdsatrian

chart

Oct 7th, 2013
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.10 KB | None | 0 0
  1. <!DOCTYPE HTML>
  2. <html>
  3.   <head>
  4.     <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  5.     <title>Highcharts Example</title>
  6.   </head>
  7.   <body>
  8.     <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
  9.     <?php  
  10.     include "koneksi.php";
  11.     $sql="SELECT nama_band,vote
  12.          FROM tb_voting2 GROUP BY nama_band";
  13.     $result=mysql_query($sql);
  14.     $series=array();
  15.     $total=0;
  16.     while($record=mysql_fetch_array($sql)){
  17.       $total+=$record['vote'];
  18.       $series[]="{name:'".$record['nama_band']."',data:[".$record['vote']."]}";
  19.     }
  20.     ?>
  21.     <script type="text/javascript">
  22.     $(function () {
  23.       $('#container').highcharts(
  24.       {
  25.         chart: {
  26.           type: 'column'
  27.         },
  28.         title: {
  29.           text: 'Total Vote'
  30.         },
  31.         xAxis: {
  32.           categories: ['nama band'],
  33.           labels: {
  34.            align: 'right',
  35.             style: {
  36.                 fontSize: '13px',
  37.                 fontFamily: 'Verdana, sans-serif'
  38.             }
  39.           }
  40.         },
  41.         yAxis: {
  42.           title: {
  43.             text: 'Votes'
  44.           }
  45.         },
  46.         legend: {
  47.           enabled: true
  48.         },
  49.         tooltip: {
  50.           formatter: function() {
  51.             var point = this.point,
  52.               s = this.series.name +':<b>'+ this.y +' vote</b><br/>';
  53.             return s;
  54.           }
  55.         },
  56.         plotOptions: {
  57.           column: {
  58.             cursor: 'pointer',
  59.             pointPadding: 0.2,
  60.             borderWidth: 0,
  61.             dataLabels: {
  62.               enabled: true,
  63.               formatter: function() {
  64.                 return this.series.name +'='+ (this.y/100).toFixed(2) +' %';
  65.               }
  66.             }
  67.           }
  68.         },        
  69.       series: [<?php echo implode(',',$series);?>]
  70.       });
  71.     });    
  72.     </script>
  73.     <script src="js/highcharts.js"></script>
  74.     <script src="js/modules/exporting.js"></script>
  75.     <div id="container" style="min-width: 310px; height: 750px; margin: 0 auto"></div>
  76.   </body>
  77. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement