stocarul / pchart-bundle
PHP面向类的框架,用于创建图表
Requires
- php: >=5.3.3
This package is not auto-updated.
Last update: 2024-09-23 15:06:34 UTC
README
Symfony 2.x 的 pChart Bundle 允许您使用 pChart 库来满足所有图表需求。
这是一个初始版本,支持渲染所有图表类型。对 pChart 库的最新版本进行了少量修改,因为它与 Symfony 2.x 和 PHP5.3 不是很兼容。目前尚未测试 pChart 缓存。
可以从 https://github.com/rbakels/pChartBundle 下载此 Bundle,但您可能已经知道了。
许可
请参阅此 Bundle 包含的 LICENSE 文件。
作者
Robin Bakels (robin@xlab.nl)。荷兰公司 Xlab B.V. 的软件工程师。更多信息请访问:http://www.xlab.nl/
安装
安装快捷简单,2 步骤过程
- 安装 XlabpChartBundle
- 启用 Bundle
步骤 1: 安装 xLabpChartBundle
将以下依赖项添加到您的 composer.json 文件中
{ "require": { "_some_packages": "...", "stocarul/pchart-bundle": "dev-master" } }
步骤 2: 启用 Bundle
最后,在 kernel 中启用 Bundle
<?php // app/AppKernel.php public function registerBundles() { $bundles = array( // ... new Xlab\pChartBundle\XlabpChartBundle(), ); }
可选,您可以将以下内容添加到您的 routing.yml 中
pChart:
resource: "@XlabpChartBundle/Resources/config/routing_pChart.yml"
prefix: /pChart
这为您提供了查看一些示例(这些示例最初与 pChart 源代码一起发布)的实时预览的可能性。包含 routing_pChart.yml 文件后,示例列表的 URL 可以访问以下内容
http://<your_hostname>/pChart/index
如何使用此 Bundle?
可能有多于一种使用方式。目前,我非常喜欢在 Controller 动作中生成图表图像,并在 Twig 模板文件中的 标签中调用此方法。
- 将路由添加到您的 routing.yml,您希望从其中渲染图表图像的位置。
- 包含适当的命名空间。名称来自原始文件(例如,pPie.class.php 位于 Xlab\pChartBundle\pPie 命名空间中)
- 创建控制器方法。
- 在所有 pChart 特定调用之后添加以下代码
示例
<?php
namespace Xlab\pChartBundle\Controller;
use Xlab\pChartBundle\pData;
use Xlab\pChartBundle\pDraw;
use Xlab\pChartBundle\pPie;
use Xlab\pChartBundle\pImage;
use Xlab\pChartBundle\pBarcode39;
use Xlab\pChartBundle\pBarcode128;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Response;
class ExamplesController extends Controller
{
public function exampleAction()
{
$response = new Response();
$response->headers->set('Content-Type', 'image/png');
/* pChart stuff goes here */
...
/* Capture output and return the response */
ob_start();
$chart->autoOutput();
$response->setContent(ob_get_clean());
return $respone;
}
}
在上面的示例中,$chart 变量是 pImage 类的实例。
另请参阅:Xlab/pChartBundle/Controller/ExamplesController.php
变更日志
2012 年 3 月 16 日
- 初始版本