jfree生成饼图时出现java.lang.NoSuchMethodError错误

qiaoyue_0406 2012-11-22 04:56:10

import java.awt.Font;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;

import javax.imageio.ImageIO;

import org.apache.poi.hssf.usermodel.HSSFClientAnchor;
import org.apache.poi.hssf.usermodel.HSSFPatriarch;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PiePlot;
import org.jfree.chart.title.LegendTitle;
import org.jfree.chart.title.TextTitle;
import org.jfree.data.general.DefaultPieDataset;


/**
* 由JFreeChart生成图片放到硬盘上
* 对于Swing程序可以由org.jfree.chart.ChartUtilities类完成图片的生成
*
* @author
*
*/
public class BingXingTu {
private static FileOutputStream fileOut = null;
private static BufferedImage bufferImg = null;
//图片生成的路径
private static String pathOfPicture = "E:/poi/company.jpeg";
//Excel生成的路径
private static String pathOfExcel = "E:/poi/test.xls";
private static ByteArrayOutputStream handlePicture(String pathOfPicture) {
ByteArrayOutputStream byteArrayOut = new ByteArrayOutputStream();
try {
bufferImg = ImageIO.read(new File(pathOfPicture));
ImageIO.write(bufferImg, "jpeg", byteArrayOut);
} catch (IOException e) {
e.printStackTrace();
}
return byteArrayOut;
}
private static DefaultPieDataset getDataset() {
DefaultPieDataset dpd = new DefaultPieDataset();
//CategoryDataset dpd = new DefaultCategoryDataset();
dpd.setValue("管理人员", 25.0);
dpd.setValue("市场人员", 10.0);
dpd.setValue("开发人员", 50.0);
dpd.setValue("其它人员", 15.0);
return dpd;
}

public void pie(){
//JFreeChart画图
DefaultPieDataset dataset = getDataset();
JFreeChart chart = ChartFactory.createPieChart3D("某公司组织结构图", dataset, true, true, true);
chart.setTitle(new TextTitle("某公司组织结构图", new Font("仿宋", Font.BOLD, 20)));
LegendTitle legend = chart.getLegend(0);//图例
legend.setItemFont(new Font("隶书", Font.TYPE1_FONT, 16));
PiePlot plot = (PiePlot) chart.getPlot();//pieplot:饼形图
plot.setLabelFont(new Font("宋体", Font.HANGING_BASELINE, 12));
try {
OutputStream os = new FileOutputStream(pathOfPicture);
//OutputStream osExl = new FileOutputStream("测试.xls");
try {
// 由ChartUtilities生成文件到一个体outputStream中去
ChartUtilities.writeChartAsJPEG(os, chart, 1000, 800);
//ChartUtilities.writeChartAsJPEG(osExl, chart, 100, 80);
} catch (IOException e) {
e.printStackTrace();
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}

//处理图片文件,以便产生ByteArray
ByteArrayOutputStream handlePicture = new ByteArrayOutputStream();
handlePicture = handlePicture(pathOfPicture);
//创建一个工作簿
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("picture sheet");
HSSFPatriarch patriarch = sheet.createDrawingPatriarch();
HSSFClientAnchor anchor = new HSSFClientAnchor(0, 0, 100, 50, (short) 1, 1, (short) 10, 20);
//插入图片
patriarch.createPicture(anchor, wb.addPicture(handlePicture.toByteArray(), HSSFWorkbook.PICTURE_TYPE_JPEG));
//写入excel文件
try {
fileOut = new FileOutputStream(pathOfExcel);
wb.write(fileOut);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (fileOut != null) {
try {
fileOut.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
public static void main(String[] args) {
BingXingTu bing = new BingXingTu();
bing.pie();
}
}










//错误信息
Exception in thread "main" java.lang.NoSuchMethodError: org.jfree.ui.RectangleInsets.<init>(DDDD)V
at org.jfree.chart.plot.Plot.<clinit>(Plot.java:192)
at org.jfree.chart.ChartFactory.createPieChart3D(ChartFactory.java:486)
at BingXingTu.pie(BingXingTu.java:63)
at BingXingTu.main(BingXingTu.java:113)
...全文
186 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
qinzi_2013 2012-11-23
  • 打赏
  • 举报
回复
方法没找到!重启下试试
yjflinchong 2012-11-23
  • 打赏
  • 举报
回复
导入包了没。 有没有缺少jar包啊。 是明显的找不到方法。

51,409

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧