cakephp饼图由动态数据组成

时间:2016-03-30 05:23:17

标签: php cakephp google-pie-chart

我想通过动态数据在cakephp中创建一个饼图。我已经创建了这个,但它是静态的。我怎样才能让它充满活力。我的代码在这里。

<?php 
echo $this->GoogleChart->create ()
    ->setTitle ( 'Trips Request Graph', array ('size' => 26, 'color' => '000000' ) )
    ->setType ( 'pie', array ('3d' ) )
    ->setSize ( 1000, 300 )
    ->setMargins ( 10, 10, 10, 10, 10 )
    ->addData ( array (10,10,10) )
    ->setPieChartLabels ( array ('Riajul','Rafsan','Taukir' ) );
?>

我想在->addData()->setPieChartLabels部分

中设置数据

1 个答案:

答案 0 :(得分:1)

试试这个

$arr = array ( 0 => "Riajul", 1 => "Rafsan", 2 => "Taukir"); // your data

$nameString = implode (", ", $arr);  // create a comma separated string

echo $this->GoogleChart->create()->setTitle ( 'Trips Request Graph', array ('size' => 26, 'color' => '000000' ) )
    ->setType ( 'pie', array ('3d' ) )
    ->setSize ( 1000, 300 )
    ->setMargins ( 10, 10, 10, 10, 10 )
    ->addData ( array (10,10,10) )
    ->setPieChartLabels ( array ($nameString) ); 
?>