PHP 对 Google Chart API 的封装类

dev-master 2015-08-18 23:29 UTC

This package is auto-updated.

Last update: 2024-09-15 17:29:07 UTC


README

phpgc 是一个 PHP 封装类,提供了构建图表的灵活方式。phpgc 使用 Google Chart api 来绘制图表。这实际上是一个 Google Chart api 的封装。通过这个 phpgc,您可以轻松地将数据可视化到您的 Web 应用程序中。

安装

在您的 composer.json 文件中写入 "sohelrana820/phpgc": "dev-master" 以安装。如果您想手动安装,请下载此存储库并将其存储在您的项目中的某个位置。

使用方法

创建 phpgc 类的实例 $chart = new \src\phpgc(); 现在,您可以使用此 $chart 对象创建图表。这里我展示了创建饼图的示例代码。

$pieColumns = array(
    'Country' => array(
        'type' => 'string',
        'label' => 'Name of Country'
    ),
    'Population' => array(
        'type' => 'number',
        'label' => 'Population'
    )
);

$pieRows = array(
    array(
        0 => 'Germany',
        1 => 100000,
    ),
    array(
        0 => 'United States',
        1 => 120000,
    ),
    array(
        0 => 'Brazil',
        1 => 80000,
    ),
    array(
        0 => 'Canada',
        1 => 70000,
    ),
    array(
        0 => 'France',
        1 => 50000,
    ),
    array(
        0 => 'BD',
        1 => 100000,
    ),
    array(
        0 => 'RU',
        1 => 90000,
    ),
);
$pieOptions = array(
    'title' => 'Population',
    'width' => 'autometic',
    'height' => '250',
    'widget' => true,
    'class' => 'custom',
    'div' => 'pie_chart_1',
);
echo $chart->pieChart($pieColumns, $pieRows, $pieOptions);

点击此处查看完整的图表列表。