amnl/gc-datatable

PHP 库,用于生成 Google 图表工具的 JSON 数据。

v0.2.0 2013-06-07 19:12 UTC

This package is not auto-updated.

Last update: 2024-09-14 13:09:59 UTC


README

Build Status Latest Stable Version Total Downloads

此库旨在简化使用 PHP 动态生成 DataTable 的 JSON 表示。DataTable 由 Google Visualization API/Chart Tools 使用,有关更多信息,请参阅 developers.google.com 上的此参考

有问题?建议?

创建一个新问题,告诉我你的建议和/或问题。我很乐意听到您的意见!

示例

目前您可以查看 "使用服务器端代码填充数据"。以下代码基本替换了 getData.php 和 sampleData.json,并允许您动态更改输出。

<?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();