Fixing Google Geo chart PHP + MYSQLi or XML parser complete tutorials

Fixing Google Geo chart PHP + MYSQLi or XML parser complete tutorials


Please Subscribe my Chanel on Youtube:


google geo chart

Mysqltable is bellow:

google chart mysql


<?php $con = mysqli_connect('localhost','root','','test') or Die(); ?>
   <script type="text/javascript" src=""></script>
  <script type="text/javascript">
      google.load("visualization", "1", {packages:["geochart"]});

      function drawRegionsMap() {

        var data = google.visualization.arrayToDataTable([

          ['Country', 'Visits'],
           <?php $query = "SELECT count(ip) AS count, country FROM visitors GROUP BY country"; $exec = mysqli_query($con,$query); while($row = mysqli_fetch_array($exec)){ echo "['".$row['country']."',".$row['count']."],"; } ?>

        var options = {

        var chart = new google.visualization.GeoChart(document.getElementById('geochartsatu'));

        chart.draw(data, options);


<h3>Geo Chart</h3>

<div id="geochartsatu" style="width: 900px; height: 500px;"></div>



Google chart + php + mysql lanjutan 2

Tutorial google chart untuk php dan mysql

<?php /* Script : PHP-JSON-MySQLi-GoogleChart Author : Enam Hossain version : 1.0 */ /* -------------------------------------------------------------------- Usage: -------------------------------------------------------------------- Requirements: PHP, Apache and MySQL Installation: --- Create a database by using phpMyAdmin and name it "chart" --- Create a table by using phpMyAdmin and name it "googlechart" and make sure table has only two columns as I have used two columns. However, you can use more than 2 columns if you like but you have to change the code a little bit for that --- Specify column names as follows: "weekly_task" and "percentage" --- Insert some data into the table --- For the percentage column only use a number --------------------------------- example data: Table (googlechart) --------------------------------- weekly_task percentage ----------- ---------- Sleep 30 Watching Movie 10 job 40 Exercise 20 */ /* Establish the database connection */ // $mysqli = new mysqli_connect('', 'root', 'root', 'test'); /* if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); exit(); } */ $mysqli =mysqli_connect('localhost', 'root', '', 'rumahsakit'); if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: ".mysqli_connect_error(); } /* select all the weekly tasks from the table googlechart */ $result = $mysqli->query(' SELECT tgldaftar, COUNT( * ) AS count, SUM( 100 ) / total AS percentage
FROM t_pasien CROSS JOIN (
SELECT COUNT( * ) AS total
FROM t_pasien ) x GROUP BY MONTH( tgldaftar )

      example data: Table (googlechart)
      Weekly_Task     percentage
      Sleep           30
      Watching Movie  10
      job             40
      Exercise        20

  $rows = array();
  $table = array();
  $table['cols'] = array(

    // Labels for your chart, these represent the column titles.
        note that one column is in "string" format and another one is in "number" format
        as pie chart only required "numbers" for calculating percentage
        and string will be used for Slice title
    array('label' => 'tgldaftar', 'type' => 'string'),
    array('label' => 'percentage', 'type' => 'number')

    /* Extract the information from $result */
    foreach($result as $r) {

      $temp = array();

      // The following line will be used to slice the Pie chart

      $temp[] = array('v' => (string) $r['tgldaftar']); 

      // Values of the each slice

      $temp[] = array('v' => (int) $r['percentage']);
      $rows[] = array('c' => $temp);

$table['rows'] = $rows;

// convert data into JSON format
$jsonTable = json_encode($table);
//echo $jsonTable;


    <!--Load the Ajax API-->
    <script type="text/javascript" src=""></script>
    <script type="text/javascript" src=""></script>
    <script type="text/javascript">

    // Load the Visualization API and the piechart package.
    google.load('visualization', '1', {'packages':['corechart']});

    // Set a callback to run when the Google Visualization API is loaded.

    function drawChart() {

      // Create our data table out of JSON data loaded from server.
      var data = new google.visualization.DataTable(<?=$jsonTable?>);
      var options = {
           title: 'jumlah Pasien berdasarkan Periode Bulan',
        //  is3D: 'true',
          width: 550,
          height: 400,
          pieHole: 0.4,
      // Instantiate and draw our chart, passing in some options.
      // Do not forget to check your div ID
      var chart = new google.visualization.PieChart(document.getElementById('donutchart'));
      chart.draw(data, options);

    <!--this is the div that will hold the pie chart-->

<div id="donutchart"></div>