我正在尝试使用库amchart我试图遵循网站的示例,它适用于静态数据我想知道如何用动态数据制作图表,即数据库实例?谁能帮我 http://www.amcharts.com/javascript-charts/stacked-column/
答案 0 :(得分:0)
查看此库:http://amcharts-php.sourceforge.net/
我相信有更多的图书馆,或者你可以自己写一个。
答案 1 :(得分:0)
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 ....