private void BuildXMLDoc(Map<String, List<WebGameIncome>> map) throws IOException, JDOMException {
// 创建根节点 chart;
Element root = new Element("chart");
root.setAttribute("animation", "1");
root.setAttribute("showvalues", "0");
root.setAttribute("caption", "");
root.setAttribute("subcaption", "");
root.setAttribute("numberprefix", "");
root.setAttribute("chartrightmargin", "15");
root.setAttribute("xaxisname", "");
root.setAttribute("yaxisname", "");
root.setAttribute("pyaxisname", "");
root.setAttribute("canvasborderalpha", "0");
root.setAttribute("bgcolor", "FFFFFF");
root.setAttribute("bgratio", "0");
root.setAttribute("bgalpha", "50");
root.setAttribute("showalternatehgridcolor", "0");
root.setAttribute("numdivlines", "0");
root.setAttribute("showyaxisvalues", "0");
root.setAttribute("showlegend", "0");
root.setAttribute("chartleftmargin", "35");
root.setAttribute("charttopmargin", "25");
root.setAttribute("chartbottommargin", "35");
root.setAttribute("drawanchors", "0");
root.setAttribute("bordercolor", "970000");
root.setAttribute("borderalpha", "31");
root.setAttribute("stack100percent", "0");
root.setAttribute("linethickness", "3");
root.setAttribute("basefontsize", "12");
root.setAttribute("themename", "Custom");
// 根节点添加到文档中;
Document Doc = new Document(root);
Element category = new Element("categories");
Element dateSet1 = new Element("dataset");
dateSet1.setAttribute("seriesName", "kxd");
dateSet1.setAttribute("color_cc", "CE0000");
dateSet1.setAttribute("color", "CE0000");
Element dateSet2 = new Element("dataset");
dateSet2.setAttribute("seriesName", "income");
dateSet2.setAttribute("color_cc", "7F7F7F");
dateSet2.setAttribute("color", "7F7F7F");
for (Entry<String, List<WebGameIncome>> entry : map.entrySet()) {
List<WebGameIncome> value = entry.getValue();
if ((value.get(0) != null) && (value.get(0).getKxd() != 0)) {
category.addContent(new Element("category").setAttribute("label", entry.getKey()));
dateSet1.addContent(new Element("set").setAttribute("value", String.valueOf(value.get(0).getKxd())));
dateSet2.addContent(new Element("set").setAttribute("value", String.valueOf(value.get(0).getIncome())));
}
}
root.addContent(category);
root.addContent(dateSet1);
root.addContent(dateSet2);
XMLOutputter XMLOut = new XMLOutputter();
// 输出 Data.xml 文件;
XMLOut.output(Doc, new FileOutputStream(FileUtil.getXMLDataBasePath() + "/xmldata/Data.xml"));
}
生成Data.xml 文件
最新推荐文章于 2021-12-27 13:30:36 发布