0

我试过使用http://bakery.cakephp.org/articles/ixu38/2010/04/30/googlechart-api-helper但我没有设法让它工作。

  1. 我已经用代码创建了助手GoogleChartHelperapp-->View-->Helper

  2. 我在我的控制器上创建了这个函数:

    public function chart() {
        $color = array(
            '#687e9b',
            '#c4ccd8',
        );
    
        $dataMultiple = array(array(0,1,2,3), array(4,5,6,7));
    
        $googleChart->setChartAttrs( 
            array(
                'type'      => 'bar-vertical',
                'title'     => '',
                'data'      => $dataMultiple,
                'size'      => array( 400, 200 ),
                'color'     => $color,
                'labelsXY'  => true,
                'min'       => array(min(rray(0,1,2,3)),min(array(4,5,6,7))),
                'max'       => array(max(array(0,1,2,3)),max(array(4,5,6,7))),
                'legend'    => array('2008', '2009')
            )
        );
    
    //  Print chart
        echo $googleChart;
    
  3. 最后我把这个命令放在视图上:

<?php echo $this->Html->link(__('Chart'), '/users/chart'); ?>

当我尝试制作图表时,cakephp 给了我这个错误:

错误:在非对象上调用成员函数 setChartAttrs()


问题出在哪里?

4

1 回答 1

0

试试这个谷歌图表助手并将其粘贴到app/view/helper 并使用下面的代码

Controller:

public $helpers = array('GoogleChart');

View:

// example of bar chart
echo $this->GoogleChart->create()
    ->setType('bar', array('horizontal', 'grouped'))
    ->setSize(500, 400)
    ->setMargins(5, 5, 5, 5)
    ->addData(array(1200.48, 432.3, 647.21, 635.2))
    ->addMarker('value', array('format' => 'f1', 'placement' => 'c'))
    ->addData(array(20, 42.3, 65.21, 95.2))
    ->addMarker('value', array('size' => 14, 'color' => '000000'))
    ->addAxis('x', array('labels' => array('jan 2012', 'feb 2012')))
    ->addAxis('y', array('axis_or_tick' => 'l', 'size' => 12));

// example of pie chart
echo $this->GoogleChart->create()
    ->setTitle('CHART TITLE', array('size' => 14, 'color' => '000000'))
    ->setType('pie', array('3d'))
    ->setSize(600, 300)
    ->setMargins(10, 10, 10, 10)
    ->addData(array(20, 35, 50, 10))
    ->setPieChartLabels(array('first', 'second', 'third', 'and so on...'));
于 2015-08-17T14:10:37.803 回答