<?php

require_once './config/database.php';
$power_db = mysql_query("SELECT `U`, `I`, `P`,`time` FROM `power` ORDER BY `date` DESC, `time` DESC LIMIT 100");

$rows = array();
    //flag is not needed
    $flag = true;
    $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 column title
        array('label' => 'P', 'type' => 'string'),
        array('label' => 'time', 'type' => 'number')

    );

    $rows = array();
    while($r = mysql_fetch_assoc($power_db)) {
        $temp = array();
        // the following line will be used to slice the Pie chart
        $temp[] = array('v' => (int) $r['time']); 
        // Values of each slice
        $temp[] = array('v' => (int) $r['P']/10); 
        $rows[] = array('c' => $temp);
    }

    $table['rows'] = array_reverse($rows);
    echo json_encode($table);

