Jasper Report (iReport) Pie Dataset from main dataset - dataset

I want to use a pie chart per group in Jasper iReport, but I don't know how to create a dataset per group.
Assume I have a table as follows:
Table users
---------
category - user - status
Then I have a the following SQL
select * from users order by category
My display has a simple group band of category with detail showing each user and their status. Ideally I would have each category group header show a pie chart with all the distinct statuses and their counts within that group. I'm at a loss as how to do this in iReport.
If I knew all the categories ahead of time I could just create a dataset for each one using the following:
select status, count(user) from user where category = <current category> group by status
I'm attempting to do this using a JRMapCollectionDataSource that resets each group and pulls the data from the rows in the group using a variable, but I'm not very familiar with the whole reset group and increment paradigm.
Any help?

You can solve this issue without programming following this steps:
sort data by category field and by user field (add sorting via iReport or adding ORDER BY clause to the query in case having deal with jdbc datasource);
add two groups: the 1st group - for category field and the 2nd group - for user field (via iReport). Note: It is not necessarily to add GROUP BY clause to the query;
add Pie Chart component to the Group Header band for the category field;
set evaluationTime and evaluationGroup properties for this pieChart.
Here is working sample for demonstrating how to build Pie Chart. In this sample I've used the csv file as datasource.
The chart shows the quantity of users for every category. I used variable usersCount for counting users in every group, but it is was possible to use built-in variable $V{userGroup_COUNT}.
Here is my jrxml file:
<?xml version="1.0" encoding="UTF-8"?>
<jasperReport ...>
<field name="category" class="java.lang.Integer"/>
<field name="user" class="java.lang.String"/>
<field name="status" class="java.lang.String"/>
<sortField name="category"/>
<sortField name="user"/>
<variable name="usersCount" class="java.lang.Integer" resetType="Group" resetGroup="userGroup" calculation="Count">
<variableExpression><![CDATA[$F{user}]]></variableExpression>
<initialValueExpression><![CDATA[0]]></initialValueExpression>
</variable>
<group name="categoryGroup">
<groupExpression><![CDATA[$F{category}]]></groupExpression>
<groupHeader>
<band height="135">
<pieChart>
<chart evaluationTime="Group" evaluationGroup="categoryGroup">
<reportElement x="158" y="0" width="200" height="135"/>
<chartTitle/>
<chartSubtitle/>
<chartLegend/>
</chart>
<pieDataset>
<dataset resetType="Group" resetGroup="categoryGroup" incrementType="Group" incrementGroup="userGroup"/>
<keyExpression><![CDATA[$F{user}]]></keyExpression>
<valueExpression><![CDATA[$V{usersCount}]]></valueExpression>
<labelExpression><![CDATA[String.valueOf($V{usersCount})]]></labelExpression>
</pieDataset>
<piePlot>
<plot/>
<itemLabel/>
</piePlot>
</pieChart>
<textField>
<reportElement x="0" y="0" width="100" height="20"/>
<textElement/>
<textFieldExpression><![CDATA["Category: " + $F{category}]]></textFieldExpression>
</textField>
</band>
</groupHeader>
</group>
<group name="userGroup">
<groupExpression><![CDATA[$F{user}]]></groupExpression>
</group>
<title>
<band height="79" splitType="Stretch"/>
</title>
</jasperReport>
Here is my csv file (data file - datasource):
category,user,status
1,user1,WORK
1,user1,HOLIDAY
1,user2,SICK
2,user1,WORK
2,user2,WORK
2,user2,HOLIDAY
2,user3,HOLIDAY
2,user4,SICK
3,user1,HOLIDAY
3,user3,HOLIDAY
3,user5,HOLIDAY
4,user1,WORK
4,user1,HOLIDAY
4,user2,SICK
4,user2,WORK
4,user2,SICK
4,user3,HOLIDAY
4,user4,HOLIDAY
4,user5,HOLIDAY
The result will be (via iReport preview):

Related

I can't change range and/or default values in DevExpress Dashboard

I have a page where users register and can make their personal diet plan etc.
I am trying to make some graphs with built-in VS dashboards.
I am using VS 2015 and SQL Server Management Studio 15.0.18206.0 if that matters.
My problems are the following:
Automatic (SUM)
Dashboard values default to SUM function, which I am not able to change, as you see in the first picture, but I kind of managed to solve this problem with the help of SQL (SELECT DISTINCT, SELECT TOP(1) etc.)
Automatic (SUM)
Default year count
When I am trying to make a dashboard to show track of user's vitals and activity, which is the core of my statistics, time defaults to YEAR and the result end up like the second picture.
Default year count
There is nothing I can do to change these and I just made irrelevant graphs to fill the page, but it's a shame because I planned to make a lot of graphs with the table you see in the third picture.
User History table
If it helps, the XML code generated from the last dashboard is this:
<?xml version="1.0" encoding="utf-8"?>
<Dashboard>
<Title Text="YearDashBoard" />
<DataSources>
<SqlDataSource ComponentName="DataSource1">
<Name>UserHistory1</Name>
<Connection Name="foodConnectionString" FromAppConfig="true" />
<Query Type="SelectQuery" Name="UserHistory1" Distinct="true">
<Tables>
<Table Name="UserHistory" />
</Tables>
<Columns>
<Column Table="UserHistory" Name="CaloriesDate" />
<Column Table="UserHistory" Name="DailyCalories" />
<Column Table="UserHistory" Name="UserID" />
</Columns>
<Filter>[UserHistory.UserID] = 17</Filter>
</Query>
<ConnectionOptions CloseConnection="true" CommandTimeout="0" />
</SqlDataSource>
</DataSources>
<Items>
<Chart ComponentName="chartDashboardItem1" Name="Chart 1" DataSource="DataSource1" DataMember="UserHistory1">
<DataItems>
<Measure DataMember="DailyCalories" DefaultId="DataItem0" />
<Dimension DataMember="CaloriesDate" DefaultId="DataItem1" />
</DataItems>
<Arguments>
<Argument DefaultId="DataItem1" />
</Arguments>
<Panes>
<Pane Name="Pane 1">
<Series>
<Simple>
<Value DefaultId="DataItem0" />
</Simple>
</Series>
</Pane>
</Panes>
</Chart>
</Items>
<LayoutTree>
<LayoutGroup Weight="100">
<LayoutItem DashboardItem="chartDashboardItem1" Weight="100" />
</LayoutGroup>
</LayoutTree>
</Dashboard>
Finally, with the help of DevExpress technical team, I found out that the whole time there was an invisible scroll bar, but you had to mouse over it (!) while being on the "BINDING" tab of the menu.

Change xtype dynamically according to the bind value in extjs

I am having a UI page which contains a table which shows the information and we are using extjs to ftech and show the values.
My code is below.
The component looks like below:
<item name="value1" xtype="link" bind="{value}">
<position>22</position>
<default>1</default>
<displayable>1</displayable>
<enabled>1</enabled>
<exportable>1</exportable>
<alwaysAvailable>1</alwaysAvailable>
<editors>
<editor name="filter" xtype="textfield"/>
</editors>
<events>
<event name="click" jsFunction="onClickOpenScreen">
<config>{"url":"......}}</config>
</event>
</events>
<config>{"width": 100}</config>
</item>
and the model is :
<field name="value" tableAlias="table1" column="value" datatype="string">
<required>0</required>
<formula>if some value then value else 0</formula>
</field>
Here in the formula we are fetching the value from db, if value is there then value otherwise display 0.
So my requirement is if any value is there then that will come as hyperlink otherwise it will come as simple value. But from this code even 0 is coming as link.

How to publish additional postgis raster layer attributes in geoserver?

i was wondering if any of You can help me with my problem. I'm storing some rasters in Postgis database. Each raster is in its own table and besides 'rid' and 'rast' columns, I manualy added other columns to store raster attributes such as 'metadata'...
I have successfully imported rasters in geoserver using ImageMosaic JDBC and in Layers Preview (OpenLayers) I can see rasters and use getFeatureInfo function, but the problem is that function getFeatureInfo returns table with correct pixel value , 'rid' field is empty (only table header apears) and no other attribute is shown (not even attribute header in table). I'm using default geoserver method for layer preview function.
mapping.postgis.xml.inc file
<!-- possible values: universal,postgis,db2,mysql,oracle -->
<spatialExtension name="pgraster"/>
<mapping>
<masterTable name="mosaic" >
<coverageNameAttribute name="name"/>
<maxXAttribute name="maxx"/>
<maxYAttribute name="maxy"/>
<minXAttribute name="minx"/>
<minYAttribute name="miny"/>
<resXAttribute name="resx"/>
<resYAttribute name="resy"/>
<tileTableNameAtribute name="tiletable" />
</masterTable>
<tileTable>
<blobAttributeName name="rast" />
<keyAttributeName name="rid" />
<textAttributeName name="metadata" />
</tileTable>
</mapping>
connect.postgis.xml.inc
<connect>
<!-- value DBCP or JNDI -->
<dstype value="DBCP"/>
<!-- <jndiReferenceName value=""/> -->
<username value="postgres" />
<password value="postgres" />
<jdbcUrl value="jdbc:postgresql://localhost:5432/web_kartografija" />
<driverClassName value="org.postgresql.Driver"/>
<maxActive value="10"/>
<maxIdle value="0"/>
</connect>
layer.postgis.xml
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE ImageMosaicJDBCConfig [
<!ENTITY mapping PUBLIC "mapping" "mapping.postgis.xml.inc">
<!ENTITY connect PUBLIC "connect" "connect.postgis.xml.inc">]>
<config version="1.0">
<coverageName name="jan"/> <!-- Name of the table in database -->
<coordsys name="EPSG:4326"/>
<!-- interpolation 1 = nearest neighbour, 2 = bilinear, 3 = bicubic -->
<scaleop interpolation="1"/>
<verify cardinality="false"/>
&mapping;
&connect;
</config>
I tried to include <textAttributeName name="metadata" /> as a column name where aditional data is stored, but still no effect. Can anobudy help me with this problem ? Thanks in advance !

Symfony Propel Many-To-Many Add

I have e functional Symfony Project. I need to add a Many-To-Many relationships in the project.
I have jobs table and cities table. How can I add this relantionships using Generator (I dont want to alter existing data)?
I will use this relationship in Jobs forms (add,edit,list) to assign multiple Cities to a Job.
You will need a cross reference table sitting between your Jobs and Cities:
<table name="job_city" isCrossRef="true">
<column name="job_id" type="INTEGER" primaryKey="true" />
<column name="city_id" type="INTEGER" primaryKey="true" />
<foreign-key foreignTable="job">
<reference local="job_id" foreign="id" />
</foreign-key>
<foreign-key foreignTable="city">
<reference local="city_id" foreign="id" />
</foreign-key>
</table>
After regenerating you will have a new set of classes: JobCity, JobCityQuery, and JobCityPeer to use. You can add a new job to a city like so:
$job = new Job();
// add job info ...
$job->save();
$city = CityQuery::create()->findOneByName("Austin");
$city->addJob($job);
$city->getJobs(); // returns PropelObjectCollection of Job objects

iReport, how to print fields of different table

I need multiple queries in my report so i added a new dataset.
The problem is i can't use fields of new dataset in my report, the error is: field does not exists.
So, how can i have multiple query in my report(to print fields of different table) without create a subreport for each field?
Thanks.
Unfortunately this isn't how iReport works. You need to get all your data into one dataset to use the fields side by side. See #GenericJon's detailed answer on using a datasetRun where your fields are used as input parameters to define another dataset.
If you really want the parameters can be used to pass a field for output in a datasetRun. This outputs Dataset1>Field1 / Dataset2>Field2.
<subDataset name="TotalUsers">
<parameter name="Users" class="java.lang.Integer" isForPrompting="false"/>
<parameter name="Date" class="java.util.Date" isForPrompting="false"/>
<queryString language="SQL">
<![CDATA[CALL GetTotalUsersAtDate($P{Date})]]>
</queryString>
<field name="TotalUsers" class="java.lang.Long"/>
</subDataset>
...
<componentElement>
<reportElement x="0" y="78" width="555" height="16"/>
<jr:list xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd" printOrder="Vertical">
<datasetRun subDataset="TotalUsers">
<parametersMapExpression><![CDATA[$P{REPORT_PARAMETERS_MAP}]]></parametersMapExpression>
<datasetParameter name="Users">
<datasetParameterExpression><![CDATA[$F{MusicSubscribers}]]></datasetParameterExpression>
</datasetParameter>
<connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
</datasetRun>
<jr:listContents height="16" width="555">
<textField pattern="#,##0.00 %" isBlankWhenNull="true">
<reportElement style="table_TD" x="475" y="0" width="80" height="16"/>
<textElement/>
<textFieldExpression><![CDATA[$P{Users}.doubleValue()/$F{TotalUsers}.doubleValue()]]></textFieldExpression>
</textField>
<staticText>
<reportElement style="table_TD" x="0" y="0" width="475" height="16"/>
<textElement textAlignment="Left" markup="none"/>
<text><![CDATA[Proportion of total users]]></text>
</staticText>
</jr:listContents>
</jr:list>
</componentElement>
I would go further to suggest you do as much of the math and collating outside of iReport too, i.e. use stored procedures if your data source is a database.

Resources