1.雷达图
第一步:生成jfreechart
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
String group1 = "huawei ";
dataset.addValue(5, group1, "w1");
dataset.addValue(6, group1, "w2");
dataset.addValue(4, group1, "w3");
dataset.addValue(2, group1, "w4");
dataset.addValue(5, group1, "w5");
dataset.addValue(5, group1, "w6");
dataset.addValue(5, group1, "w7");
dataset.addValue(8, group1, "w8");
group1 = "apple ";
dataset.addValue(2, group1, "w1");
dataset.addValue(4, group1, "w2");
dataset.addValue(4, group1, "w3");
dataset.addValue(5, group1, "w4");
dataset.addValue(5, group1, "w5");
dataset.addValue(8, group1, "w6");
dataset.addValue(9, group1, "w7");
dataset.addValue(8, group1, "w8");
SpiderWebPlot spiderwebplot = new SpiderWebPlot(dataset);
JFreeChart jfreechart = new JFreeChart("Test", TextTitle.DEFAULT_FONT, spiderwebplot, false);
LegendTitle legendtitle = new LegendTitle(spiderwebplot);
legendtitle.setPosition(RectangleEdge.TOP);
jfreechart.addSubtitle(legendtitle);
第二步:转为图片
ByteArrayOutputStream out = new ByteArrayOutputStream();
ChartUtilities.writeChartAsPNG(out, jfreechart, 400, 500);
第三步:通过poi 写入表格
ByteArrayOutputStream byteArrayOut = out;
// 画图的顶级管理器,一个sheet只能获取一个(一定要注意这点)
HSSFPatriarch patriarch = sheet.createDrawingPatriarch();
// anchor主要用于设置图片的属性
sheet.setDefaultRowHeightInPoints(30);
HSSFClientAnchor anchor = new HSSFClientAnchor(0, 0, 255, 255, (short) 1, 1, (short)8 , 25);
anchor.setAnchorType(3);
// 插入图片
patriarch.createPicture(anchor, wb.addPicture(byteArrayOut.toByteArray(), HSSFWorkbook.PICTURE_TYPE_PNG));
附件下载地址:
http://download.csdn.net/download/u012442381/9928440