Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
PUBLIC CLOUD
PRIVATE CLOUD
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
Clear chart series and pass new data
shivkumar150
<p>Hi All,</p>
<p> </p>
<p>I've somewhat achieved my goal but till midway. Using CSV datasource, I increment report variables to get count of a specific data. Now using these variables, I need to plot a bar chart. In the afterDatasetFilled function, I need to clear the existing series and put the report variable data.</p>
<p> </p>
<p>Dataset afterClose method</p>
<pre class="_prettyXprint">
reportContext.setGlobalVariable("Tcad",vars["totalcad"]); </pre>
<p>Chart afterDatasetFilled method</p>
<div>
<pre class="_prettyXprint">
function afterDataSetFilled( series, dataSet, icsc )
{
importPackage( Packages.java.util );
importPackage(Packages.java.lang);
importPackage( Packages.org.eclipse.birt.chart.model.type.impl );
importPackage( Packages.org.eclipse.birt.chart.model.data.impl);
rpCtx=icsc.getExternalContext().getScriptable();
var totalCad=rpCtx.getGlobalVariable("Tcad");
var newseriesarr=new ArrayList();
if(series.getSeriesIdentifier()=="Series1"){
newseriesarr.add(totalCad);
}else{
newseriesarr.add("TotalCAD");
}
if(series.getSeriesIdentifier()=="Series1"){
dataSet.setValues(newseriesarr);
}else{
dataSet.setValues(newseriesarr);
}</pre>
</div>
<p>It is the series clearing and adding the new dataSet, that is pending.</p>
<p> </p>
<p>Or is there any more effective way to achieve the bar chart creation with data aggregation.</p>
<p> </p>
<p>I've attached the rptdeisgn and csv datasource.</p>
Find more posts tagged with
Comments
Clement Wong
<p>What is the "count of a specific data"?</p>
<p> </p>
<p>It appears from your code in <em>onFetch </em>that you want to count for each "Item", if the "ItemType" contains 'CAD' and Status is 'Released'?</p>
<p> </p>
<p>There is an easier way. Instead of the code that you implemented, in the Chart, you can change the Value (Y) Series aggregation function from Default (Sum) to Count.</p>
<p> </p>
<p>And in the Expression for that:</p>
<pre class="_prettyXprint">
if (row["ItemType"].toLowerCase().indexOf("cad")!=-1) {
if (row["Status"] == 'Released') 1;
else null;
}
else {
null;
}
</pre>
<p>Also, all the code in beforeOpen, onFetch, afterClose, etc... can be removed and be replaced by inserting Aggregation(s) instead.</p>
<p> </p>
<p>For example, COUNT of all CAD:</p>
<pre class="_prettyXprint">
if (row["ItemType"].toLowerCase().indexOf("cad")!=-1) {
1;
}
else {
null;
}
</pre>
<p>Attached is a revised design modified and tested in OS BIRT 4.5.0.</p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
shivkumar150
<p>Thanks Clement for the quick reply.</p>
<p> </p>
<p>So, finally achieved the needed report. Your advice of changing Value (Y) series aggregation helped. </p>
<p>So, the major changes were as follows:</p>
<p>1) Changed Value(Y) Series aggregation to Count.</p>
<p>2) In Category (X) Series, I selected the ItemType, which sorted the data according to data type.</p>
<p>3) Created another series, where data was sorted according to "Status" using below script:</p>
<div>
<pre class="_prettyXprint">
if (row["Status"] == 'Released') 1;
else null;</pre>
</div>
<p>Thanks once again for quick help.</p>
<p> </p>
<p>BIRT version 4.5.0</p>
<p> </p>