Jump to content
Changes to the Jaspersoft community edition download ×

How to create a stucked chart related to a group header


Recommended Posts


I am starting to develop reports with jasper.

I want to create a report with group and related subgroup.

I am trying to create a report with a country group and, inside this country group, a stacked bar that shows a perspective of jobs in each country.

My table has the next fields: id, country, name, job

Examples of rows in this table:

   1 | New York | Peter Gabriel  | singer   |
|    2 | New York | Elena Franklin | singer   |
|    3 | New York | Elisabeth Cain | reporter |
|    4 | Illinois | Albert Sousa   | engineer |
|    5 | Illinois | Ann Clock      | engineer |
|    6 | Illinois | Rose Castle    | nurse

The query from the database in jasper is

select country,  count(job) as NJob,  job from dem group by country, job[/code]

I have created a group header in jasper studio with "country" and, in the detail, I have created a stacked bar with category an series with the field "job" and value "NJob". But the result is that, for each country, shows two graphics and each graphics shows all the jobs although this job doesn't exist in this country. For example, for New York the graphics shows the single, reporter, engineer and nurse.


I want to show only jobs in the country  but I am very lost how to do this.

Any help?

Thanks in advanced.

This is my jxml

<?xml version="1.0" encoding="UTF-8"?><!-- Created with Jaspersoft Studio version 6.6.0.final --><!-- using JasperReports Library version 6.6.0  --><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="Rejemplo"              pageWidth="595" pageHeight="842" columnWidth="555"              leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20"              uuid="d6b8d2c8-f1a8-430f-9b76-84dc3f6b980d">    <property name="com.jaspersoft.studio.data.sql.tables" value=""/>    <property name="com.jaspersoft.studio.data.defaultdataadapter" value="testMySQL"/>    <queryString language="SQL">        <![CDATA[select country,  count(job) as NJob,  job from dem group by country, job]]>    </queryString>    <field name="country" class="java.lang.String">        <property name="com.jaspersoft.studio.field.label" value="country"/>        <property name="com.jaspersoft.studio.field.tree.path" value="dem"/>    </field>    <field name="NJob" class="java.lang.Long">        <property name="com.jaspersoft.studio.field.label" value="NJob"/>    </field>    <field name="job" class="java.lang.String">        <property name="com.jaspersoft.studio.field.label" value="job"/>        <property name="com.jaspersoft.studio.field.tree.path" value="dem"/>    </field>    <group name="GCountries" keepTogether="true">        <groupExpression><![CDATA[$F{country}]]></groupExpression>        <groupHeader>            <band height="33">                <textField>                    <reportElement x="0" y="0" width="100" height="30"                                   uuid="df86b54b-dca2-4388-86cd-ccfaaafb99cd"/>                    <textFieldExpression>                        <![CDATA[$F{country}]]>                    </textFieldExpression>                </textField>            </band>        </groupHeader>    </group>    <background>        <band splitType="Stretch"/>    </background>    <detail>        <band height="286" splitType="Stretch">            <stackedBarChart>                <chart isShowLegend="false" evaluationTime="Report">                    <reportElement x="10" y="10" width="510" height="276"                                   uuid="e709bbd0-3e51-490f-93b3-58220d67f6c8"/>                    <chartTitle/>                    <chartSubtitle/>                    <chartLegend/>                </chart>                <categoryDataset>                    <categorySeries>                        <seriesExpression><![CDATA[$F{job}]]></seriesExpression>                        <categoryExpression><![CDATA[$F{job}]]></categoryExpression>                        <valueExpression><![CDATA[$F{NJob}]]></valueExpression>                    </categorySeries>                </categoryDataset>                <barPlot>                    <plot orientation="Horizontal"/>                    <itemLabel/>                    <categoryAxisFormat>                        <axisFormat labelColor="#000000" tickLabelColor="#000000"                                    axisLineColor="#000000"/>                    </categoryAxisFormat>                    <valueAxisFormat>                        <axisFormat labelColor="#000000" tickLabelColor="#000000"                                    axisLineColor="#000000"/>                    </valueAxisFormat>                </barPlot>            </stackedBarChart>        </band>    </detail></jasperReport>[/code]


Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Popular Days

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...