我有以下数据。 如何使用它创建条形图和饼图?
Fiscal Year Total Budget Average Budget Number of States Reporting Average Budget % Change
2001-2002 $81,337,970 $77,365,083 $8 11.00%
2002-2003 $78,329,957 $59,330,670 $93 7.00%
我是jQuery的新手,我需要在jQuery中完成。
答案 0 :(得分:0)
http://www.1stwebdesigner.com/css/top-jquery-chart-libraries-interactive-charts/
您通常必须将json数据放入这些图表中:
JSON(JavaScript Object Notification)是配对值键的哈希值。
所以例如:
var data = [
{
"period" : "2001-2002",
"totalBudget" : 81337970,
"avgBudget" : 77365083,
"numberStates" : 8,
"avgBudgetChange" : 11.00
},
{
"period" : "2002-2003",
"totalBudget" : 78329957,
"avgBudget" : 58330670,
"numberStates" : 93,
"avgBudgetChange" : 7.00
}
]
要访问特定数据:data[0].period //will output "2001-2002"
如果必须从服务器端获取这些数据:
例如,使用PHP,您首先需要使用函数json_encode(data); // will encode an array into json
将数组编码为json
http://php.net/manual/en/function.json-encode.php
然后执行XMLHttpRequest:http://api.jquery.com/jQuery.post/,http://api.jquery.com/jQuery.get/,http://api.jquery.com/jQuery.ajax/
然后根据您使用的图表库制作图表,添加一些选项。
希望它有所帮助。