2amigos / yiiwheels

Widget extension library for the YiiStrap extension
http://yiiwheels.2amigos.us
Other
133 stars 77 forks source link

PHP Warning in WhChart.php(112) #67

Closed Leuloch closed 10 years ago

Leuloch commented 10 years ago

When I set the Grid/Chart Switcher (like the example in http://yiiwheels.2amigos.us/site/grid#gridswitch) I receive this error message: PHP Warning Illegal string offset 'attribute' in WhChart.php(112)

Am I doing something wrong?

tonydspaniard commented 10 years ago

Can you provide code? Is hard for me to tell like this...

Leuloch commented 10 years ago

Antonio, this is the code I use in my index.php: *Note that this is only an example (because I'm using the id column to generate the graph.)


<?php

$this->breadcrumbs = array(
    Empresa::label(2),
    Yii::t('app', 'Index'),
);
$this->layout='//layouts/column2';
$this->title=  Yii::t('app', 'Empresas');
$this->menu = array(
    array('label'=>Yii::t('app', 'Create'), 'url'=>array('create'), 'icon' => 'icon-plus-sign'),
    array('label'=>Yii::t('app', 'Manage'), 'url'=>array('admin'), 'icon' => 'icon-search'),
);
?>

<h1><?php echo GxHtml::encode(Empresa::label(2)); ?></h1>

<?php $this->widget('yiiwheels.widgets.grid.WhGridView', array(
        'type' => 'striped bordered',
        'dataProvider' => $dataProvider,
        'template' => "{items}\n{extendedSummary}",
        'columns' => array(
                'id',       
                'nome',
                'razao_social',
                'ddd_tel_comercial',
                'telefone_comercial',

                array(
                'name'=>'atividade_id',
                'value'=>'GxHtml::valueEx($data->atividade)',
                'filter'=>GxHtml::listDataEx(Atividade::model()->findAllAttributes(null, true)),
                ),                
        array(
            'class' => 'bootstrap.widgets.TbButtonColumn',
        ),
         ),         
         'chartOptions' => array(                
                'data' => array(
                        'series' => array(
                                'name' => 'Número de Cadastro',
                                'attribute' => 'id',
                        ),
                ),
                'config' => array(
                        'chart' => array(
                                'width' => 800,
                        )
                ),
         ),
)); ?>

And this is the error message:

PHP warning

Illegal string offset 'attribute'

/opt/lampp/htdocs/polyafer-app2/protected/extensions/yiiwheels/widgets/grid/behaviors/WhChart.php(112)

100         $chartId = $this->grid->registerChartControlButtonsScript();
101 
102         // render Chart
103         // chart options
104         $data = $this->grid->dataProvider->getData();
105         $count = count($data);
106         $seriesData = array();
107         $cnt = 0;
108         foreach ($configSeries as $set) {
109             $seriesData[$cnt] = array('name' => isset($set['name']) ? $set['name'] : null, 'data' => array());
110 
111             for ($row = 0; $row < $count; ++$row) {
112                 $column = $this->grid->getColumnByName($set['attribute']);
113                 if (!is_null($column) && $column->value !== null) {
114                     $seriesData[$cnt]['data'][] = $this->evaluateExpression(
115                         $column->value,
116                         array('data' => $data[$row], 'row' => $row)
117                     );
118                 } else {
119                     $value = CHtml::value($data[$row], $set['attribute']);
120                     $seriesData[$cnt]['data'][] = is_numeric($value) ? (float)$value : $value;
121                 }
122 
123             }
124             ++$cnt;

Stack Trace
#0  
 unknown(0): WhChart->renderChart()
#1  
+
 /opt/lampp/htdocs/yii-1.1.14.f0fee9/framework/base/CComponent.php(261): call_user_func_array(array(WhChart, "renderChart"), array())
#2  
–
 /opt/lampp/htdocs/polyafer-app2/protected/extensions/yiiwheels/widgets/grid/WhGridView.php(207): CComponent->__call("renderChart", array())

Note that this is only an example (because I'm using the id column to generate the graph.)
202     /**
203      * Renders grid header
204      */
205     public function renderTableHeader()
206     {
207         $this->renderChart();
208         parent::renderTableHeader();
209     }
210 
211     /**
212      * Renders the table footer.

#3  
–
 /opt/lampp/htdocs/polyafer-app2/protected/extensions/yiiwheels/widgets/grid/WhGridView.php(207): WhGridView->renderChart()

202     /**
203      * Renders grid header
204      */
205     public function renderTableHeader()
206     {
207         $this->renderChart();
208         parent::renderTableHeader();
209     }
210 
211     /**
212      * Renders the table footer.

#4  
+
 /opt/lampp/htdocs/yii-1.1.14.f0fee9/framework/zii/widgets/grid/CGridView.php(480): WhGridView->renderTableHeader()
#5  
+
 /opt/lampp/htdocs/yii-1.1.14.f0fee9/framework/zii/widgets/CBaseListView.php(167): CGridView->renderItems()
#6  
 unknown(0): CBaseListView->renderSection(array("{items}", "items"))
#7  
+
 /opt/lampp/htdocs/yii-1.1.14.f0fee9/framework/zii/widgets/CBaseListView.php(150): preg_replace_callback("/{(\w+)}/", array(WhGridView, "renderSection"), "{items} {extendedSummary}")
#8  
–
 /opt/lampp/htdocs/polyafer-app2/protected/extensions/yiiwheels/widgets/grid/WhGridView.php(155): CBaseListView->renderContent()

150     /**
151      * Renders grid content
152      */
153     public function renderContent()
154     {
155         parent::renderContent();
156         $this->registerCustomClientScript();
157     }
158 
159     /**
160      * Helper function to get an attribute from the data

#9  
+
 /opt/lampp/htdocs/yii-1.1.14.f0fee9/framework/zii/widgets/CBaseListView.php(135): WhGridView->renderContent()
#10     
+
 /opt/lampp/htdocs/yii-1.1.14.f0fee9/framework/web/CBaseController.php(173): CBaseListView->run()
#11     
+
 /opt/lampp/htdocs/polyafer-app2/protected/views/empresa/index.php(50): CBaseController->widget("yiiwheels.widgets.grid.WhGridView", array("type" => "striped bordered", "dataProvider" => CActiveDataProvider, "template" => "{items} {extendedSummary}", "columns" => array("id", "nome", "razao_social", "ddd_tel_comercial", ...), ...))
#12     
+
 /opt/lampp/htdocs/yii-1.1.14.f0fee9/framework/web/CBaseController.php(126): require("/opt/lampp/htdocs/polyafer-app2/protected/views/empresa/index.ph...")
#13     
+
 /opt/lampp/htdocs/yii-1.1.14.f0fee9/framework/web/CBaseController.php(95): CBaseController->renderInternal("/opt/lampp/htdocs/polyafer-app2/protected/views/empresa/index.ph...", array("dataProvider" => CActiveDataProvider), true)
#14     
+
 /opt/lampp/htdocs/yii-1.1.14.f0fee9/framework/web/CController.php(869): CBaseController->renderFile("/opt/lampp/htdocs/polyafer-app2/protected/views/empresa/index.ph...", array("dataProvider" => CActiveDataProvider), true)
#15     
+
 /opt/lampp/htdocs/yii-1.1.14.f0fee9/framework/web/CController.php(782): CController->renderPartial("index", array("dataProvider" => CActiveDataProvider), true)
#16     
+
 /opt/lampp/htdocs/polyafer-app2/protected/controllers/EmpresaController.php(87): CController->render("index", array("dataProvider" => CActiveDataProvider))
#17     
+
 /opt/lampp/htdocs/yii-1.1.14.f0fee9/framework/web/actions/CInlineAction.php(49): EmpresaController->actionIndex()
#18     
+
 /opt/lampp/htdocs/yii-1.1.14.f0fee9/framework/web/CController.php(308): CInlineAction->runWithParams(array("r" => "empresa/index"))
#19     
+
 /opt/lampp/htdocs/yii-1.1.14.f0fee9/framework/web/filters/CFilterChain.php(133): CController->runAction(CInlineAction)
#20     
+
 /opt/lampp/htdocs/yii-1.1.14.f0fee9/framework/web/filters/CFilter.php(40): CFilterChain->run()
#21     
+
 /opt/lampp/htdocs/yii-1.1.14.f0fee9/framework/web/filters/CFilterChain.php(130): CFilter->filter(CFilterChain)
#22     
+
 /opt/lampp/htdocs/yii-1.1.14.f0fee9/framework/web/CController.php(291): CFilterChain->run()
#23     
+
 /opt/lampp/htdocs/yii-1.1.14.f0fee9/framework/web/CController.php(265): CController->runActionWithFilters(CInlineAction, array(array("auth.filters.AuthFilter")))
#24     
+
 /opt/lampp/htdocs/yii-1.1.14.f0fee9/framework/web/CWebApplication.php(282): CController->run("index")
#25     
+
 /opt/lampp/htdocs/yii-1.1.14.f0fee9/framework/web/CWebApplication.php(141): CWebApplication->runController("empresa/index")
#26     
+
 /opt/lampp/htdocs/yii-1.1.14.f0fee9/framework/base/CApplication.php(180): CWebApplication->processRequest()
#27     
+
 /opt/lampp/htdocs/polyafer-app2/index.php(13): CApplication->run() 
tonydspaniard commented 10 years ago

This is wrong

'series' => array(
   'name' => 'Número de Cadastro',
   'attribute' => 'id',
 ),

Check how it is set on the example site:

'series' => array(
                array(
                    'name' => 'Hours worked',
                    'attribute' => 'hours'
                )
            )