如何使用java poi或jfree jar在excel中创builddynamic柱形图

我需要在excel报告中创build一个dynamic的柱状图,并根据选定的date与2列值(销售额和保证金)进行比较。 已经使用poi的WriteableWork对象生成Excel报告了。 但我需要dynamic生成图表。

这个方法是创buildexcel报告

public String excelReport() throws ParseException, IOException { try { ByteArrayOutputStream bos = new ByteArrayOutputStream(); WritableWorkbook w = Workbook.createWorkbook(bos); WritableSheet sheet = w.createSheet("Page 1", 0); // Create Filename String filenameDate = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()); attachmentName = "attachment; filename=\"test".xls\"" ; int headerCol = 0; addBoldCell(sheet, headerCol++, 0, "Date"); addBoldCell(sheet, headerCol++, 0,"Sale"); addBoldCell(sheet, headerCol++, 0,"Margin"); int row = 1; int col = 0; addNumberCell(sheet, col++, row, date); addNumberCell(sheet, col++, row, 20000); addNumberCell(sheet, col++, row, 500); w.write(); w.close(); bufferSize = bos.size(); fileInputStream = new ByteArrayInputStream(bos.toByteArray()); } catch (Exception e) { log.warn("Error creating an Excel file.", e); } finally { if (out != null) { out.close(); } } } return SUCCESS; } 

在struts.xml中

 <action name="excelReport" method="excelReport" class="com.test.action.ReportAction"> <result name="success" type="stream"> <param name="contentType">application/vnd.ms-excel</param> <param name="contentDisposition">${attachmentName}</param> <param name="inputName">fileInputStream</param> <param name="bufferSize">${bufferSize}</param> </result> </action> 

Excel报告,我成功地获得,我想图表这个Excel值如下面的示例图表

在这里输入图像说明

我尝试了一些poi和jfree样本,但没有得到解决scheme。