SSH1+JfreeChart图表出不来
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import com.manager.ResultInterface;
import java.io.FileOutputStream;
import
java.io.IOException;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.chart.*;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.servlet.ServletUtilities;
import com.manager.ResultPict;
public class FindTeaScore extends Action{
private ResultInterface rp=null;
@Override
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
// 调用业务层方法totalTea()
String[] tea_no=rp.totalTea();
for(int i=0;i<tea_no.length;i++)
{
int[][]res=rp.result(tea_no[i]);
System.out.println("the length of res in action "+res.length);
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
for(int j=0;j<res.length;j++){
//各题的ABCD个数
dataset.addValue(res[j][0], tea_no[i], "A");
System.out.println(tea_no[i]+"--of number--第"+j+"题count A:--"+res[j][0]);
dataset.addValue(res[j][1], tea_no[i], "B");
dataset.addValue(res[j][2], tea_no[i], "C");
dataset.addValue(res[j][3], tea_no[i], "D");
// System.out.println("A count:"+res[j][0]);
}
// 创建类别图(Category)数据对象
JFreeChart chart=ChartFactory.createBarChart3D("teacherevaluation", "amout", "select", dataset, PlotOrientation.VERTICAL, true, true, true);
FileOutputStream fos_jpg = null;
try {
String dirpag=tea_no[i];
System.out.println("the sno is :"+dirpag);
fos_jpg = new FileOutputStream("./"+dirpag+".jpg"); // 图片的输出目录,以教师编号命名
ChartUtilities.writeChartAsJPEG(fos_jpg, 0.1f, chart, 800, 600, null);
} finally {
try {
fos_jpg.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
return mapping.findForward("success_pic");
}
public ResultInterface getRp() {
return rp;
}
public void setRp(ResultInterface rp) {
this.rp = rp;
}
}
------解决方案--------------------估计是没把图片导出到页面
------解决方案--------------------你现在全局定一个JFreeChart chart,