FusionCharts学习之基础篇

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>this is my First Charts</title>
<script language="JavaScript" src="FusionCharts/JS/FusionCharts.js"></script>
<script type="text/javascript" src="js/jquery-1.8.2.js"></script>
<script type="text/javascript">
	function showFusionCharts(){
 		var myChart = new FusionCharts("FusionCharts/Charts/Pie3D.swf", "myChartId", "800", "480");
 		$.ajax({               
            type: "POST",               
            dataType: "text",               
            url: 'getTestJSON',   
            success: function(data) {   
                alert(data);
                //myChart.setDataURL("Data.xml");
                myChart.setDataXML(data);
                myChart.render("chartdiv");
            }   
        });  
    }
</script>
</head>
<body onload="showFusionCharts();">
<div id="chartdiv"></div>
</body>
</html>

 

/**
	 * @author chenzheng
	 * @since 2013-8-4
	 * @Description: FusionCharts测试
	 * @throws
	 * @return
	 * @throws Exception
	 * String
	 */
	public String getTestJSON() throws Exception {
		String dataxml="<chart caption='my First Charts'>"
			+"<set name='Jan' value='462' />"
			+"<set name='Feb' value='857' />"
			+"<set name='Mar' value='671' />"
			+"<set name='Apr' value='494' />"
			+"<set name='May' value='761' />"
			+"<set name='Jun' value='960' />"
			+"<set name='Jul' value='629' />"
			+"<set name='Aug' value='622' />"
			+"<set name='Sep' value='376' />"
			+"<set name='Oct' value='494' />"
			+"<set name='Nov' value='761' />"
			+"<set name='Dec' value='960' />"
			+"</chart>";
		HttpServletResponse response = ServletActionContext.getResponse();
		response.setCharacterEncoding("utf-8");
		PrintWriter pw = null;
		try {
			pw = response.getWriter();
			pw.write(dataxml);
		} catch (IOException e) {
			e.printStackTrace();
		}
		pw.flush();
		pw.close();
		return null;
	}

 

你可能感兴趣的:(FusionCharts)