PHP Classes

File: demos/012.php

Recommend this page to a friend!
  Classes of Tom Schaefer   d3Google   demos/012.php   Download  
File: demos/012.php
Role: Example script
Content type: text/plain
Description: Create a table chart with data table and json object
Class: d3Google
Generate JavaScript to show Google charts and maps
Author: By
Last change:
Date: 11 years ago
Size: 1,793 bytes
 

Contents

Class file image Download
<?php
include_once '../d3.classes.inc.php';
include_once
'../google.classes.inc.php';
include_once
'../element.php';

# how to create chart options
# with the IDE autocompleter

$results = array(
    array(
'Mike', array("v" => 10000, "f" => '$10,000'), true),
    array(
'Jim', array("v" => 8000, "f" => '$8,000'), false),
    array(
'Alice', array("v" => 12500, "f" => '$12,500'), true),
    array(
'Bob', array("v" => 7000, "f" => '$7,000'), true)
);

# chart option definition
$tableOptions = google::options()->Tablechart;
$tableOptions->showRowNumber = true;


# html definition
$html = E("html");
$head = $html->head();
$body = $html->body();
$div = $body->toBody("div", array("id"=>"table_div"));

# chart definition
$f = func()->name("drawTable");

$head->script()->addAttribute("src", "//www.google.com/jsapi");
$head->script()->add(google(true)->load("visualization", "1", obj(array("packages"=>array('table')))));
$head->script()->add($f)->linebreak()->add(google(true)->setOnLoadCallback($f->getVar("drawTable")->getVar()));

# create data table
$data = google()->visualization->DataTable()->createVar("data", true);
stack()->add($data);
stack()->add( google(true, $data->getVar())->addColumn("string", "Name") );
stack()->add( google(true, $data->getVar())->addColumn("number", "Salary") );
stack()->add( google(true, $data->getVar())->addColumn("boolean", "Full Time Employee") );
stack()->add( google(true, $data->getVar())->addRows($results) );

# create table chart
$table = google()->visualization->Table(document()->getElementById("table_div"))->createVar("table", true);
stack()->add( $table );
stack()->add( google(true, $table->getVar())->draw($data->getVar(), $tableOptions) );
   
$f->add(stack());
   

echo
$html;