我正在尝试使用库 amchart 我尝试遵循站点的示例,它适用于静态数据我想知道如何使用动态数据(即数据库实例)制作图表?谁可以帮助我 http://www.amcharts.com/javascript-charts/stacked-column/
问问题
1780 次
2 回答
0
查看这个库:http
://amcharts-php.sourceforge.net/
我相信还有更多的库,或者您可以自己编写一个。
于 2012-12-06T08:36:45.983 回答
0
在您的 servlet 标头中定义 response.setContentType("application/json");
以 JSON 格式创建数据,例如
StringBuffer sb=new StringBuffer();
sb.append("[");
if(rs1.next()){
sb.append("{");
sb.append("\"country\": \"CH\",");
sb.append("\"visits\":\""+rs1.getString(1)+"\",");
sb.append("\"color\":\""+"#FF0F00"+"\"");
sb.append("},");
sb.append("{");
sb.append("\"country\": \"USA\",");
sb.append("\"visits\":\""+rs1.getString(2)+"\",");
sb.append("\"color\":\""+"#FF6600"+"\"");
sb.append("},");
sb.append("{");
sb.append("\"country\": \"UK\",");
sb.append("\"visits\":\""+rs1.getString(3)+"\",");
sb.append("\"color\":\""+"#FF9E01"+"\"");
sb.append("},");
sb.append("{");
sb.append("\"country\": \"AU\",");
sb.append("\"visits\":\""+rs1.getString(4)+"\",");
sb.append("\"color\":\""+"#FCD202"+"\"");
sb.append("},");
sb.append("{");
sb.append("\"country\": \"DK\",");
sb.append("\"visits\":\""+rs1.getString(5)+"\",");
sb.append("\"color\":\""+"#F8FF01"+"\"");
sb.append("},");
sb.append("{");
sb.append("\"country\": \"PK\",");
sb.append("\"visits\":\""+rs1.getString(6)+"\",");
sb.append("\"color\":\""+"#B0DE09"+"\"");
sb.append("},");
sb.append("{");
sb.append("\"country\": \"ML\",");
sb.append("\"visits\":\""+rs1.getString(7)+"\",");
sb.append("\"color\":\""+"#04D215"+"\"");
sb.append("},");
sb.append("{");
sb.append("\"country\": \"JP\",");
sb.append("\"visits\":\""+rs1.getString(8)+"\",");
sb.append("\"color\":\""+"#0D8ECF"+"\"");
sb.append("},");
sb.append("{");
sb.append("\"country\": \"IN\",");
sb.append("\"visits\":\""+rs1.getString(9)+"\",");
sb.append("\"color\":\""+"#0D52D1"+"\"");
sb.append("},");
sb.append("{");
sb.append("\"country\": \"TW\",");
sb.append("\"visits\":\""+rs1.getString(10)+"\",");
sb.append("\"color\":\""+"#2A0CD0"+"\"");
sb.append("}");
}
sb.append("]");
然后做out.write(sb.toString());
然后在 html 文件中从请求对象中获取数据 var test=JSON.parse(xmlhttp.responseText);
记得我在这个中使用过 Ajax ....
于 2013-02-12T06:02:44.130 回答