daryn.leaity Posted May 28, 2017 Share Posted May 28, 2017 Hi Guys,I'm very new to using this and any help would be greatly appreciated.I have created a report which has two graphs. It works perfectly in preview but when I generate from java the graphs are blank.From java I create the report with a JREmptyDataset Inside the report itself I have declared 2x datasets (one for each graph)Here is my code:Controller@RequestMapping(value = "/weeklyStatistics", method = RequestMethod.GET) protected void generateInvoice(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { resp.setContentType("application/pdf"); OutputStream out = resp.getOutputStream(); JasperPrint jasperPrint = reportService.generateWeeklyStatistics(); resp.setContentType("application/x-pdf"); // if you want file to download instead resp.setHeader("Content-disposition", "inline; filename=WEEKLY-STATISTICS - " + DateConverter.ConvertDateToString(new Date()) + ".pdf"); try { JasperExportManager.exportReportToPdfStream(jasperPrint, out); } catch (JRException e1) { e1.printStackTrace(); }}[/code] JasperPrint: @Override public JasperPrint generateWeeklyStatistics() { InputStream input = servletContext.getResourceAsStream("/reports/statistics.jrxml"); LocalDate nextThursday = LocalDate.now().with(TemporalAdjusters.next(DayOfWeek.THURSDAY)); java.util.Date date = java.sql.Date.valueOf(nextThursday); Map<String, Object> parameters = new HashMap<String, Object>(); parameters.put("nextThursday", nextThursday); JasperPrint jasperPrint = null; JasperReport jasperReport = null; try { jasperReport = JasperCompileManager.compileReport(input); } catch (JRException e) { // TODO Auto-generated catch block e.printStackTrace(); } try { jasperPrint = JasperFillManager.fillReport(jasperReport, null, new JREmptyDataSource()); } catch (JRException e) { // TODO Auto-generated catch block e.printStackTrace(); } return jasperPrint; }[/code] JasperReport<?xml version="1.0" encoding="UTF-8"?><!-- Created with Jaspersoft Studio version 6.3.1.final using JasperReports Library version 6.3.1 --><!-- 2017-05-29T11:28:09 --><jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="statistics" pageWidth="595" pageHeight="842" whenNoDataType="AllSectionsNoDetail" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" whenResourceMissingType="Empty" uuid="fc97a963-c0b6-4c19-a348-7e2773e092a3"> <property name="template.engine" value="tabular_template"/> <property name="com.jaspersoft.studio.data.defaultdataadapter" value="New Data Adapter (2)"/> <property name="com.jaspersoft.studio.data.sql.tables" value=""/> <style name="Table"> <box> <pen lineWidth="1.0" lineColor="#000000"/> <topPen lineWidth="1.0" lineColor="#000000"/> <leftPen lineWidth="1.0" lineColor="#000000"/> <bottomPen lineWidth="1.0" lineColor="#000000"/> <rightPen lineWidth="1.0" lineColor="#000000"/> </box> </style> <subDataset name="tableDataset" uuid="2c22c341-01c2-473b-aaf8-6279b3136b14"> <property name="com.jaspersoft.studio.data.defaultdataadapter" value="SpringHibernateSession"/> <queryString> <![CDATA[]]> </queryString> </subDataset> <subDataset name="Value of Services Delivered" uuid="4830f0b1-25a7-4d84-ba6a-ec8ceed39947"> <property name="com.jaspersoft.studio.data.sql.tables" value=""/> <property name="com.jaspersoft.studio.data.defaultdataadapter" value="New Data Adapter (2)"/> <queryString> <![CDATA[sELECT CAST(date_trunc('week', order_date) AS DATE) as "Week" , sum(total_debit) as profit from transactions where participant_identifier=ECOS' and order_date > now() - interval '6 weeks' group by "Week" order by "Week]]> </queryString> <field name="Week" class="java.sql.Date"/> <field name="profit" class="java.math.BigDecimal"/> </subDataset> <subDataset name="New Customers" uuid="cf13da5e-082f-4829-a057-b1a14f1344e5"> <property name="com.jaspersoft.studio.data.sql.tables" value=""/> <property name="com.jaspersoft.studio.data.defaultdataadapter" value="New Data Adapter (2)"/> <queryString> <![CDATA[sELECT CAST(date_trunc('week', switch_in_date) AS DATE) as "Week" , count(*) as customers from icp where switch_in_date > now() - interval '66 weeks' group by "Week" order by "Week"]]> </queryString> <field name="Week" class="java.sql.Date"/> <field name="customers" class="java.lang.Long"/> </subDataset> <parameter name="nextThursday" class="java.sql.Date"> <parameterDescription><![CDATA[]]></parameterDescription> </parameter> <queryString> <![CDATA[]]> </queryString> <variable name="CurrentThursday" class="java.sql.Date"/> <summary> <band height="466" splitType="Stretch"> <property name="local_mesure_unitheight" value="pixel"/> <property name="com.jaspersoft.studio.layout" value="com.jaspersoft.studio.editor.layout.VerticalRowLayout"/> <lineChart> <chart evaluationTime="Report"> <reportElement x="0" y="0" width="555" height="233" uuid="5d4650a6-22c1-45fb-8a40-36c01c1cde5e"/> <chartTitle/> <chartSubtitle/> <chartLegend/> </chart> <categoryDataset> <dataset> <datasetRun subDataset="Value of Services Delivered" uuid="c4169e3b-5c63-4b00-8241-85075a2c6b6f"> <connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression> </datasetRun> </dataset> <categorySeries> <seriesExpression><![CDATA["Value of sales for past 6x weeks"]]></seriesExpression> <categoryExpression><![CDATA[$F{Week}]]></categoryExpression> <valueExpression><![CDATA[$F{profit}]]></valueExpression> </categorySeries> </categoryDataset> <linePlot> <plot/> <categoryAxisFormat> <axisFormat labelColor="#000000" tickLabelColor="#000000" axisLineColor="#000000"/> </categoryAxisFormat> <valueAxisFormat> <axisFormat labelColor="#000000" tickLabelColor="#000000" axisLineColor="#000000"/> </valueAxisFormat> </linePlot> </lineChart> <lineChart> <chart evaluationTime="Report"> <reportElement x="0" y="233" width="555" height="233" uuid="301311ba-d1b8-44d2-8532-39bf1e776cca"/> <chartTitle/> <chartSubtitle/> <chartLegend/> </chart> <categoryDataset> <dataset> <datasetRun subDataset="New Customers" uuid="605f61eb-837c-43ac-9ddc-d3bd3417be19"/> </dataset> <categorySeries> <seriesExpression><![CDATA["New switched-in customers"]]></seriesExpression> <categoryExpression><![CDATA[$F{Week}]]></categoryExpression> <valueExpression><![CDATA[$F{customers}]]></valueExpression> </categorySeries> </categoryDataset> <linePlot> <plot/> <categoryAxisFormat> <axisFormat labelColor="#000000" tickLabelColor="#000000" axisLineColor="#000000"/> </categoryAxisFormat> <valueAxisFormat> <axisFormat labelColor="#000000" tickLabelColor="#000000" axisLineColor="#000000"/> </valueAxisFormat> </linePlot> </lineChart> </band> </summary></jasperReport>[/code] Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now