Skip to content

Generate a JSON-representation of a DataTable for Google's Chart Tools / Visualization API easily, using PHP.

License

Notifications You must be signed in to change notification settings

itavero/AMNL-GCDataTable

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GC DataTable

Build Status Latest Stable Version Total Downloads

This library is meant to simplify the dynamic generation of a JSON-representation of a DataTable when using PHP. DataTables are used by the Google Visualization API / Chart Tools, see this reference on developers.google.com for more info.

Problems? Suggestions?

Create a new issue to tell me about your suggestions and/or problems. I'd love to hear your opinion!

Example

For the time being you can have a look at "Populating Data Using Server Side Code". The code below basically replaces getData.php and sampleData.json and allows you to dynamically change the output.

<?php

/*
 * A bunch of use-statements
 * (assuming you have some kind of autoloading mechanism)
 */
use AMNL\Google\Chart\Table;
use AMNL\Google\Chart\Column;
use AMNL\Google\Chart\Row;
use AMNL\Google\Chart\Type as T;

/* The actual code */
$pizzaTable = new Table(
    new Column(new T\String(), 'Topping'),
    new Column(new T\Number(), 'Slices')
);

$pizzaTable->addRow(new Row('Mushrooms', 3));
$pizzaTable->addRow(new Row('Onions', 1));
$pizzaTable->addRow(new Row('Olives', 1));
$pizzaTable->addRow(new Row('Zucchini', 1));
$pizzaTable->addRow(new Row('Pepperoni', 2));

/* JSON Output */
header('Content-Type: application/json');
echo $pizzaTable->toJson();

About

Generate a JSON-representation of a DataTable for Google's Chart Tools / Visualization API easily, using PHP.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Languages