RSS

JFREECHART – 自己做了一个小的笔记程序

15 Mar
看的是JFreeChat0.96那个版本:

这里采用的是级联菜单,比如选择左边的select,右边会列出对应的选项.源代码在这里

/**
*Author:Finchan
*Date:15 Mar,2007
*Description:Static Text Definition
*/
function $(identifier){
return document.getElementById(identifier);
}
var subdetails = {
“chap4″:[[“4-2-5”,“c425”]],
“chap5″:[[“5-2-2”,“c522”],[“5-2-5”,“c525”]]
};
var CascadeMenu = {
“showSubMenu”:function(parentID){
var subSelectNode = $(“subchapter”);
var temp = subSelectNode.options;
temp.length = 0;
var subMenuArray = [];
for(var prop in subdetails){
if(parentID == prop){
subMenuArray = subdetails[prop];
break;
}
}
this.dealtWithSelectDom(subMenuArray,temp);
},
“dealtWithSelectDom”:function(arrayCatogory,tempo){
for(var j=0;j
tempo.add(new Option(arrayCatogory[j][0],arrayCatogory[j][1]));
}
}
};

这是表单部分:

Servlet 部分代码如下:
public class ServletDemo extends HttpServlet {
public ServletDemo() {
}
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException,IOException {
String chartRequest = request.getParameter(“subchapter”);
Configuration config = new Configuration();
Map map = config.getMap();
JFreeChart chart = null;
for (int i = 0; i < map.size(); i++) {
if (map.containsKey(chartRequest)) {
String clazz = (String) map.get(chartRequest);
System.out.println(clazz);
try {
Factory factory = (Factory) Class.forName(clazz).newInstance();
chart = factory.makeGraphics();
} catch (Exception e) {
e.printStackTrace();
}
}
}
try {
OutputStream out = response.getOutputStream();
response.setContentType(“image/png”);
ChartUtilities.writeChartAsPNG(out, chart, 400, 300);
} catch (Exception e) {
System.err.println(e.toString());
} finally {
// out.close();
}
}
}

Configuration代码如下:

publicclass Configuration {

    public Map map =new HashMap();
    public Configuration(){ map.put(“c425”,“com.jean.chart.chapter4.First”); }

    public Map getMap(){ return map; }
}

Factory代码如下:

publicinterface Factory {
    public JFreeChart makeGraphics();
}

First代码如下:

public class First implements Factory{

public JFreeChart makeGraphics(){
DefaultPieDataset data = new DefaultPieDataset();
data.setValue(“Category 1″, 43.2);
data.setValue(“Category 2″, 27.9);
data.setValue(“Category 3″, 79.5);
JFreeChart chart = ChartFactory.createPieChart(
“Sample Pie Chart”,
data,
true, // legend
true, // tooltips
false // URLs
);
return chart;
}
}

Advertisements
 
Leave a comment

Posted by on 03/15/2007 in JREECHART

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

 
%d bloggers like this: