我正在使用http://www.jqplot.com/tests/pie-donut-charts.php它需要以以下格式提供数据:
//JavaScript
var data = [
['Heavy Industry', 12],['Retail', 9], ['Light Industry', 14],
['Out of home', 16],['Commuting', 7], ['Orientation', 9]
];
数据是用PHP在服务器端生成的。我手动创建字符串如下:
//PHP
$string.='["'.$row['name'].'",'.$row['count'].'],';
我宁愿只创建一个数组,然后使用json_encode()或类似的方法来创建数据。有什么建议吗?
$array = array(
array(
"Heavy Industry",
12
),
array(
"Retail",
9
)
);
$json = json_encode($array);
var_dump($json); // "[["Heavy Industry",12],["Retail",9]]"