PHP Classes
elePHPant
Icontem

File: demos/008.php

Recommend this page to a friend!
  Classes of Tom Schaefer  >  d3Google  >  demos/008.php  >  Download  
File: demos/008.php
Role: Example script
Content type: text/plain
Description: the chart editor
Class: d3Google
Generate JavaScript to show Google charts and maps
Author: By
Last change:
Date: 3 years ago
Size: 2,492 bytes
 

Contents

Class file image Download
<?php

include_once '../d3.classes.inc.php';
include_once
'../google.classes.inc.php';
include_once
'../element.php';


# html definition
$html = E("html");
$head = $html->head();
$body = $html->body();
$div = $body->toBody("div", array("id"=>"chart"));
$div->css(array("width"=>"600px", "height"=>"400px"));

$body->toBody("input", array("type"=>"button", "onclick"=>"openEditor()", "value"=>"Open Editor"));

# chart definition

$f = func()->name("init");
$fe = func()->name("openEditor");
$f3 = func();
$head->script()->addAttribute("src", "//www.google.com/jsapi");
$head->script()->add(google(true)->load("visualization", "1", obj(array("packages"=>array('charteditor')))));
$head->script()->add(google::variable(null, "wrapper"))
    ->
add($f)
    ->
add($fe)->linebreak()
    ->
add(google(true)
        ->
setOnLoadCallback($f->getVar("init")->getVar())
    );

$wrapper = google(false)->visualization->ChartWrapper(obj(
        array(
               
"chartType" => 'ColumnChart',
               
"dataTable" => array(
                    array(
'Year', 'Austria', 'Belgium', 'Czech Republic', 'Finland', 'France', 'Germany'),
                    array(
'2003', 1336060, 3817614, 974066, 1104797, 6651824, 15727003),
                    array(
'2004', 1538156, 3968305, 928875, 1151983, 5940129, 17356071),
                    array(
'2005', 1576579, 4063225, 1063414, 1156441, 5714009, 16716049),
                    array(
'2006', 1600652, 4604684, 940478, 1167979, 6190532, 18542843),
                    array(
'2007', 1968113, 4013653, 1037079, 1207029, 6420270, 19564053),
                    array(
'2008', 1901067, 6792087, 1037327, 1284795, 6240921, 19830493)
                ),
               
"options" => array('title' => 'Countries'),
               
"containerId" => 'chart'
       
)
))->
createVar("wrapper", true, false);

stack()->add($wrapper);
stack()->add(";");
stack()->add(google(false, $wrapper->getVar())->draw());
stack()->add(";");

$f->add(stack());


$editor = google()->visualization->ChartEditor()->createVar("editor");
stack()->add($editor);
$fe->add(stack());

$f3->add(google(false, $editor->getVar())->getChartWrapper()->createVar($wrapper->getVar(),false, false));
$f3->add(google(true, $wrapper->getVar())->draw(document()->getElementById("chart")));

$event = google(false)->visualization->events(google::property)->addListener($editor->getVar(), "ok", $f3)->colon();
$fe->add($event);

$fe->add(google(true, $editor->getVar())->openDialog($wrapper->getVar()));


echo
$html;