【问题标题】:GoogleChart Plugin view emptyGoogleChart 插件视图为空
【发布时间】:2015-12-29 16:53:24
【问题描述】:

我使用的是 CakePHP 2.x,我需要通过图表显示报告。我看到了 Scott Harwell 的 CakePHP CakePHP GoogleCharts Plugin 这个插件。我一步一步地做所有事情,不知怎的,我的观点一直显得空洞。

DOM 中没有 javascript 输出。

这是我的代码:

我的 bootstrap.php

CakePlugin::load('GoogleCharts');

我的控制器:

$results = $this->Statistique->getIndicateursQuants( $this->request->data );
$this->set( 'results', $results );

$chart = new GoogleCharts();
$chart->type("LineChart");  
$chart->options(array('title' => "Etat statistique du nombre de flux")); 
$chart->columns(array(
       'name' => array(
           'type' => 'string',              
            'label' => 'Name'
        ),
        'nb' => array(
            'type' => 'number',
             'label' => 'nombre',
        )
 ));
 $content_chart =array();
 foreach($results as $index => $result){
    foreach($result as $cle => $value){
                    array_push($content_chart,array("name"=>$cle,"nb"=> (int)$value));
    }
 }
 foreach($content_chart as $row){
     $chart->addRow(array('name' => $row['name'], 'nb' => $row['nb']));
 }
 $this->set(compact('chart'));

我的看法:

<div id="chart_div">
    <?php $this->GoogleCharts->createJsChart($chart);?>
</div>

我在 GoogleChartsHelper 中有测试器,$scriptOutput 是这样的:

$(document).ready(function(){
options_56823e100db90 = chartOptions = {
"width":400,
"height":300,
"title":"Etat statistique du nombre de flux",
"titleTextStyle":{"color":"red"}
};
js_56823e100dc16 = chartData = new google.visualization.arrayToDataTable([
['Name','nombre'],
['encours',852],
['refuse',11],
['valide',13],
['cloture',91],
['total',967]]);
chart_56823e100dcaf = chart = new google.visualization.LineChart(document.getElementById('chart_div'));
chart_56823e100dcaf.draw(js_56823e100dc16, options_56823e100db90);});

但是当我看到源代码时,它并不包含在 DOM 中。

插件:enter image description here

非常感谢。

【问题讨论】:

  • 您好,请问您的问题解决了吗?我和你有同样的问题。

标签: javascript jquery cakephp plugins


【解决方案1】:

在您的控制器中,就在$this-&gt;set(compact('chart')); 之前执行var_dump($chart); 以确保您发送到视图的内容。这将为您提供有关问题所在的一些信息。

还有两件事你没有明确提到:

1 - 您是否在控制器中包含 App::uses('GoogleCharts', 'GoogleCharts.Lib');

2 - 您是否在控制器中包含了 public $helpers = array('GoogleCharts.GoogleCharts');

这些将引导我们找到最终解决方案。

【讨论】:

  • 您好,非常感谢您的回答。而且我确信我已经包含了“App::uses('GoogleCharts', 'GoogleCharts.Lib');”和“$helpers = array('GoogleCharts.GoogleCharts');”
  • object(GoogleCharts)#104 (6) { ["type":"GoogleCharts":private]=> string(9) "LineChart" ["columns":"GoogleCharts":private]= > array(2) { ["name"]=> array(2) { ["type"]=> string(6) "string" ["label"]=> string(4) "Name" } ["nb "]=> array(2) { ["type"]=> string(6) "number" ["label"]=> string(6) "nombre" } } ["rows":"GoogleCharts":private] => array(5) { [0]=> array(2) { [0]=> string(7) "encours" [1]=> int(0) }... }
  • ["options":"GoogleCharts":private]=> array(4) { ["width"]=> int(400) ["height"]=> int(300) [" title"]=> string(34) "Etat statistique du nombre de flux" ["titleTextStyle"]=> array(1) { ["color"]=> string(3) "red" } } ["callbacks": "GoogleCharts":private]=> 数组(0) { } ["div":"GoogleCharts":private]=> 字符串(9) "chart_div" }
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-07-07
  • 1970-01-01
  • 2021-09-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多