Note that there are some explanatory texts on larger screens.

plurals
  1. POCakePHP, Google Charts Plugin and JsHelper
    text
    copied!<p>i wish select an element of dropdownlist (choose a Project) and with JSHELPER (ajax) update the GRAPH that show statistics of this Project.</p> <p>I can choose the Project and through the 'POST' I can generate the array graph, but i cannot show the GRAPH. I tested without JSHELPER and show my Graph.</p> <p>MY VIEW CODE:</p> <pre><code> &lt;b&gt;ESCOLHA O PROJETO: &lt;/b&gt; &lt;?php echo $this-&gt;Form-&gt;select('projects', array($projects), array('multiple' =&gt; false, 'class' =&gt; 'span2', 'id' =&gt; 'projectsTest')); ?&gt; &lt;/br&gt; &lt;div id="chart_div" &gt; &lt;/div&gt; &lt;?php $this-&gt;Js-&gt;get('#projectsTest')-&gt;event('change', $this-&gt;Js-&gt;request(array( 'controller' =&gt; 'Registos', 'action' =&gt; 'timePerProjectIssueTypeChart' ), array( 'update' =&gt; '#chart_div', 'async' =&gt; true, 'method' =&gt; 'post', 'dataExpression' =&gt; true, 'data' =&gt; $this-&gt;Js-&gt;serializeForm(array( 'isForm' =&gt; true, 'inline' =&gt; true )) ))); </code></pre> <p>?> MY VIEW TIME_PER_PROJECT_ISSUE_TYPE_CHART</p> <pre><code>&lt;div id="chart_div" &gt; &lt;?php echo $this-&gt;GoogleChart-&gt;createJsChart($timePerProjectIssueTypeChart); ?&gt; &lt;/div&gt; </code></pre> <p>CONTROLLER</p> <pre><code> function timePerProjectIssueTypeChart() { if (!empty($this-&gt;request-&gt;data['projects'])) { $id_project = $this-&gt;request-&gt;data['projects']; $totalProject = $this-&gt;timeSpentPerProjectSpecific(10001, 'Registo.issuetype'); $timeSpent = $this-&gt;totalTimeSpentPerProject(10001); //Setup data for chart $timePerProjectIssueTypeChart = new GoogleChart(); $timePerProjectIssueTypeChart-&gt;type("PieChart"); $timePerProjectIssueTypeChart-&gt;options(array('title' =&gt; "Percentagem de Tempo (horas) investido em cada Tarefa", 'height' =&gt; 300, 'width' =&gt; 500)); $timePerProjectIssueTypeChart-&gt;columns(array( //Each column key should correspond to a field in your data array 'issuetype' =&gt; array( 'type' =&gt; 'string', 'label' =&gt; 'Tipo Tarefa' ), 'tempoGasto' =&gt; array( 'type' =&gt; 'time', 'label' =&gt; '% 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-&gt;timeToHour($row[0]['tempogasto']) / $timeSpent[0][0]['tempogasto']) * 100; } else { $percentagemTempoGasto = 0; } if (!empty($row['IssueType'])) { $timePerProjectIssueTypeChart-&gt;addRow(array('tempoGasto' =&gt; $percentagemTempoGasto, 'issuetype' =&gt; $row['IssueType']['pname'])); } else { $timePerProjectIssueTypeChart-&gt;addRow(array('tempoGasto' =&gt; $percentagemTempoGasto, 'issuetype' =&gt; 'Sem tarefa')); } } //Set the chart for your view $this-&gt;set('totalProject', $totalProject); $this-&gt;set('timeSpent', $timeSpent); $this-&gt;set(compact('timePerProjectIssueTypeChart')); } } </code></pre> <p>I do not put the code of the controllers, because individually tested and are working.</p> <p>Thanks</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload