xiangjinqi 发表于 2013-1-29 09:30:01

funsionchart利用zoomline现实报表信息,将数据转为XML流--JAVA

1、界面

 
<div id="chart1div"></div>javascript脚本:

 
var chart1 = new FusionCharts("<%=request.getContextPath()%>/FusionCharts/ZoomLine.swf", "0", "1000", "600", "0", "1");         chart1.setDataXML(srcHtml);         chart1.render("chart1div");     
2、XML类

package com.yihaodian.pis.util; import java.io.IOException;import org.dom4j.Document;import org.dom4j.DocumentHelper;import org.dom4j.Element;/*** 使用dom4j生成XML工具类*   * @author 向旗*   */public class XMLUtil {      private Document document = null;      public Document getDocument() {          return document;      }      /**      * 构造方法,初始化Document      */      public XMLUtil() {          document = DocumentHelper.createDocument();      }      /**      * 生成根节点      *       * @param rootName      * @return      */      public Element addRoot(String rootName) {         Element root = document.addElement(rootName);          return root;      }      /**      * 生成节点      *       * @param parentElement      * @param elementName      * @return      */      public Element addNode(Element parentElement, String elementName) {          Element node = parentElement.addElement(elementName);          return node;      }      /**      * 为节点增加一个属性      *       * @param thisElement      * @param attributeName      * @param attributeValue      */      public void addAttribute(Element thisElement, String attributeName,            String attributeValue) {          thisElement.addAttribute(attributeName, attributeValue);      }      /**      * 为节点增加多个属性      *       * @param thisElement      * @param attributeNames      * @param attributeValues      */      public void addAttributes(Element thisElement, String[] attributeNames, String[] attributeValues) {          for (int i = 0; i < attributeNames.length; i++) {            thisElement.addAttribute(attributeNames, attributeValues);          }      }      /**      * 增加节点的值      *       * @param thisElement      * @param text      */      public void addText(Element thisElement, String text) {          thisElement.addText(text);      }      /**      * 获取最终的XML      *       * @return      * @throws IOException   */      public String getXML() {          return document.asXML().substring(39);      }}  
3、JAVA增加XML节点内容

 
XMLUtil xml = new XMLUtil();      Element graph = xml.addRoot("graph");      xml.addAttribute(graph, "caption", "CPI Category Report");      // xml.addAttribute(graph, "subCaption", "消费者物价指数种类报告");      xml.addAttribute(graph, "basefontsize", "12");      xml.addAttribute(graph, "yAxisName", "价格CPI报表");      xml.addAttribute(graph, "decimalPrecision", "2");// 小数精确度,0为精确到个位      xml.addAttribute(graph, "showValues", "0");// 在报表上不显示数值      xml.addAttribute(graph, "hovercapbg", "FFECAA");      xml.addAttribute(graph, "hovercapborder", "F47E00");      xml.addAttribute(graph, "animation", "1");      xml.addAttribute(graph, "numdivlines", "4");      xml.addAttribute(graph, "numVdivlines", "0");      xml.addAttribute(graph, "numVdivlines", "0");      xml.addAttribute(graph, "yaxisminvalue", "1000");      xml.addAttribute(graph, "yaxismaxvalue", "1800");      xml.addAttribute(graph, "lineThickness", "3");      xml.addAttribute(graph, "rotateNames", "1");      xml.addAttribute(graph, "numberSuffix", "%");增加种类:Element categories = xml.addNode(graph, "categories");      for (int i = 0; i < datelen; i++) {            Element category = xml.addNode(categories, "category");            category.addAttribute("name", (new Date(dateMinDate.getTime() + i                  * 24 * 60 * 60 * 1000)).toString());      }增加种类对应的数据:Element dataset = xml.addNode(graph, "dataset");                  xml.addAttribute(                            dataset,                            "color",                            Integer.toString(                                    (int) (Math.random() * 255 * 255 * 255))                                    .toUpperCase());                  xml.addAttribute(dataset, "showValue", "1");                  xml.addAttribute(dataset, "alpha", "100");                  xml.addAttribute(dataset, "anchorAlpha", "0");                  xml.addAttribute(dataset, "lineThickness", "2");                  xml.addAttribute(dataset, "seriesname", catNameStrs);                                    for (int m = 0; m < datelen; m++) {                        Elementset= xml.addNode(dataset, "set");                  } 4.关于传参的问题

传到JAVASCRIPT一方面利用AJAX传参,另一方面利用文本,
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd "> <html xmlns="http://www.w3.org/1999/xhtml "> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Fusion Chart Test</title> <script type="text/javascript" src="FusionCharts.js"></script> <script type="text/javascript"> function show(){var xml = document.getElementById("test").value;alert(xml);    var chart = new FusionCharts("ZoomLine.swf", "0", "800", "600",0,0);   chart.setDataXML(xml);   chart.render("chartDiv"); }    </script></head> <body> <div id="chartDiv"></div> <input type="text" size="500" id="test"/> <input type="button"value="show"/></body> </html>
页: [1]
查看完整版本: funsionchart利用zoomline现实报表信息,将数据转为XML流--JAVA