我正在尝试创建一个 JSON 对象来保存用于FLOT图表的数据。文档说数据格式应该是这样的点数组:
[ [1, 3], [2, 14.01], [3.5, 3.14] ]
我遇到的问题是我的 AJAX 调用返回一个 JSON 对象,其数据格式如下:
Rate: [96, 74, 73, 96, 124, 104]
Year: [2008, 2009, 2010, 2011, 2012, 2013]
有人可以解释我应该如何修改此代码,以便它创建 FLOT 图表所需的正确数据格式吗?谢谢。
function ajaxmuniChart1c(){
$muni = $this->input->POST('muni');
$q = $this->db->query("SELECT SaleYear AS Y, NewSaleType AS T, count(*) AS C, format((sum(SalePrice) / sum(Quantity1)),0) AS R FROM tblsales WHERE tblsales.SaleYear > 2007 AND tblsales.Quantity1 > 2000 AND (tblsales.NewSaleType = 'Industrial') AND tblsales.Municipality = '".$muni."' GROUP BY T,Y ORDER BY T,Y");
$json_SaleYear = array();
$json_AvrgRate = array();
foreach ($q->result_array() as $row){
$json_SaleYear[] = $row['Y'];
$json_AvrgRate[] = $row['R'];
}
$json['Year'] = $json_SaleYear;
$json['Rate'] = $json_AvrgRate;
echo json_encode($json);
exit;
}