google visualization - Creating a zend project to generate googlecharts -


hi, i'm working on zend project generate graphs using google charts api uses values database views tables, year , months "jan dec" values below them. below scripts. works fine when click link output graphs: code back..in form of array , not visual chart.

['year', 'month', ''value'], ['2008","january,'65], ['2008","february,'56], ['2008","march,'78], ['2008","april,'3], ['2008","may,'67], ['2008","june,'34], ['2008","july,'74], ['2008","august,'85], ['2008","september,'97], ['2008","october,'57], ['2008","november,'58], ['2008","december,'34]   

what doing wrong? please

indexcontroller.php <?php  class indexcontroller extends zend_controller_action {      public function init()     {         /* initialize action controller here */     }      public function indexaction()    {     $yearlyreport = new application_model_dbtable_yearlyreport();     $this->view->yearlyreport = $yearlyreport->fetchall();     }      public function generategraphaction()    {     //$yearlyreport = new application_model_dbtable_yearlyreport();     //$this->view->yearlyreport = $yearlyreport->fetchall();       //$this->user();       //get id param index.phtml (view)      $id = $this->getrequest()->getparam('id');      //get model , query $i      $yearlyreport = new application_model_dbtable_yearlyreport();      $row = $yearlyreport->getyearlyreport($id);      //assign data model view [edit](display.phtml)      $this->view->yearlyreport = $yearlyreport;     /*create dtring of form:     * var data = google.visualization.arraytodatatable([       ['year', 'sales', 'expenses'],       ['2004',  1000,      400],       ['2005',  1170,      460],       ['2006',  660,       1120],       ['2007',  1030,      540]       ]);     *      */     $data = "['year', 'month', ''value'],             ['" . $row['year'] . '","' . 'january' . ",'" .    $row['january'] . "],             ['" . $row['year'] . '","' . 'february' . ",'" . $row['february'] . "],             ['" . $row['year'] . '","' . 'march' . ",'" . $row['march'] . "],             ['" . $row['year'] . '","' . 'april' . ",'" . $row['april'] . "],             ['" . $row['year'] . '","' . 'may' . ",'" . $row['may'] . "],             ['" . $row['year'] . '","' . 'june' . ",'" . $row['june'] . "],             ['" . $row['year'] . '","' . 'july' . ",'" . $row['july'] . "],             ['" . $row['year'] . '","' . 'august' . ",'" . $row['august'] . "],             ['" . $row['year'] . '","' . 'september' . ",'" . $row['september'] . "],             ['" . $row['year'] . '","' . 'october' . ",'" . $row['october'] . "],             ['" . $row['year'] . '","' . 'november' . ",'" . $row['november'] . "],             ['" . $row['year'] . '","' . 'december' . ",'" . $row['december'] . "],";         $this->view->data = $data;      }  } ?>  generategraph.phtml <?php echo $this->doctype(); echo $this->data; ?>  <html>   <head>     <script type="text/javascript" src="https://www.google.com/jsapi"></script>    <script type="text/javascript">   google.load("visualization", "1", {packages:["corechart"]});   google.setonloadcallback(drawchart);   function drawchart() {     var data = <?php echo $this->data; ?>      var options = {       title: 'generate',       vaxis: {title: 'year',  titletextstyle: {color: 'red'}}     };      var chart = new google.visualization.barchart(document.getelementbyid('chart_div'));        chart.draw(data, options);   } </script> </head> <body> <div id="chart_div" style="width: 900px; height: 500px;"></div>  </body> </html>   yearlyreport.php "models" <?php  class application_model_dbtable_yearlyreport extends zend_db_table_abstract {   protected $_name = 'yearlyreport';  public function getyearlyreport($id) {     $id = (int)$id;     $row = $this->fetchrow('id =' . $id);     if (!$row) {         throw new exception("could not find row $id");     }     return $row->toarray(); }           public function generategraph($year, $january, $february, $march, $april, $may, $june, $july, $august, $september, $october, $november, $december )  {     $data = array(     'year' => $year,     'january' => $january,     'february' => $february,     'march' => $march,     'april' => $april,     'may' => $may,     'june' => $june,     'july' => $july,     'august' => $august,     'september' => $september,     'october' => $october,     'november' => $november,     'december' => $december,     );      $this->generategraph($data);   }      }   index.phtml     <?php $this->title = "yearlyreports"; $this->headtitle($this->title); ?>    <table> <tr>     <th>year</th>     <th>january</th>     <th>february</th>     <th>march</th>     <th>april</th>     <th>may</th>     <th>june</th>     <th>july</th>     <th>august</th>     <th>september</th>     <th>october</th>     <th>november</th>     <th>december</th>     <th>&nbsp;</th>  </tr> <?php foreach ($this->yearlyreport $yearly) : ?>      <tr>         <td><?php echo $this->escape($yearly->year); ?></td>         <td><?php echo $this->escape($yearly->january); ?></td>         <td><?php echo $this->escape($yearly->february); ?></td>         <td><?php echo $this->escape($yearly->march); ?></td>         <td><?php echo $this->escape($yearly->april); ?></td>         <td><?php echo $this->escape($yearly->may); ?></td>         <td><?php echo $this->escape($yearly->june); ?></td>         <td><?php echo $this->escape($yearly->july); ?></td>         <td><?php echo $this->escape($yearly->august); ?></td>         <td><?php echo $this->escape($yearly->september); ?></td>         <td><?php echo $this->escape($yearly->october); ?></td>         <td><?php echo $this->escape($yearly->november); ?></td>         <td><?php echo $this->escape($yearly->december); ?></td>          <td>               <a href="<?php echo  $this->url(array('controller'=>'index', 'action'=>'generategraph', 'id'=>$yearly->id));?>">generategraph</a>         </td>            </tr>          <?php endforeach; ?>   </table> 

when using barchart, requires 2 columns of data: label , value.

so change $data variable following:

$data = "['month', 'value'], ['january'," . $row['january'] . "], ['february'," . $row['february'] . "], ['march'," . $row['march'] . "], ['april'," . $row['april'] . "], ['may'," . $row['may'] . "], ['june'," . $row['june'] . "], ['july'," . $row['july'] . "], ['august'," . $row['august'] . "], ['september'," . $row['september'] . "], ['october'," . $row['october'] . "], ['november'," . $row['november'] . "], ['december'," . $row['december'] . "]"; 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -

php - Accessing static methods using newly created $obj or using class Name -