how can i generate something like this in a loop?:
$data = array(
'cols' => array(
array('id' => '', 'label' => 'Year', 'type' => 'string'),
array('id' => '', 'label' => 'diastolisch', 'type' => 'number'),
array('id' => '', 'label' => 'systolisch', 'type' => 'number')
),
'rows' => array(
array('c' => array(array('v' => '1990'), array('v' => 150), array('v' => 100))),
array('c' => array(array('v' => '1995'), array('v' => 300), array('v' => 50))),
array('c' => array(array('v' => '2000'), array('v' => 180), array('v' => 200))),
array('c' => array(array('v' => '2005'), array('v' => 400), array('v' => 100))),
array('c' => array(array('v' => '2010'), array('v' => 300), array('v' => 600))),
array('c' => array(array('v' => '2015'), array('v' => 350), array('v' => 400)))
)
);
$chart->load(json_encode($data));
im already rendering a table with the same data like this:
<?php foreach ($dataSets as $dataSet): ?>
<tr>
<td><?php echo $dataSet['DataSet']['id']; ?></td>
<td>
<?php echo $this->Html->link($dataSet['DataSet']['user_id'],
array('controller' => 'dataSets', 'action' => 'view', $dataSet['DataSet']['id'])); ?>
</td>
<td><?php echo $dataSet['DataSet']['created']; ?></td>
<td> <p><small><?php echo $dataSet['DataSet']['diastolisch']; ?></small></p></td>
<td> <p><small><?php echo $dataSet['DataSet']['systolisch']; ?></small></p></td>
<td> <p><small> <?php echo $dataSet['DataSet']['puls']; ?></small></p></td>
<td> <p><small><?php echo $dataSet['DataSet']['gewicht']; ?></small></p></td>
<td> <p><small><?php echo $dataSet['DataSet']['comment']; ?></small></p></td>
</tr>
<?php endforeach; ?>
<?php unset($dataSet); ?>
update:this is the loop for now, still not working
$rows = array();
$table = array();
$table['cols'] = array(
// Labels for your chart, these represent the column titles.
/*
note that one column is in "string" format and another one is in "number" format
as pie chart only required "numbers" for calculating percentage
and string will be used for Slice title
*/
array('id' => '', 'label' => 'Zeitpunkt', 'type' => 'string'),
array('id' => '', 'label' => 'diastolisch', 'type' => 'number'),
array('id' => '', 'label' => 'systolisch', 'type' => 'number')
);
/* Extract the information from $result */
foreach($dataSets as $r) {
$tempCreated[] = array('v' => $r['DataSet']['created']);
$tempSystolisch[] = array('v' => $r['DataSet']['systolisch']);
$tempDiastolisch[] = array('v' => $r['DataSet']['systolisch']);
$rows[] = array('c' => array(array('v' => $tempCreated), array('v' => $tempSystolisch), array('v' => $tempDiastolisch)));
}
$table['rows'] = $rows;
// convert data into JSON format
$chart->load(json_encode($table));