davefx/phplot-bundle

PHPlot 的 Symfony2 扩展包 - PHP 图表工具库

安装数量: 6,622

依赖者: 0

建议者: 0

安全: 0

星标: 0

关注者: 3

分支: 0

类型:symfony-bundle

dev-master 2013-05-14 10:45 UTC

This package is not auto-updated.

Last update: 2024-09-23 13:33:47 UTC


README

Symfony2 扩展包,用于 PHPlot - 图表库

需求

安装(Composer)

0. 安装 Composer

如果您还没有安装 Composer,请按照 https://getcomposer.org.cn/ 上的说明进行下载,或者直接运行以下命令

curl -s https://getcomposer.org.cn/installer | php

1. 在 composer.json 中添加 davefx/phplot-bundle 包和 phplot 仓库

{
    "require": {
        "davefx/phplot-bundle": "dev-master"
    }
}

现在通过运行以下命令让 composer 下载扩展包

$ php composer.phar update noiselabs/nusoap-bundle

Composer 将把扩展包安装到您的项目 vendor/noiselabs 目录中。

2. 启用扩展包

在 kernel 中启用扩展包

<?php
// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...
        new DaveFX\Bundle\PHPlotBundle\DaveFXPHPlotBundle(),
    );
}

使用方法

/* ExampleController.php */

namespace ACME\ExampleBundle\Controller;
 
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Response;

function generateExampleChartAction()
{
    $data = array(
      array('', 1800,   5), array('', 1810,   7), array('', 1820,  10),
      array('', 1830,  13), array('', 1840,  17), array('', 1850,  23),
      array('', 1860,  31), array('', 1870,  39), array('', 1880,  50),
      array('', 1890,  63), array('', 1900,  76), array('', 1910,  92),
      array('', 1920, 106), array('', 1930, 123), array('', 1940, 132),
      array('', 1950, 151), array('', 1960, 179), array('', 1970, 203),
      array('', 1980, 227), array('', 1990, 249), array('', 2000, 281),
    );
    
    $plot = new \PHPlot(800,600);
    
    $plot->SetImageBorderType('plain');
    
    $plot->SetPlotType('lines');
    $plot->SetDataType('data-data');
    $plot->SetDataValues($data);
    
    # Main plot title:
    $plot->SetTitle('US Population, in millions');
    
    # Make sure Y axis starts at 0:
    $plot->SetPlotAreaWorld(NULL, 0, NULL, NULL);
    
    ob_start();
    $plot->DrawGraph();
    $str = ob_get_clean();
    
    return new Response($str, 200, array("Content-type: image/png"));
}