Jump to content
Changes to the Jaspersoft community edition download ×

Add Horizontal Bar Chart to Group Header


Recommended Posts

Hi I am new to Jasper reports. I want to add a horizontal bar chart to a report in the group header with a bar for Kitchen & Bathroom counts. Other than the very basics e.g. dragging the chart onto the template and assigning the orientation I am clueless on how to proceed. If anyone could give me some pointers I would be most grateful thank you. Further details are below.

The data set is on SQL Server and as so. I'm using a group by in my SQL expression for the data set. 


These are how I want to get the charts to look like. For each Group By there would be a header and a chart like so





The report template as it exists at the moment with some fields in the Group Header. The aim to to eventually have a page per Group By



This is the report source:

<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.3.1.final using JasperReports Library version 6.3.1  -->
<!-- 2017-04-11T12:41:05 -->
<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="ChartTest" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="4c052314-543c-4cb2-bda7-e58860d79f68">
<property name="com.jaspersoft.studio.data.sql.tables" value=""/>
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="DevJasperReportsServer-1reportsDatabase.xml"/>
<queryString language="SQL">
<![CDATA[sELECT  [storeId]
      ,MAX([Kitchen]) AS Kitchen
      ,MAX([bathroom]) AS Bathroom
      ,MAX([Location]) AS Location
      ,MAX([Employees]) AS Employees
      ,MAX([Revenue]) AS Revenue
  GROUP BY [storeId]]]>
<field name="StoreId" class="java.lang.String"/>
<field name="Kitchen" class="java.lang.Integer"/>
<field name="Bathroom" class="java.lang.Integer"/>
<field name="Location" class="java.lang.String"/>
<field name="Employees" class="java.lang.Integer"/>
<field name="Revenue" class="java.math.BigDecimal"/>
<group name="StoreId">
<group name="Group1">
<band height="215">
<reportElement x="180" y="30" width="200" height="20" uuid="d7b99763-8fa7-489f-a21b-397747554556"/>
<reportElement x="180" y="60" width="100" height="20" uuid="c408f962-bf6a-4750-9c17-69b5a5fb0db4"/>
<reportElement x="180" y="90" width="100" height="20" uuid="f475d12c-7c11-43dc-a176-a31d9e2c6697"/>
<reportElement x="0" y="30" width="100" height="20" uuid="c550d318-262c-4a02-8f85-76e557b3bcbd"/>
<reportElement x="0" y="60" width="100" height="20" uuid="4983f9ee-23f9-42dc-b9d9-d218083afa64"/>
<reportElement x="0" y="90" width="100" height="20" uuid="db5f8402-1784-4b3b-bf44-464941296658"/>
<reportElement x="0" y="0" width="560" height="30" forecolor="#FFFFFF" backcolor="#BF4745" uuid="a29b4137-1c40-4acc-b6d4-07876388a267"/>
<reportElement x="207" y="14" width="100" height="16" forecolor="#FFFFFF" uuid="97fe2a26-a1ce-46f7-adb4-f7da9a1e32ea"/>
<font isBold="true"/>
<band height="50"/>
<band splitType="Stretch"/>
<band height="79" splitType="Stretch"/>
<band height="35" splitType="Stretch"/>
<band height="125" splitType="Stretch"/>
<band height="54" splitType="Stretch"/>
<band height="42" splitType="Stretch"/>
Link to comment
Share on other sites

  • Replies 1
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Posted Images

Hi , 


Reading your complete explanation, please follow the steps to create a desired output.

1. Create group based on the Store id

2. inside group header place the bar chart, and go the properties of the chart and in the tab chart plot you can find the property Orientation and set it to Horizontal

3. In the chart have two series, Bathroom and Kitchen, of which you have values directly so the plot can be directly created.

4. The format which you have created in the jrxml you can directly paste that into your detail band.

So in this way each record of your query will be acting as one group.

Hope that this helps.




Ankur Gupta



Link to comment
Share on other sites

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