PHP Classes
elePHPant
Icontem

File: demos/014.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Tom Schaefer  >  d3Google  >  demos/014.php  >  Download  
File: demos/014.php
Role: Example script
Content type: text/plain
Description: Create annotated timeline
Class: d3Google
Generate JavaScript to show Google charts and maps
Author: By
Last change: fix
Date: 2 years ago
Size: 2,415 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(new
Date(2008, 1 ,1), 30000, null, null, 40645, null, null),
    array(new
Date(2008, 1 ,2), 14045, null, null, 20374, null, null),
    array(new
Date(2008, 1 ,3), 55022, null, null, 50766, null, null),
    array(new
Date(2008, 1 ,4), 75284, null, null, 14334, 'Out of Stock', 'Ran out of stock on pens at 4pm'),
    array(new
Date(2008, 1 ,5), 41476, 'Bought Pens', 'Bought 200k pens', 66467, null, null),
    array(new
Date(2008, 1 ,6), 33322, null, null, 39463, null, null)
);

# chart option definition
$timelineOptions = google::options()->AnnotatedTimeline;
$timelineOptions->displayAnnotations = true;


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

# 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('annotatedtimeline')))));
$head->script()->add($f)->linebreak()->add(google(true)->setOnLoadCallback($f->getVar("drawTable")->getVar()));

$data = google()->visualization->DataTable()->createVar("data", true);
stack()->add($data);

   
stack()->add( google(true, $data->getVar())->addColumn("date", "Date") );
   
stack()->add( google(true, $data->getVar())->addColumn("number", "Sold Pencils") );
   
stack()->add( google(true, $data->getVar())->addColumn("string", "title1") );
   
stack()->add( google(true, $data->getVar())->addColumn("string", "text1") );
   
stack()->add( google(true, $data->getVar())->addColumn("number", "Sold Pens") );
   
stack()->add( google(true, $data->getVar())->addColumn("string", "title2") );
   
stack()->add( google(true, $data->getVar())->addColumn("string", "text2") );
   
   
stack()->add( google(true, $data->getVar())->addRows($results));

   
$timeline = google()->visualization->AnnotatedTimeLine(document()->getElementById("chart"))->createVar("annotatedtimeline", true);
   
stack()->add( $timeline );
   
stack()->add( google(true, $timeline->getVar())->draw($data->getVar(), $timelineOptions) );
   
$f->add(stack());
   

echo
$html;