Home
Analytics
Dynamic Filter
arunearla
Hi,
Can anyone tell me, how can i do dynamic filtering in BIRT 4.2.0. Whenever I select top 10,it should display the chart for top 10 rows data.I want to display the chart for top 10 rows,last 10 rows,top 20 rows dynamically.
Find more posts tagged with
Comments
kclark
I've attached a report showing how to do this. I created two tables and they both have a filter on them The top is for TopN and the second is BottomN. If you go to property editor>filters>add you can add these here.
Tubal
This post might get you started:<br />
<br />
<a class='bbc_url' href='
http://birtworld.blogspot.com/2010/06/conditional-table-filters.html'>http://birtworld.blogspot.com/2010/06/conditional-table-filters.html</a><br
/>
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>importPackage( Packages.org.eclipse.birt.report.engine.api.script.element );
importPackage( Packages.org.eclipse.birt.report.model.api.simpleapi );
if(params["Region"].value!= null){
var filterCondition = StructureScriptAPIFactory.createFilterCondition();
filterCondition.setExpr("row['COUNTRY']");
filterCondition.setOperator("eq");
filterCondition.setValue1("params[\"Region\"]");
var filterKey = filterCondition.getStructure();
var filterItem = SimpleElementFactory.getInstance().createFilterCondition( filterKey )
this.addFilterCondition( filterItem );
}</pre>
<br />
First, you would set up a report parameter for the user to decide how the report will be filtered.<br />
<br />
Then, you would put your code in your table's onPrepare method.<br />
<br />
The operator for "Top N" is just "top-n", or "bottom-n".<br />
<br />
So you might replace ....setOperator("eq") with setOperator("top-n")
arunearla
Thanks for the help clark and tubal, can u do some favour for me.<br />
<br />
<br />
could u please prepare me a sample report for dynamic filter.The sample report should contain <strong class='bbc'>3 report parameters</strong> for single <strong class='bbc'> table data set</strong>. first one is for <em class='bbc'> from date</em>, Second One is for <em class='bbc'>TO date</em>,Third one is for dynamic filtering i.e the user have the choice to select first 10 rows,last 20 rows,first 20 rows,last 10 rows,based on this 3 report parameters,i need to display the chart. If u have a time ,please send me the sample reports on this.
arunearla
I want to display chart according to attached figure. can anyone help how to achieve this?
arunearla
<blockquote class='ipsBlockquote' data-author="'arunearla'" data-cid="110883" data-time="1351065765" data-date="24 October 2012 - 01:02 AM"><p>
I want to display chart according to attached figure. can anyone help how to achieve this?<br /></p></blockquote>
arunearla
I Guess it was not possible in birt? can anyone tell me...any other ways to achieve this?
Tubal script code is not sufficient to achieve my query.
kclark
arunearia,
Sorry for the slow response. I've created a report with 4 parameters. topN, bottomN, fromDate, toDate. topN and bottomN are list boxes that allow the user to select 10 or 20. The fromDate and toDate are date fields (yyyy-MM-dd). I then created two tables with filters. First it filters by the date range using params["fromDate"] and params["toDate"] then it filters by topN and bottomN. This may not be exactly what you are needing for your report but it should get you pointed in the right direction.
arunearla
Hi Clark,
Thanks for the response.It helps up to some extent of my problem.whenever i select two report parameters i.e [number of top rows],[number of bottom rows],then only the report is generating.In case, if one parameter is empty like [number of top rows ] and another parameter [number of bottom rows] is selected 10,then it was not working.I want to generate a report according to below attachments shown.Hardly i am suffering with this requirement. could you please suggest me how to achieve this (or) if possible,send me a sample report .
arunearla
Hi Clark,
I have been trying this query.Please suggest me how can i proceed.
Below Fig:(selection) have a choice to select TOP/BOTTOM and Fig:no of rows have a choice to select 10/20 rows.
I wrote some code on prepare method.
importPackage( Packages.org.eclipse.birt.report.engine.api.script.element );
importPackage( Packages.org.eclipse.birt.report.model.api.simpleapi );
if(params["selection"].value = "TOP"){
var filtercondition= StructureScriptAPIFactory.createFilterCondition();
filterCondition.setExpr("row['SVCNAME']");
filterCondition.setOperator("top-n");
filterCondition.setValue1("params[\"Count\"].value");
var filterKey = filterCondition.getStructure();
var filterItem = SimpleElementFactory.getInstance().createFilterCondition( filterKey )
this.addFilterCondition( filterItem );
}
else if(params["selection"].value = "BOTTOM"){
var filtercondition= StructureScriptAPIFactory.createFilterCondition();
filterCondition.setExpr("row['SVCNAME']");
filterCondition.setOperator("bottom-n");
filterCondition.setValue1("params[\"Count\"].value");
var filterKey = filterCondition.getStructure();
var filterItem = SimpleElementFactory.getInstance().createFilterCondition( filterKey )
this.addFilterCondition( filterItem );
}
but it is throwing error.
Can you help, where i am going wrong?
arunearla
Hi Tubal,
I have been trying this query.Please suggest me how can i proceed.
report parameter (selection) have a choice to select TOP/BOTTOM and report parameter9count) have a choice to select 10/20 rows.
I wrote some code on prepare method.
importPackage( Packages.org.eclipse.birt.report.engine.api.script.element );
importPackage( Packages.org.eclipse.birt.report.model.api.simpleapi );
if(params["selection"].value = "TOP"){
var filtercondition= StructureScriptAPIFactory.createFilterCondition();
filterCondition.setExpr("row['SVCNAME']");
filterCondition.setOperator("top-n");
filterCondition.setValue1("params[\"Count\"].value");
var filterKey = filterCondition.getStructure();
var filterItem = SimpleElementFactory.getInstance().createFilterCondition( filterKey )
this.addFilterCondition( filterItem );
}
else if(params["selection"].value = "BOTTOM"){
var filtercondition= StructureScriptAPIFactory.createFilterCondition();
filterCondition.setExpr("row['SVCNAME']");
filterCondition.setOperator("bottom-n");
filterCondition.setValue1("params[\"Count\"].value");
var filterKey = filterCondition.getStructure();
var filterItem = SimpleElementFactory.getInstance().createFilterCondition( filterKey )
this.addFilterCondition( filterItem );
}
but it is throwing error.
Can you help, where i am going wrong?
Hans_vd
Hi Arun,<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>var filtercondition= StructureScriptAPIFactory.createFilterCondition();</pre>
In the definition of the variable you write "filtercondition", lowercase<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>filterCondition.setExpr("row['SVCNAME']");</pre>
From then on, you use "filterCondition" with capital C<br />
<br />
That's why the code is throwing an error.
arunearla
Hi,
I did the changes according to your suggestion. But still i en counting the same issue.
please find the attached zip file, which contains .design file and database schema file.Please have a look at this, and give me a solution for my problem.
thank you,
arunearla
Hi ,
Please help me to generate the chart for either top 10/20 rows or bottom 10/20 rows with in a single dataset.I sent you the attached files and database schema in my previous post.Please have a look at my post and give me a possible solution for this.Hardly i was trying for this.And please let me know wheather it is possible in BIRTt charting or not.
Thanks,
Arun
Hans_vd
<blockquote class='ipsBlockquote' ><p>Then, you would put your code in your table's onPrepare method.</p></blockquote>
In the table that is in your report I don't see any code in the onPrepare method. Where did you put it?<br />
<br />
Also, the chart that is in your report is not in a table.<br />
First create a table based on the data set, put the code in the onPrepare method and finally create the chart in the header row.<br />
<br />
In <a class='bbc_url' href='
http://enterprisesmartapps.wordpress.com/2012/01/16/birt-generate-a-separate-chart-for-each-group-value/'>this
post</a> is described how to put a chart in a group header. You can put a chart in the table header the same way as it is put in a group header as described in that post.
Hans_vd
Ok, I found your script code in the XML source.
How did it get at the report level? I'm using an older version of BIRT, but as far as I know there is no onPrepare method on report level?
Did you just paste the code in the XML?
arunearla
hi,
I am using Birt 4.2.0 VERSION. I diddnot copied the code directly in the XML. My requirement is need to display the chart as well as report for the same.The chart is either top 10/20 rows or bottom 10/20 rows.The table report also same. Whetever the chart displays same values should apper in the table report as well.
I just clicked in the report(i.e i didnot select chart or table) and then clicked on the script.At this time on prepare,before factory methods appers.
so i clicked on prepare method and then wrote the code.
regards
arun
Hans_vd
Still, the script as it is needs to be in the onPrepare method of the table.
So you need to put the chart in a table.
arunearla
Hi,<br />
First i need to display a chart.Please forgot (or) remove the table.table is second prarity . Please ignore that.<br />
Now i want to display only <strong class='bbc'>chart either top 10/20 rows or bottom 10/20 rows</strong>. this is my only requirement.<br />
<br />
As mentioned above posts by Tubal , i tried to achieve by coding, but it was not working. If you have any idea on this,please do this for me .<br />
<br />
Thanks<br />
Arun.
Hans_vd
Hi Arun,
Why do you want me to forget about the table? Because that is the way you can achieve what you want. You draw a table on the report (one row, one column), bind it to your dataset, put the script in the onPrepare method and then create the chart in the header of the table. You can remove the detail row and the footer row.
Is there a reason why you don't want to use a table in order to get your chart right?
arunearla
Hi,
I generated the chart according to your way.But still i was unable to display chart for either top 10/20 rows or bottom 10/20 rows.Is there any other way to achieve. Below is the attached .rptdesign file.
please suggest me how to sort out this.
Hans_vd
Possible parameter values: "Bottom n", "Top n"
script: if(params["selection"].value = "TOP"){
arunearla
Hi,
I tried with "Bottom n", "Top n" parameters also.But it is not working.
could you please try to create a report for this. please spare your time to create a sample report for me.
regards
arun.
Hans_vd
Hi Arun,
I think you are almost there. Can you change the Select Data in the chart properties to "Inherit Data from Container" and see if it works? After all the filter is put on the table, not on the chart itself.
Regards
Hans
arunearla
Hi Hans,
I did the changes on select dataset chart properties to "Inherit Data from Container".But there is no change.
still the chart was not displaying according to my requirement.
is ther any other way to do this. below is the latest Attachment.
regards
arun.
Hans_vd
Hi Arun,<br />
<br />
There were still some errors in the script. The most important one: in the if statement there was "=" instead of "=="<br />
<br />
With this script it should work:<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>importPackage( Packages.org.eclipse.birt.report.engine.api.script.element );
importPackage( Packages.org.eclipse.birt.report.model.api.simpleapi );
if(params["selection"].value == "Top n"){
filterCondition= StructureScriptAPIFactory.createFilterCondition();
filterCondition.setExpr("row[\"SVCNAME\"]");
filterCondition.setOperator("top n");
filterCondition.setValue1("params[\"count\"].value");
filterKey = filterCondition.getStructure();
filterItem = SimpleElementFactory.getInstance().createFilterCondition( filterKey )
this.addFilterCondition( filterItem );
}
else if(params["selection"].value == "Bottom n"){
filterCondition= StructureScriptAPIFactory.createFilterCondition();
filterCondition.setExpr("row[\"SVCNAME\"]");
filterCondition.setOperator("bottom n");
filterCondition.setValue1("params[\"count\"].value");
filterKey = filterCondition.getStructure();
filterItem = SimpleElementFactory.getInstance().createFilterCondition( filterKey )
this.addFilterCondition( filterItem );
}</pre>
<br />
Regards<br />
Hans
arunearla
Hi Hans,<br />
<br />
It is working now
.Thanks a lot.Thanks for the your guidance ,in order to resolve my problem. I really did mistakes in the way. <a class='bbc_url' href='
http://www.birt-exchange.org/org/forum/public/style_emoticons/'>http://www.birt-exchange.org/org/forum/public/style_emoticons/</a><#EMO_DIR#>/confused.gif.you
are the one who guided me in the proper way.<br />
<br />
<strong class='bbc'> Thank You very much.<br />
</strong><br />
Regards<br />
arun
Hans_vd
Hi Arun,
You're welcome.
It's great to see you have it working now!
Regards
Hans
arunearla
Hi Hans,
Need some help from you. Along with filtering,i need to sort the data by column Total.
for this i wrote a query in crating the data set.
and i also tried to set the table property "sort".
But the chart was not displays according to given query.It was not displaying top/bottom entries according to given query.
query: select DISTINCT SVCNAME,STATUS,COUNT(STATUS) AS total from LOG_CONTENT WHERE CREATEDATE >=? and CREATEDATE <=? GROUP BY(SVCNAME,STATUS) ORDER BY TOTAL DESC.
Please help me, where i am going wrong.
Regards
Arun.