Note that there are some explanatory texts on larger screens.

plurals
  1. POCakephp to Google Chart
    primarykey
    data
    text
    <p>In my controller I create the array to be charted </p> <pre><code>function chart() { $results = $this-&gt;Visit-&gt;query( "SELECT date(visits.created) as visit_date, Count(visits.id) AS count_visits FROM visits GROUP BY date(visits.created)" ); foreach($results AS $result) { $row = array( $result[0]['visit_date'], $result[0]['count_visits'] ); $chartData[] = json_encode($row); } pr($chartData); } </code></pre> <p>pr($chartData) gives following array</p> <pre><code>Array ( [0] =&gt; ["2012-07-11","5"] [1] =&gt; ["2012-07-13","1"] [2] =&gt; ["2012-07-14","1"] ) </code></pre> <p>in chart view i have </p> <pre><code>google.load('visualization', '1.0', {'packages':['corechart']}); google.setOnLoadCallback(drawChart); function drawChart() { // Create the data table. var data = google.visualization.arrayToDataTable($chartData); var options = { title: 'Visits by Date', hAxis: {title: 'Date', titleTextStyle: {color: 'black'}} }; var chart = new google.visualization.ColumnChart(document.getElementById('chart_div')); chart.draw(data, options); } </code></pre> <p>but this doesn't get me a chart .. no errors ... just no chart ..</p> <p>if I manually type in an array to test my view, it works fine ... eg if i replace .. </p> <pre><code>var data = google.visualization.arrayToDataTable($chartData); </code></pre> <p>with the following format from Google Chart example it generates a nice column chart</p> <pre><code> var data = google.visualization.arrayToDataTable([ ['Date', 'Count'], ['2012-07-11', 5], ['2012-07-13', 1], ['2012-07-14', 1] ]); </code></pre> <p>couple of questions: - how do i get the header titles in the var data array? - do double quotes or single quotes in array make a difference? - am i passing the array $chartData from php to Google chart javascript correctly? - the Google example has '[]' around the array, how do i get those around my array too? </p> <p>(bwt, i know all about cakephp's Find(all) but I just got lost in documentation about how to get what i wanted and sql was much easier )</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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