日期:2014-05-19  浏览次数:20710 次

fusioncharts获取xml数据源路劲问题?
最近在研究fusioncharts报表,今天遇到一个问题很纠结,始终无法明确xml数据源的路径,忘高手指点:
后台:
public String showChart(){
try {
  //获得数据集
List<SaleNum> list = this.saleNumService.getSaleNum();
Document document = DocumentHelper.createDocument();
document.setXMLEncoding("utf-8");
Element eGraph = document.addElement("graph");
eGraph.addAttribute("caption", "sale") ;
eGraph.addAttribute("xAxisName", "mon");
eGraph.addAttribute("yAxisName", "Units");
eGraph.addAttribute("showNames", "1") ;
eGraph.addAttribute("decimalPrecision", "0");
eGraph.addAttribute("formatNumberScale","0") ;
for(int i = 0;i < list.size(); i++){
Element eSet = eGraph.addElement("set");
eSet.addAttribute("label", list.get(i).getMonth());
eSet.addAttribute("value", list.get(i).getNum().toString());
eSet.addAttribute("color", "17400") ;
}
String path = Address.getAddress();//path是tomcat\webapps\项目名称
Writer out = new FileWriter(path+"\\data.xml");
OutputFormat format = OutputFormat.createPrettyPrint(); 
format.setEncoding("UTF-8"); 
XMLWriter writer = new XMLWriter(out,format);
writer.write(document);
writer.close();
System.out.println("xml生成成功");
} catch (Exception e) {
System.out.println("xml生成失败");
e.printStackTrace();
}
return "showChart";
}

前台:
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
String path1 = System.getProperty("user.dir");
int num = path1.indexOf("\\bin");
String path2 = path1.substring(0,num);
out.println(path1+"\n");
out.println(path+"\n");
out.println(basePath);
out.println(path2);
String path3 = path2+"\\webapps\\ZZXJ2\\data.xml";
out.println(path3);
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
  <base href="<%=basePath%>">
   
  <title>chart1</title>
   
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">  
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
<script type="text/javascript" src="<%=request.getContextPath() %>/js/FusionCharts.js"></script>
  </head>
  
  <body>
  <div id="chartdiv" align="center">图形将出现在这个DIV里面,会覆盖文字</div>
  <script type="text/javascript">
  var myChart = new FusionCharts("<%=request.getContextPath()%>/FusionCharts/Column3D.swf","myChartId","600",&q