CakePHP、Google图表插件和JsHelper
我希望选择dropdownlist的一个元素(选择一个项目),并使用JSHELPER(ajax)更新显示该项目统计信息的图形 我可以选择项目,并通过“POST”生成数组图,但我无法显示该图。我在没有JSHELPER的情况下进行了测试,并显示了我的图表 我的视图代码:CakePHP、Google图表插件和JsHelper,cakephp,Cakephp,我希望选择dropdownlist的一个元素(选择一个项目),并使用JSHELPER(ajax)更新显示该项目统计信息的图形 我可以选择项目,并通过“POST”生成数组图,但我无法显示该图。我在没有JSHELPER的情况下进行了测试,并显示了我的图表 我的视图代码: <b>ESCOLHA O PROJETO: </b> <?php echo $this->Form->select('projects', array($proje
<b>ESCOLHA O PROJETO: </b>
<?php
echo $this->Form->select('projects', array($projects), array('multiple' => false,
'class' => 'span2',
'id' => 'projectsTest'));
?>
</br>
<div id="chart_div" >
</div>
<?php
$this->Js->get('#projectsTest')->event('change', $this->Js->request(array(
'controller' => 'Registos',
'action' => 'timePerProjectIssueTypeChart'
), array(
'update' => '#chart_div',
'async' => true,
'method' => 'post',
'dataExpression' => true,
'data' => $this->Js->serializeForm(array(
'isForm' => true,
'inline' => true
))
)));
我不把控制器的代码,因为单独测试和工作
感谢Teste com ajax、sem o JS助手:
$(document).ready(function() {
$("#projectsTest").change(function(){
$.ajax({
type: 'POST',
data: { projects: $('#projectsTest').val()},
url: 'timePerProjectIssueTypeChart',
success: funcion() {
$("chart_div").load('timePerProjectIssueTypeChart');
}
})
})
});
E não esqueça de colocar
$this->layout=false
无控制器嗨!!BR???Não seria“控制器”=>“注册表”
?可以是'controller'=>'RegistRos'
?@Igor Martin Portugues:)注册为palavras estão corretas。。。欧盟在这方面所做的一切都是错误的。这是一张谷歌图表。在开始采取行动之前,我们必须解决问题。这是一个很好的解决方案,它是一个关于蛋糕的布局图,它是一个行动图。好的,你可以去埃希比昂o@Igor马丁斯·奥普拉菲科的问题就在眼前。是的,是的。在欧洲,没有一个código da视图<代码>时间>每个项目的问题类型图表<代码>e colocar na视图“委托人”(sem o codigo do JS Helper)o gráfico aparece normal e:)Nunca usei o JS Helper,acho que element pouca servation e o mesmo vai ser continuation,vou postar uma resposta com ajax normal.Edita sua pergunta e coloca o controller,瓦伊·菲卡尔·马伊斯特!:这是一个没有seu控制器的应答器。新的连续扫描电镜功能:这是一个连续不断的问题:nao mostra o gráfico apenas…estranho esse山谷歌图表,Deficil hein。泰塔·乌萨罗·海查特,我是宁静的
function timePerProjectIssueTypeChart() {
if (!empty($this->request->data['projects'])) {
$id_project = $this->request->data['projects'];
$totalProject = $this->timeSpentPerProjectSpecific(10001, 'Registo.issuetype');
$timeSpent = $this->totalTimeSpentPerProject(10001);
//Setup data for chart
$timePerProjectIssueTypeChart = new GoogleChart();
$timePerProjectIssueTypeChart->type("PieChart");
$timePerProjectIssueTypeChart->options(array('title' => "Percentagem de Tempo (horas) investido em cada Tarefa",
'height' => 300, 'width' => 500));
$timePerProjectIssueTypeChart->columns(array(
//Each column key should correspond to a field in your data array
'issuetype' => array(
'type' => 'string',
'label' => 'Tipo Tarefa'
),
'tempoGasto' => array(
'type' => 'time',
'label' => '% horas'
)
));
//You can also use this way to loop through data and creates data rows:
foreach ($totalProject as $row) {
if ($timeSpent[0][0]['tempogasto'] != 0) {
$percentagemTempoGasto = ($this->timeToHour($row[0]['tempogasto']) / $timeSpent[0][0]['tempogasto']) * 100;
} else {
$percentagemTempoGasto = 0;
}
if (!empty($row['IssueType'])) {
$timePerProjectIssueTypeChart->addRow(array('tempoGasto' => $percentagemTempoGasto, 'issuetype' => $row['IssueType']['pname']));
} else {
$timePerProjectIssueTypeChart->addRow(array('tempoGasto' => $percentagemTempoGasto, 'issuetype' => 'Sem tarefa'));
}
}
//Set the chart for your view
$this->set('totalProject', $totalProject);
$this->set('timeSpent', $timeSpent);
$this->set(compact('timePerProjectIssueTypeChart'));
}
}
$(document).ready(function() {
$("#projectsTest").change(function(){
$.ajax({
type: 'POST',
data: { projects: $('#projectsTest').val()},
url: 'timePerProjectIssueTypeChart',
success: funcion() {
$("chart_div").load('timePerProjectIssueTypeChart');
}
})
})
});