Jump to content
We've recently updated our Privacy Statement, available here ×

lucky7456969

Members
  • Posts

    17
  • Joined

  • Last visited

 Content Type 

Profiles

Forum

Events

Featured Visualizations

Knowledge Base

Documentation (PDF Downloads)

Blog

Documentation (Test Area)

Documentation

Dr. Jaspersoft Webinar Series

Downloads

Posts posted by lucky7456969

  1. Say I can make sub-reports and datasets of a certain number

    by pre-creating them. But what if I can't predict how many number of charts are needed in advance

    Say the user will input a range of dates, for example, from january 2011 to feburary 2013

    or june 2012 to November 2013, there can be a product breakdown for each month

    So how can I make such reports?

    Thanks

    Jack

     

  2. Hello, I have built a JRBeanCollectionDataSource and confirmed that there was data in it. I have set the max number of slices to be 35 and the expression is set to the type of product, and the values are the percentage calculated off the SQL query built before the JRBeanCollectionDataSource is built 

    @Override
        public void printReport(List data) {
                   int m = getCurrentMonth();
                   List<Sales> lSales = new ArrayList<>();
                   
                   int[] lastm = getMonths(m);
                   
                   
                  List<Sales> ls = new ArrayList<>();
                  List<SalesChart> lsc = new ArrayList<>();
                   
                  try {
                      
                      
                        String sql = getSQL(m);
                        ResultSet rs = getDB().query(sql);
                         
    
                        while (rs.next())
                        {
                            
                            Sales s = new Sales();
                            s.setType(rs.getString("type"));
                            s.setMonth(m);
                            s.setNs(rs.getInt("NS"));
                            s.setPercent(rs.getDouble("percent"));
                            
                            
                            SalesChart sc = new SalesChart();
                            sc.setType(s.getType());
                            sc.setMonth(s.getMonth());
                            sc.setNs(s.getNs());
                            sc.setPercent(s.getPercent());
                            
                            
                            
                            
                            /*sc.setType(s.getType());
                            sc.setMonth(s.getMonth());
                            sc.setNs(s.getNs());*/
                            
                            lsc.add(sc);
                            
                            s.setListOfSales(lsc);
                            
                            ls.add(s);
                            
                            
                            
                            
                        }       
                        
                            
                            
                            
    
    
                      
                        
                        
                        JRBeanCollectionDataSource beanCollectionDataSource = new JRBeanCollectionDataSource(ls,false);
       
                                 
                                 
                         JasperPrint    jp = null;
                           
                         jp = JasperFillManager.fillReport(getClass().getResourceAsStream("/Reporting/SalesReport6MthByProdType.jasper"), null, beanCollectionDataSource);
                            
                          
    
                            JRViewer test = new JRViewer(jp);
              
                            f.add(test);
                            f.setSize(new Dimension(1000,600));
                           
                            f.setVisible(true);
                    } catch (SQLException ex) {
                        Logger.getLogger(SalesReport6MthByCustType.class.getName()).log(Level.SEVERE, null, ex);
                    } catch (JRException ex) {
                Logger.getLogger(SalesReport6MthByCustType.class.getName()).log(Level.SEVERE, null, ex);
            }
         }
    

     

    <?xml version="1.0" encoding="UTF-8"?>
    <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="SalesReport6MthByProdType" pageWidth="842" pageHeight="595" orientation="Landscape" columnWidth="802" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="c20dea1d-3bb9-4a9d-b2a1-a0f143b6f929">
        <property name="ireport.zoom" value="1.0"/>
        <property name="ireport.x" value="0"/>
        <property name="ireport.y" value="0"/>
        <subDataset name="ChartDataSet" uuid="24d1087e-5730-4cf2-a9af-5f5575b04e20">
            <field name="type" class="java.lang.String"/>
            <field name="percent" class="java.lang.Double"/>
        </subDataset>
        <field name="type" class="java.lang.String"/>
        <field name="month" class="java.lang.Integer"/>
        <field name="ns" class="java.lang.Integer"/>
        <field name="percent" class="java.lang.Double"/>
        <field name="listOfSales" class="java.util.List"/>
        <background>
            <band splitType="Stretch"/>
        </background>
        <title>
            <band height="79" splitType="Stretch"/>
        </title>
        <pageHeader>
            <band height="35" splitType="Stretch"/>
        </pageHeader>
        <columnHeader>
            <band height="37" splitType="Stretch">
                <staticText>
                    <reportElement uuid="9e3da9da-4daf-4302-b75c-a250ae184cf5" x="0" y="0" width="100" height="20"/>
                    <textElement/>
                    <text><![CDATA[type]]></text>
                </staticText>
                <staticText>
                    <reportElement uuid="bbcd135b-7e83-4682-bf78-a6ecb111218b" x="100" y="0" width="100" height="20"/>
                    <textElement/>
                    <text><![CDATA[month]]></text>
                </staticText>
                <staticText>
                    <reportElement uuid="eac33577-ef47-4530-8bf0-cc74791dceb2" x="200" y="0" width="100" height="20"/>
                    <textElement/>
                    <text><![CDATA[ns]]></text>
                </staticText>
                <staticText>
                    <reportElement uuid="0fca5398-0b95-40d2-bc8e-c585d2bf587c" x="300" y="0" width="100" height="20"/>
                    <textElement/>
                    <text><![CDATA[percent]]></text>
                </staticText>
            </band>
        </columnHeader>
        <detail>
            <band height="25" splitType="Stretch">
                <textField>
                    <reportElement uuid="b64122c2-df49-47f2-b20b-0cc1487f27a4" x="0" y="0" width="100" height="20"/>
                    <textElement/>
                    <textFieldExpression><![CDATA[$F{type}]]></textFieldExpression>
                </textField>
                <textField>
                    <reportElement uuid="653557c7-8263-4aa4-b549-ce053c9580b5" x="100" y="0" width="100" height="20"/>
                    <textElement/>
                    <textFieldExpression><![CDATA[$F{month}]]></textFieldExpression>
                </textField>
                <textField>
                    <reportElement uuid="cd5fbe1d-407d-4f58-b5ae-a1305c9cc8ed" x="200" y="0" width="100" height="20"/>
                    <textElement/>
                    <textFieldExpression><![CDATA[$F{ns}]]></textFieldExpression>
                </textField>
                <textField>
                    <reportElement uuid="6f2329bf-6a72-4734-817c-33f0b8af9a55" x="300" y="0" width="100" height="20"/>
                    <textElement/>
                    <textFieldExpression><![CDATA[$F{percent}]]></textFieldExpression>
                </textField>
            </band>
        </detail>
        <summary>
            <band height="249" splitType="Stretch">
                <pieChart>
                    <chart>
                        <reportElement uuid="07eccfec-7d0d-4263-9bc5-86db1f878ef3" x="0" y="0" width="802" height="249"/>
                        <chartTitle/>
                        <chartSubtitle/>
                        <chartLegend/>
                    </chart>
                    <pieDataset maxCount="35">
                        <dataset>
                            <datasetRun subDataset="ChartDataSet" uuid="cca37856-3256-4727-b6fd-2ea6c88ab0d6">
                                <dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{listOfSales})]]></dataSourceExpression>
                            </datasetRun>
                        </dataset>
                        <keyExpression><![CDATA[$F{type}]]></keyExpression>
                        <valueExpression><![CDATA[$F{percent}]]></valueExpression>
                    </pieDataset>
                    <piePlot>
                        <plot/>
                        <itemLabel/>
                    </piePlot>
                </pieChart>
            </band>
        </summary>
    </jasperReport>
     
    


                   
                    
        

    http://i.imgur.com/G3DmUMy.png 

    Wonder why this won't work. I had a stacked bar previously which worked perfectly with this coding.

     

    Thanks Jack

     

  3. <?xml version="1.0" encoding="UTF-8"?>
    <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="MonthlyMemberTotalSales" pageWidth="792" pageHeight="612" orientation="Landscape" columnWidth="752" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="3acf8789-25fe-40e8-8db6-634fee41dc65">
        <property name="ireport.zoom" value="1.0"/>
        <property name="ireport.x" value="0"/>
        <property name="ireport.y" value="0"/>
        <subDataset name="ChartDataSet" uuid="8108e26f-b11d-4ba4-a27f-48af25a186d9">
            <field name="type" class="java.lang.String"/>
            <field name="month" class="java.lang.Integer"/>
            <field name="percent" class="java.lang.Double"/>
            <field name="sales" class="java.lang.Integer"/>
            <field name="total" class="java.lang.Integer"/>
        </subDataset>
        <field name="type" class="java.lang.String"/>
        <field name="month" class="java.lang.Integer"/>
        <field name="sales" class="java.lang.Integer"/>
        <field name="total" class="java.lang.Integer"/>
        <field name="percent" class="java.lang.Double"/>
        <field name="listOfSales" class="java.util.List"/>
        <background>
            <band splitType="Stretch"/>
        </background>
        <title>
            <band height="79" splitType="Stretch">
                <staticText>
                    <reportElement uuid="1dcb5f2b-a4df-450c-96b2-d6030e9b4a33" mode="Opaque" x="0" y="0" width="752" height="79" backcolor="#FFFF00"/>
                    <textElement textAlignment="Center">
                        <font size="48" isUnderline="false"/>
                    </textElement>
                    <text><![CDATA[Monthly Sales Report]]></text>
                </staticText>
            </band>
        </title>
        <pageHeader>
            <band height="35" splitType="Stretch"/>
        </pageHeader>
        <columnHeader>
            <band height="30" splitType="Stretch">
                <staticText>
                    <reportElement uuid="cbc4f3a4-dde4-4535-a4da-42ae2396a394" x="0" y="0" width="100" height="20"/>
                    <textElement/>
                    <text><![CDATA[type]]></text>
                </staticText>
                <staticText>
                    <reportElement uuid="eb7f73ac-ef4b-42c7-af83-c220cb90e7e2" x="100" y="0" width="100" height="20"/>
                    <textElement/>
                    <text><![CDATA[month]]></text>
                </staticText>
                <staticText>
                    <reportElement uuid="140e982e-1a40-4fd9-8b90-04f5ffcf6b48" x="200" y="0" width="100" height="20"/>
                    <textElement/>
                    <text><![CDATA[sales]]></text>
                </staticText>
                <staticText>
                    <reportElement uuid="00024fb5-6d2b-4352-9965-d972097ad16d" x="300" y="0" width="100" height="20"/>
                    <textElement/>
                    <text><![CDATA[percent]]></text>
                </staticText>
            </band>
        </columnHeader>
        <detail>
            <band height="125" splitType="Stretch">
                <textField>
                    <reportElement uuid="f953968e-1da4-4312-9dd0-c89356b2cfd1" x="0" y="0" width="100" height="20"/>
                    <textElement/>
                    <textFieldExpression><![CDATA[$F{type}]]></textFieldExpression>
                </textField>
                <textField>
                    <reportElement uuid="194c193f-1c98-4f6a-a27e-df8620eb9621" x="100" y="0" width="100" height="20"/>
                    <textElement/>
                    <textFieldExpression><![CDATA[$F{month}]]></textFieldExpression>
                </textField>
                <textField>
                    <reportElement uuid="67cb8451-eb97-447d-9eb3-c3bc1026f135" x="200" y="0" width="100" height="20"/>
                    <textElement/>
                    <textFieldExpression><![CDATA[$F{sales}]]></textFieldExpression>
                </textField>
                <textField>
                    <reportElement uuid="570c2d09-90ca-4313-b3f8-84f797d4fc5a" x="300" y="0" width="100" height="20"/>
                    <textElement/>
                    <textFieldExpression><![CDATA[$F{percent}]]></textFieldExpression>
                </textField>
            </band>
        </detail>
        <columnFooter>
            <band height="137" splitType="Stretch">
                <stackedBarChart>
                    <chart>
                        <reportElement uuid="74539c29-04d5-4692-92cd-a400279861d8" x="0" y="0" width="752" height="137"/>
                        <chartTitle/>
                        <chartSubtitle/>
                        <chartLegend/>
                    </chart>
                    <categoryDataset>
                        <dataset>
                            <datasetRun subDataset="ChartDataSet" uuid="39f7f3ab-8979-45ec-af7d-997d6010adce">
                                <dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{listOfSales})]]></dataSourceExpression>
                            </datasetRun>
                        </dataset>
                        <categorySeries>
                            <seriesExpression><![CDATA[$F{type}]]></seriesExpression>
                            <categoryExpression><![CDATA[$F{month}]]></categoryExpression>
                            <valueExpression><![CDATA[$F{sales}]]></valueExpression>
                        </categorySeries>
                    </categoryDataset>
                    <barPlot>
                        <plot/>
                        <itemLabel/>
                    </barPlot>
                </stackedBarChart>
            </band>
        </columnFooter>
        <pageFooter>
            <band height="54" splitType="Stretch"/>
        </pageFooter>
        <summary>
            <band height="42" splitType="Stretch"/>
        </summary>
    </jasperReport>

     

    I have confirmed listOfSales has two sets of data, one for vip and one for normal

    The normal customer group never gets a chance to show up

    Thanks

    Jack

     

  4. When I am asked to create a series

    I put

    ${grossSales}

    ${netSales}

    I get these out of Jasper report, I think this notation is not accepted. How would I create multiple series, say 2 bars for each customer one for gross sales and one for net sales?

    SEVERE: null net.sf.jasperreports.engine.fill.JRExpressionEvalException: Error evaluating expression : Source text : $F{grossSales} $F{netSales}

     

    http://i.imgur.com/t591MtC.png

  5. The main frame is closed after the report preview is closed. I put the print method in a factory class.

    public static void print(Database db, int CustID)
         {
              
                              HashMap<String, Object> param = new HashMap<>();
                   try {
                
                            InputStream in =
                            UtilityFactory.class.getResourceAsStream("/Reporting/SalesReport.jrxml");
                            JasperDesign jd = null;
                            
                            jd = JRXmlLoader.load(in);
                            

                            JRDesignParameter parameter = new JRDesignParameter();
                            
                         /*  parameter.setName("ReportTitle");
                            parameter.setValueClass(java.lang.String.class);
                            jd.addParameter(parameter);

                            parameter = new JRDesignParameter();
                            parameter.setName("OrderByClause");
                            parameter.setValueClass(java.lang.String.class);
                            jd.addParameter(parameter);
                            
                           parameter = new JRDesignParameter();
                            parameter.setName("CustomerID");
                            parameter.setValueClass(java.lang.String.class);
                            jd.addParameter(parameter);*/
                            
                            ResultSet customer =  db.getCustomer2(CustID);
                            
                             
                            String logoStr = UtilityFactory.class.getResource("/resources/ICJB.png").getPath();
                             
                            param.put("logo", logoStr);
                            
                            param.put("REPORT_NAME", "Sales Report");
                            while (customer.next())
                            {

                                param.put("ColumnHeader", customer.getString(2) + " " + customer.getString(3));
                                param.put("PageHeader", "");
                                param.put("customerID", customer.getInt(1));
                                 
                                 
                            }
                            
                            

                            
                            
                            JRDesignQuery newQuery = new JRDesignQuery();
                             
                            //newQuery.setText(sql);
                             
                            
                           // jd.setQuery(newQuery);
                            
                            
                             
                            JasperReport jr = JasperCompileManager.compileReport(jd);
                           
                            
                            JasperPrint jp = JasperFillManager.fillReport(jr, param, db.getConnection());
                            JasperViewer.viewReport(jp);
                        }
                        catch (Exception e)
                        {
                            e.printStackTrace();
                        }
         }

     

      Thanks,>

  6. I don't know why Here is the factory class

    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    package jewellery.Charting;
    
    /**
     *
     * @author Jacky
     */
    public class AgeDistribution {
        
        int ProductID;
        String ProductName;
        String AgeGroup;
        int NoOfPeople;
        
        public AgeDistribution()
        {
            
        }
    
        public AgeDistribution(int ProductID, String ProductName, String AgeGroup, int NoOfPeople) {
            this.ProductID = ProductID;
            this.ProductName = ProductName;
            this.AgeGroup = AgeGroup;
            this.NoOfPeople = NoOfPeople;
        }
        
    
        public int getProductID() {
            return ProductID;
        }
    
        public void setProductID(int ProductID) {
            this.ProductID = ProductID;
        }
    
        public String getProductName() {
            return ProductName;
        }
    
        public void setProductName(String ProductName) {
            this.ProductName = ProductName;
        }
    
        public String getAgeGroup() {
            return AgeGroup;
        }
    
        public void setAgeGroup(String AgeGroup) {
            this.AgeGroup = AgeGroup;
        }
    
        public int getNoOfPeople() {
            return NoOfPeople;
        }
    
        public void setNoOfPeople(int NoOfPeople) {
            this.NoOfPeople = NoOfPeople;
        }
        
        
    
        
        
    }
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    package Reporting.BeanDataSource;
    
    import java.util.ArrayList;
    import java.util.List;
    import jewellery.Charting.AgeDistribution;
    
    /**
     *
     * @author Jacky
     */
    public class AgeDistributionFactory {
     
      public static java.util.Collection generateCollection()
      {
        java.util.Vector collection = new java.util.Vector();
        assert (!lAgeDistribution.isEmpty());
        for (AgeDistribution ageDist : lAgeDistribution)
        {
            collection.add(ageDist);
        }
        return collection;
       }
     
      public static void addToCollection(AgeDistribution ageDist)
      {
          lAgeDistribution.add(ageDist);
      }
     
      static List<AgeDistribution> lAgeDistribution = new ArrayList<>();
    }
     
    
    
    

    net.sf.jasperreports.engine.JRException: Error retrieving field value from bean : ProductID

  7. I have seen a video in which it uses JRBeanCollectionDataSource, but can I use JDBCCategoryDataSet instead?

    Where can I set this up?

    I actually pass in a query like

    "select p.ProductID, p.ProductName from products AS p"
    

    Then I have a subreport which in turn

    SELECT products.ProductID,
              products.ProductName,
              SUM(IF(cust.Age < 20,1,0)) as 'Under 20',
              SUM(IF(cust.Age BETWEEN 20 and 29,1,0)) as '20 - 29',
              SUM(IF(cust.Age BETWEEN 30 and 39,1,0)) as '30 - 39',
              SUM(IF(cust.Age BETWEEN 40 and 49,1,0)) as '40 - 49',
              SUM(IF(cust.Age BETWEEN 50 and 59,1,0)) as '50 - 59',
              SUM(IF(cust.Age BETWEEN 60 and 69,1,0)) as '60 - 69',
              SUM(IF(cust.Age BETWEEN 70 and 79,1,0)) as '70 - 79',
              SUM(IF(cust.Age BETWEEN 80 and 89,1,0)) as '80 - 89',
              SUM(IF(cust.Age >= 90,1,0)) as 'Above 90',
              count(cust.CustomerID) AS 'NoOfCustomer'
              FROM (((products AS products
              LEFT JOIN order_details AS order_details ON (order_details.ProductID = products.ProductID ))
              LEFT JOIN orders AS orders ON (order_details.OrderID = orders.OrderID ))
              LEFT JOIN customers AS cust ON (orders.CustomerID = cust.CustomerID ))
              where products.ProductID = $P{ProductID}
              GROUP BY products.ProductName
    

    I pass in the subreport with the parameter of the productid

     

    Can I reuse this query data in my JFreeChart right below it

    http://jasperreports.sourceforge.net/api/net/sf/jasperreports/engine/data/ListOfArrayDataSource.html

    Note that how can I go up one level to the parent report and dig down to the subreport of age group distribution listed above

    Update:

    II understand I could have used the java beans datasource, but how can I create the beans inside Jasper report,

    rather than inside the Java code?

     

     

    With Thanks

    Jack

     

     

     

     

     

     

×
×
  • Create New...