$jsonb = array();
foreach($em as $k => $v) {
$q = "
SELECT a.STATE ,
COALESCE(b.count, 0) AS Count
FROM
(
SELECT 'done' AS STATE
UNION
SELECT 'open' AS STATE
UNION
SELECT 'pending' AS STATE
UNION
SELECT 'draft' AS STATE
UNION
SELECT 'cancel' AS STATE
) a LEFT JOIN
(
SELECT STATE ,
count(*) AS count
FROM crm_lead
WHERE (create_date, create_date) OVERLAPS ('2012-{$nn}-01'::DATE, '2012-{$nn}-{$num}'::DATE)
GROUP BY STATE
) b ON a.STATE = b.STATE
";
$result = retrieve($q);
$jsona = array();
$values = array();
$ev = array();
foreach($result as $key => $val) {
$ev[] = $val['count'];
}
$jsonb[] = array("label" => $v,"values" =>$ev);
}
$jsona[] = array("label" => array(done,open,pending,draft,cancel),"values" => $jsonb);
这是构造要返回给 JavaScript 的 JSON 对象的完整代码。附言。此代码包含一些不重要的自定义函数,您可能会猜到它们的值。