Advertisement
justhrun

highcharts_index.php

Sep 16th, 2014
278
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.89 KB | None | 0 0
  1. <?php
  2. $con = mysql_connect("localhost","root","");
  3. mysql_select_db("graph2", $con);
  4.  
  5. $result = mysql_query("select nama from kecamatan order by id_kec");
  6. while(list($nama) = mysql_fetch_row($result)) $kecamatan[] = "'$nama'";
  7. mysql_free_result($result);
  8.  
  9. $calon = array();
  10. $hasil = array();
  11. $i = 0;
  12. $result = mysql_query("select id_calon, nama_calon from calon order by id_calon");
  13. while(list($id,$nama) = mysql_fetch_row($result)) {
  14.     $calon[] = $nama;
  15.     $res = mysql_query("select suara from hasil where id_calon='$id' order by id_kec");
  16.     while(list($suara) = mysql_fetch_row($res)) { $hasil[$i][] = $suara; }
  17.     $i++;
  18.     mysql_free_result($res);
  19. }
  20. mysql_free_result($result);
  21. ?>
  22. <html><head>
  23. <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  24. <title>Pilkada 2022 - PHP</title>
  25. <META HTTP-EQUIV="Refresh" CONTENT="3000">
  26. <META HTTP-EQUIV="Pragma" CONTENT="no-cache">
  27. <META HTTP-EQUIV="Cache-Control" content="no-cache">
  28. <script type="text/javascript" src="js/jquery-1.9.1.min.js" ></script>
  29. <script type="text/javascript" src="js/highcharts.js" ></script>
  30. <script type="text/javascript" src="js/themes/gray.js"></script>
  31. <script type="text/javascript">
  32.         $(document).ready(function() {
  33.                 var options = {
  34.                         chart: {
  35.                                 renderTo: 'container',
  36.                                 defaultSeriesType: 'line',
  37.                                 marginRight: 130,
  38.                                 marginBottom: 25
  39.                         },
  40.                         title: {
  41.                                 text: 'Project Requests',
  42.                                 x: -20 //center
  43.                         },
  44.                         subtitle: {
  45.                                 text: '',
  46.                                 x: -20
  47.                         },
  48.                         xAxis: {
  49.                                 categories: [<?php echo join($kecamatan, ","); ?>]
  50.                         },
  51.                         yAxis: {
  52.                                 title: {
  53.                                         text: 'Hasil suara'
  54.                                 },
  55.                                 plotLines: [{
  56.                                         value: 0,
  57.                                         width: 1,
  58.                                         color: '#808080'
  59.                                 }]
  60.                         },
  61.                         tooltip: {
  62.                                 formatter: function() {
  63.                                                 return '<b>'+ this.series.name +'</b><br/>'+
  64.                                                 this.x +': '+ this.y;
  65.                                 }
  66.                         },
  67.                         legend: {
  68.                                 layout: 'vertical',
  69.                                 align: 'right',
  70.                                 verticalAlign: 'top',
  71.                                 x: -10,
  72.                                 y: 100,
  73.                                 borderWidth: 0
  74.                         },
  75.                         series: [<?php
  76.                                 $series = "";
  77.                                 for($i=0;$i<count($calon);$i++) {
  78.                                         $tab = $i ? "\t\t\t\t":"";
  79.                                         $series .= "$tab{name: '".$calon[$i]."', data: [". join($hasil[$i], ",") ."]},\n";
  80.                                 }
  81.                                 $series = substr($series,0,-2);
  82.                                 echo $series;
  83.                                 ?> ]
  84.  
  85.                 }
  86.                 setInterval(function() { getData(); }, 30000);    
  87.                 function getData(){ chart = new Highcharts.Chart(options); }
  88.         });
  89. </script>
  90. </head>
  91. <body>
  92. <div id="container" style="width: 100%; height: 400px; margin: 0 auto"></div>
  93. </body>
  94. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement