Google Chart + Php + Mysql Geolocation

Indonesia geo chart
indonesia geo
geo

google.load(‘visualization’, ‘1’, {‘packages’: [‘geochart’]});
google.setOnLoadCallback(drawVisualization);

function drawVisualization() {var data = new google.visualization.DataTable();

data.addColumn(‘string’, ‘Country’);
data.addColumn(‘number’, ‘Value’);
data.addColumn({type:’string’, role:’tooltip’});var ivalue = new Array();

//data.addRows([[{v:’ID’,f:’ID’},1000,’Test’]]);

data.addRows(

[

[{v:’Sumatera Utara’,f:’ID’},21,’Sumut’],
[{v:’Sumatera Barat’,f:’ID’},50,’Sumbar’],
[{v:’Sumatera Selatan’,f:’ID’},50,’Sumsel’],
[{v:’Jawa Barat’,f:’ID’},23,’Jabar’],
[{v:’Kalimantan Timur’,f:’ID’},23,’Kaltim’],
[{v:’Bali’,f:’ID’},34,’Bali’],
[{v:’Sulawesi Selatan’,f:’ID’},39,’Sulsel’],
[{v:’Bengkulu’,f:’ID’},87,’Bengkulu’],
[{v:’Jawa Tengah’,f:’ID’},376,’Jateng’],
[{v:’Jawa Timur’,f:’ID’},34,’Jatim’] ,
[{v:’Sulawesi Barat’,f:’ID’},34, ‘sulbar’],
[{v:’Kalimantan Barat’,f:’ID’},21,’Kalbar’],
[{v:’Papua’,f:’ID’},21,’papua’],
[{v:’Maluku Utara’,f:’ID’},1,’maluku utara’],

]);

var options = {
backgroundColor: {fill:’#FFFFFF’,stroke:’#FFFFFF’ ,strokeWidth:0 },
colorAxis: {minValue: 0, maxValue: 0, colors: [ ‘#D64513’,]},
legend: ‘none’,
backgroundColor: {fill:’#FFFFFF’,stroke:’#FFFFFF’ ,strokeWidth:0 },
datalessRegionColor: ‘#f5f5f5’,
displayMode: ‘regions’,
enableRegionInteractivity: ‘true’,
resolution: ‘provinces’,
region:’ID’,
keepAspectRatio: true,
width:600,
height:600,
tooltip: {textStyle: {color: ‘#444444′}, trigger:’focus’}
};
var chart = new google.visualization.GeoChart(document.getElementById(‘visualization’));
chart.draw(data, options);
}

Pak Teguh Website

Advertisements

line chart from google chart

line
berbagi sorce code line chart php + mysql [google chart]


<?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('127.0.0.1:3306', '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 * FROM widget_prices
       ');

  /*
      ---------------------------
      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' => 'week', 'type' => 'string'),
    array('label' => 'price', '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['week']); 

      // Values of the each slice

      $temp[] = array('v' => (int) $r['price']); 
      $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="https://www.google.com/jsapi"></script>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></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.
    google.setOnLoadCallback(drawChart);

    function drawChart() {

      // Create our data table out of JSON data loaded from server.
      var data = new google.visualization.DataTable(<?=$jsonTable?>);
      var options = {
           title: 'Analisa Penggunaan Kamar',
           hAxis: {title: 'Minggu ke-', titleTextStyle: {color: 'blue'}},
          is3D: 'true',
          width: 550,
          height: 400
        };
      // Instantiate and draw our chart, passing in some options.
      // Do not forget to check your div ID
      var chart = new google.visualization.LineChart(document.getElementById('chart_line'));
      chart.draw(data, options);
    }
    </script>
 


    <!--this is the div that will hold the pie chart-->
    <div id="chart_line"></div>

tutorial 3: sql

query with operator

SELECT firstName + '  ' + lastName AS [full name]
FROM memberDetails
WHERE city='yogyakarta';
SELECT filmName
FROM films
WHERE yearReleased <= 1990;

operator AND

SELECT filmName, lastName, street, city, state, zipCode
FROM memberDetails
WHERE dateOfJoining >= '2004-01-01' AND dateOfJoining <= '2005-03-01';
SELECT firstName, lastName
FROM memberDetails
WHERE dateOfBirth <= '1990-05-05' AND state='jakarta';

operator OR

SELECT state, dateOfJoining
FROM memberDetails
WHERE state='new state' OR state='golden state'
AND dateOfJoining >= '2005-01-01';

 

SELECT firstName, lastName, city, DateofBirth
FROM memberDetails
WHERE (city = 'Townsite' OR city='bigcity')
AND
      (DateofBirth >= '1989-05-29' OR DateofBirth <= '1945-08-17');

operator NOT

SELECT firstName
FROM memberDetails
WHERE NOT STATE='golden state';

operator BETWEEN

SELECT filmName, yearReleased, Rating, AvailableonDVD
FROM Films
WHERE (Rating BETWEEN 2 AND 4)
AND
      (AvailableonDVD = 'y');

operator LIKE

SELECT lastName
FROM memberDetails
WHERE lastName LIKE 'J%';

 

SELECT lastName
FROM memberDetails
WHERE lastName LIKE 'D_s';
SELECT lastName
FROM memberDetails
WHERE lastName NOT LIKE 'J%';

operatot IN

SELECT filmName, yearReleased, Rating
FROM Films
WHERE yearReleased in (1967,1977,1987)
AND
RATING in (4,5);

operator ORDER BY

SELECT yearReleased
FROM Films
ORDER BY yearReleased DESC;

Tutorial 2: sql

create table with referential integrity

create table barang

CREATE TABLE barang (
kd_brg varchar(4) NOT NULL,
nm_brg varchar(25) NOT NULL,
harga_beli double NOT NULL,
harga_jual double NOT NULL,
stok double NOT NULL,
PRIMARY KEY (kd_brg))
ENGINE=MYISAM;

create table pembelian_detil

CREATE TABLE pembelian_detil (
no_beli varchar(4) NOT NULL,
kd_brg varchar(4) NOT NULL,
harga_beli double NOT NULL,
jumlah double NOT NULL,
PRIMARY KEY (no_beli, kd_brg))
ENGINE=MYISAM;

add referential integrity

ALTER TABLE pembelian_detil
ADD CONSTRAINT FOREIGN KEY (kd_brg)
REFERENCES barang (kd_brg);

create table penjualan_detil

CREATE TABLE penjualan_detil (
no_jual varchar(4) NOT NULL,
kd_brg varchar(4) NOT NULL,
harga_jual double NOT NULL,
jumlah double NOT NULL,
PRIMARY KEY (no_jual, kd_brg))
ENGINE=MYISAM;

add referential integrity

ALTER TABLE penjualan_detil
ADD CONSTRAINT FOREIGN KEY (kd_brg)
REFERENCES barang (kd_brg);

tutorial: SQL

create table pelanggan

CREATE TABLE pelanggan (
kd_plg int(4) unsigned zerofill NOT NULL auto_increment,
nm_plg varchar(20) NOT NULL,
alamat varchar(50) NOT NULL,
PRIMARY KEY (kd_plg))
ENGINE=MYISAM AUTO_INCREMENT; 

entering information

INSERT INTO pelanggan (nm_plg, alamat)
VALUES
('slamet','jl.karang-tengah 24 demak'),
('vera','jl.kaliurang 2 yogyakarta');

query information

SELECT kd_plg, nm_plg, alamat FROM pelanggan

Selecting Data from different tables (INNER JOIN)

create table barang

CREATE TABLE barang (
kd_brg int(4) unsigned zerofill NOT NULL auto_increment PRIMARY KEY,
nm_brg varchar (30) NOT NULL,
harga double NOT NULL); 

entering information

INSERT INTO barang (nm_brg, harga)
VALUES
('LED samsung','1500'),
('Macbook','6000');

create table penjualan

CREATE TABLE penjualan (
no_jual int(4) NOT NULL auto_increment PRIMARY KEY,
kd_plg int(4) NOT NULL,
tgl DATE NOT NULL)
ENGINE=MYISAM;

entering information

INSERT INTO penjualan (kd_plg,tgl)
VALUES
(1, '2012-07-05')
(2, '2012-09-01');

create table penjualan_detil

CREATE TABLE penjualan_detil (
no_jual int(4) NOT NULL,
kd_brg int(4) unsigned zerofill NOT NULL,
harga double NOT NULL,
jumlah int(4) NOT NULL,
PRIMARY KEY (no_jual,kd_brg));
INSERT INTO penjualan_detil (no_jual,kd_brg)
VALUES
(1,1, '1500',2)
(1,2, '6000',5);
SELECT no_jual, nm_plg, alamat, tgl
FROM penjualan AS p
INNER JOIN 
pelanggan AS pl (p.kd_plg=pl.kd_plg)