【发布时间】:2014-03-25 17:49:55
【问题描述】:
我有一个从 json 获取数据的谷歌条形图。它是月度客户流程图,它显示了一个月中的所有日期和相应的客户流量。现在我希望显示最大客户流量的栏以蓝色着色,其余部分为灰色。 例如:
^
| ...
|-----Grey--------
|-----Blue------------
|-----Grey----------
|-----Grey--------
|-----Grey----------
| ...
|__________________________________>
这是 json 的一部分:
$table = array();
$table['cols'] = array(
/* define your DataTable columns here
* each column gets its own array
* syntax of the arrays is:
* label => column label
* type => data type of column (string, number, date, datetime, boolean)
*/
// I assumed your first column is a "string" type
// and your second column is a "number" type
// but you can change them if they are not
array('label' => 'Dates as in '.$mon, 'type' => 'string'),
array('label' => 'Revenue', 'type' => 'number')
);
$rows = array();
while($r = mysql_fetch_assoc($query)) {
$temp = array();
// each column needs to have data inserted via the $temp array
$temp[] = array('v' => $r['date']);
$temp[] = array('v' => (int) $r['amount']); // typecast all numbers to the appropriate type (int or float) as needed - otherwise they are input as strings
// insert the temp array into $rows
$rows[] = array('c' => $temp);
}
// populate the table with rows of data
$table['rows'] = $rows;
// encode the table as JSON
$jsonTable = json_encode($table);
【问题讨论】:
标签: javascript php json google-api bar-chart