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

Pie Chart only legends visible


lucky7456969

Recommended Posts

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

 

Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...