掲示板
Images are not displayed for Jasper report with a pie chart JRHtmlExporter
16年前 に kumar vel によって更新されました。
Images are not displayed for Jasper report with a pie chart JRHtmlExporter
New Member 投稿: 4 参加年月日: 07/10/21 最新の投稿
Hi ,
I am generating a Jasper report with the JRHtmlExporter. The image of the pie chart are not displayed.
But the text outputs are diplayed in the report. Pls find the below code which is being used and le me know any issue/suggestion on the below code.
public class ViewJasperReport extends PortletAction {
public ActionForward render(ActionMapping mapping, ActionForm form, PortletConfig config, RenderRequest req, RenderResponse res) throws Exception {
String reportName = req.getParameter("report_name");
reportName = System.getProperty("user.dir")+"\\"+reportName;
System.out.println("PWD"+System.getProperty("user.dir"));
Connection connection;
try
{
res.setContentType("text/html");
PrintWriter out = res.getWriter();
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
connection = DriverManager.getConnection("jdbc:odbc:EmployeeData","","");
ServletContext context = this.getServlet().getServletContext();
File reportFile = new File(context.getRealPath("/html/portlet/ext/library/Untitled_report_4.jasper"));
HashMap parameters = new HashMap();
parameters.put("employeeChart", new Boolean(true));
parameters.put("BaseDir", reportFile.getParentFile());
System.out.println("creating report...");
JasperPrint jasperPrint = null;
System.out.println("reportFile.getPath() = " + reportFile.getPath());
JasperReport jasperReport = (JasperReport)JRLoader.loadObject(reportFile.getPath());
System.out.println("got jasper report...");
//create JasperPrint using fillReport() method
jasperPrint = JasperFillManager.fillReport(jasperReport, parameters,connection);
System.out.println("got jasper print");
JRHtmlExporter exporter = new JRHtmlExporter();
PortletSession session = req.getPortletSession();
Map imagesMap = new HashMap();
session.setAttribute("IMAGES_MAP", imagesMap, PortletSession.APPLICATION_SCOPE);
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
exporter.setParameter(JRExporterParameter.OUTPUT_WRITER, out);
exporter.setParameter(JRHtmlExporterParameter.IS_USING_IMAGES_TO_ALIGN, Boolean.TRUE);
exporter.setParameter(JRHtmlExporterParameter.IS_OUTPUT_IMAGES_TO_DIR, Boolean.FALSE);
exporter.setParameter(JRHtmlExporterParameter.IMAGES_MAP, imagesMap);
exporter.setParameter(JRHtmlExporterParameter.HTML_HEADER, "");
exporter.setParameter(JRHtmlExporterParameter.HTML_FOOTER, "");
exporter.setParameter(JRHtmlExporterParameter.IMAGES_URI, "/report/image?image=");
exporter.exportReport();
}catch(Exception e){
e.printStackTrace();
}
}
}
I tried with jrxml file also. still the images are not seen.
I am generating a Jasper report with the JRHtmlExporter. The image of the pie chart are not displayed.
But the text outputs are diplayed in the report. Pls find the below code which is being used and le me know any issue/suggestion on the below code.
public class ViewJasperReport extends PortletAction {
public ActionForward render(ActionMapping mapping, ActionForm form, PortletConfig config, RenderRequest req, RenderResponse res) throws Exception {
String reportName = req.getParameter("report_name");
reportName = System.getProperty("user.dir")+"\\"+reportName;
System.out.println("PWD"+System.getProperty("user.dir"));
Connection connection;
try
{
res.setContentType("text/html");
PrintWriter out = res.getWriter();
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
connection = DriverManager.getConnection("jdbc:odbc:EmployeeData","","");
ServletContext context = this.getServlet().getServletContext();
File reportFile = new File(context.getRealPath("/html/portlet/ext/library/Untitled_report_4.jasper"));
HashMap parameters = new HashMap();
parameters.put("employeeChart", new Boolean(true));
parameters.put("BaseDir", reportFile.getParentFile());
System.out.println("creating report...");
JasperPrint jasperPrint = null;
System.out.println("reportFile.getPath() = " + reportFile.getPath());
JasperReport jasperReport = (JasperReport)JRLoader.loadObject(reportFile.getPath());
System.out.println("got jasper report...");
//create JasperPrint using fillReport() method
jasperPrint = JasperFillManager.fillReport(jasperReport, parameters,connection);
System.out.println("got jasper print");
JRHtmlExporter exporter = new JRHtmlExporter();
PortletSession session = req.getPortletSession();
Map imagesMap = new HashMap();
session.setAttribute("IMAGES_MAP", imagesMap, PortletSession.APPLICATION_SCOPE);
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
exporter.setParameter(JRExporterParameter.OUTPUT_WRITER, out);
exporter.setParameter(JRHtmlExporterParameter.IS_USING_IMAGES_TO_ALIGN, Boolean.TRUE);
exporter.setParameter(JRHtmlExporterParameter.IS_OUTPUT_IMAGES_TO_DIR, Boolean.FALSE);
exporter.setParameter(JRHtmlExporterParameter.IMAGES_MAP, imagesMap);
exporter.setParameter(JRHtmlExporterParameter.HTML_HEADER, "");
exporter.setParameter(JRHtmlExporterParameter.HTML_FOOTER, "");
exporter.setParameter(JRHtmlExporterParameter.IMAGES_URI, "/report/image?image=");
exporter.exportReport();
}catch(Exception e){
e.printStackTrace();
}
}
}
I tried with jrxml file also. still the images are not seen.
16年前 に kumar v によって更新されました。
RE: Images are not displayed for Jasper report with a pie chart JRHtmlExpor
New Member 投稿: 4 参加年月日: 07/10/21 最新の投稿
Will Liferay support on-fly Jasper report with Pie/bar chart???
16年前 に Roman Hoyenko によって更新されました。
RE: Images are not displayed for Jasper report with a pie chart JRHtmlExpor
Liferay Master 投稿: 878 参加年月日: 07/10/08 最新の投稿
well, most likely the path to images is incorrect. Look what is the path referenced in Liferay and try to fix it.
I guess it is obvious, can't help you more with the details - I don't use Jasper.
I guess it is obvious, can't help you more with the details - I don't use Jasper.
16年前 に kumar v によって更新されました。
RE: Images are not displayed for Jasper report with a pie chart JRHtmlExpot
New Member 投稿: 4 参加年月日: 07/10/21 最新の投稿
Thanks Roman, I am able to display the image after storing it in an absolute path.
File reportFile1 = new File(context.getRealPath("/html/portlet/ext/library/"));
String destino = reportFile1.getPath();
exporter.setParameter(JRHtmlExporterParameter.IMAGES_DIR_NAME,destino);
exporter.setParameter(JRHtmlExporterParameter.IMAGES_URI,destino + "/");
IS there any way to export(view) the report without storing the images???
File reportFile1 = new File(context.getRealPath("/html/portlet/ext/library/"));
String destino = reportFile1.getPath();
exporter.setParameter(JRHtmlExporterParameter.IMAGES_DIR_NAME,destino);
exporter.setParameter(JRHtmlExporterParameter.IMAGES_URI,destino + "/");
IS there any way to export(view) the report without storing the images???
10年前 に pradeep pandey によって更新されました。
RE: Images are not displayed for Jasper report with a pie chart JRHtmlExpor
New Member 投稿: 5 参加年月日: 14/02/28 最新の投稿
Hi Kumar ,
I am also facing same issue while exporting Bar chart in liferay,report is coming on page but chart image is not coming Plz look into below code:
and let me know where i m wrong.
web.xml:
<servlet>
<servlet-name>ImageServlet</servlet-name>
<servlet-class>net.sf.jasperreports.j2ee.servlets.ImageServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>ImageServlet</servlet-name>
<url-pattern>/reports/image</url-pattern>
</servlet-mapping>
in report.jsp:
request.getSession().setAttribute(ImageServlet.DEFAULT_JASPER_PRINT_SESSION_ATTRIBUTE, jasperPrint);
JRExporter exporterHTML = new JRHtmlExporter();
exporterHTML.setParameter(JRHtmlExporterParameter.CHARACTER_ENCODING, "ISO-8859-9");
exporterHTML.setParameter(JRHtmlExporterParameter.IMAGES_MAP, imagesMap);
exporterHTML.setParameter(JRHtmlExporterParameter.JASPER_PRINT, jasperPrint);
exporterHTML.setParameter(JRHtmlExporterParameter.IMAGES_URI,"/reports/image?image=");
exporterHTML.setParameter(JRHtmlExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS, Boolean.TRUE);
exporterHTML.setParameter(JRHtmlExporterParameter.IS_USING_IMAGES_TO_ALIGN, Boolean.FALSE);
exporterHTML.setParameter(JRHtmlExporterParameter.IS_OUTPUT_IMAGES_TO_DIR, Boolean.TRUE);
exporterHTML.setParameter(JRHtmlExporterParameter.IS_WHITE_PAGE_BACKGROUND, Boolean.FALSE);
exporterHTML.setParameter(JRHtmlExporterParameter.OUTPUT_STREAM, byteArrayOutputStream);
exporterHTML.exportReport();
ouputStream.write(byteArrayOutputStream.toByteArray());
I am also facing same issue while exporting Bar chart in liferay,report is coming on page but chart image is not coming Plz look into below code:
and let me know where i m wrong.
web.xml:
<servlet>
<servlet-name>ImageServlet</servlet-name>
<servlet-class>net.sf.jasperreports.j2ee.servlets.ImageServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>ImageServlet</servlet-name>
<url-pattern>/reports/image</url-pattern>
</servlet-mapping>
in report.jsp:
request.getSession().setAttribute(ImageServlet.DEFAULT_JASPER_PRINT_SESSION_ATTRIBUTE, jasperPrint);
JRExporter exporterHTML = new JRHtmlExporter();
exporterHTML.setParameter(JRHtmlExporterParameter.CHARACTER_ENCODING, "ISO-8859-9");
exporterHTML.setParameter(JRHtmlExporterParameter.IMAGES_MAP, imagesMap);
exporterHTML.setParameter(JRHtmlExporterParameter.JASPER_PRINT, jasperPrint);
exporterHTML.setParameter(JRHtmlExporterParameter.IMAGES_URI,"/reports/image?image=");
exporterHTML.setParameter(JRHtmlExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS, Boolean.TRUE);
exporterHTML.setParameter(JRHtmlExporterParameter.IS_USING_IMAGES_TO_ALIGN, Boolean.FALSE);
exporterHTML.setParameter(JRHtmlExporterParameter.IS_OUTPUT_IMAGES_TO_DIR, Boolean.TRUE);
exporterHTML.setParameter(JRHtmlExporterParameter.IS_WHITE_PAGE_BACKGROUND, Boolean.FALSE);
exporterHTML.setParameter(JRHtmlExporterParameter.OUTPUT_STREAM, byteArrayOutputStream);
exporterHTML.exportReport();
ouputStream.write(byteArrayOutputStream.toByteArray());
10年前 に pradeep pandey によって更新されました。
RE: Images are not displayed for Jasper report with a pie chart JRHtmlExpor
New Member 投稿: 5 参加年月日: 14/02/28 最新の投稿
Hi,
I also change code as below
File reportFile1 = new File(context.getRealPath("/html/image/"));
String destino = reportFile1.getPath();
exporter.setParameter(JRHtmlExporterParameter.IMAGES_DIR_NAME,destino);
exporter.setParameter(JRHtmlExporterParameter.IMAGES_URI,destino + "/")
But still chart image is not coming,
;
I also change code as below
File reportFile1 = new File(context.getRealPath("/html/image/"));
String destino = reportFile1.getPath();
exporter.setParameter(JRHtmlExporterParameter.IMAGES_DIR_NAME,destino);
exporter.setParameter(JRHtmlExporterParameter.IMAGES_URI,destino + "/")
But still chart image is not coming,
;