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)
Chart is not generated when data binding reference is a report item in 2.3.1
vradhika
I have a simple report with a table in it. During run time, I dynamically add columns to the table and insert a chart. If I set the table handle as the data binding reference for the chart, both the chart and the table are not generated.<br />
However, if I bind the chart to a data set, or run the report without the chart, the report works fine. The following is the code I used to generate the chart:<br />
<br />
private void createChart( ReportDesignHandle designHandle) throws SemanticException {<br />
ElementFactory elementFactory = designHandle.getElementFactory();<br />
TableHandle tableHandle = ( TableHandle )designHandle.findElement( "table" );<br />
ScriptDataSetHandle scriptDataSet = ( ScriptDataSetHandle ) designHandle.findDataSet( "ScriptedDataSet" );<br />
ExtendedItemHandle extendedItemHandle = elementFactory.newExtendedItem( null, "Chart" );<br />
try {<br />
extendedItemHandle.setWidth( "6in" );//$NON-NLS-1$<br />
extendedItemHandle.setHeight( "6in" );//$NON-NLS-1$<br />
extendedItemHandle.setProperty( "outputFormat", "PNG" );<br />
ChartWithAxes newChart = ChartWithAxesImpl.create();<br />
extendedItemHandle.getReportItem().setProperty( "chart.instance", createLineChart( newChart, settings ) );// extendedItemHandle.setDataBindingReference( tableHandle );<br />
int tablePos = designHandle.getBody().findPosn( tableHandle );<br />
designHandle.getBody().add( extendedItemHandle, tablePos ); <br />
} catch ( SemanticException e ) {<br />
e.printStackTrace();<br />
}<br />
}<br />
<br />
public static Chart createLineChart( ChartWithAxes newChart, ChartSettings settings ) {<br />
newChart.setType( "Line Chart" );<br />
newChart.setSubType( "Overlay" );<br />
<br />
// Plot<br />
newChart.getBlock().setBounds( BoundsImpl.create( 0, 0, 400, 350 ) );<br />
newChart.getBlock().setBackground( ColorDefinitionImpl.WHITE() );<br />
Plot p = newChart.getPlot();<br />
p.getClientArea().setBackground( ColorDefinitionImpl.create( 255, 255, 225 ) );<br />
<br />
// Title<br />
newChart.getTitle().getLabel().getCaption().setValue( settings.getTitle() );//$NON-NLS-1$<br />
newChart.getTitle().setVisible( true );<br />
<br />
// Legend<br />
newChart.getLegend().setVisible( true );<br />
<br />
// X-Axis<br />
Axis xAxisPrimary = ( ( ChartWithAxes ) newChart ).getPrimaryBaseAxes()[0];<br />
xAxisPrimary.setType( AxisType.TEXT_LITERAL );<br />
xAxisPrimary.getMajorGrid().setTickStyle( TickStyle.BELOW_LITERAL );<br />
xAxisPrimary.getOrigin().setType( IntersectionType.MIN_LITERAL );<br />
xAxisPrimary.getTitle().setVisible( true );<br />
xAxisPrimary.getTitle().getCaption().setValue( settings.getXAxisColumnTitle() );<br />
<br />
// Y-Axis<br />
Axis yAxisPrimary = ( ( ChartWithAxes ) newChart ).getPrimaryOrthogonalAxis( xAxisPrimary );<br />
yAxisPrimary.setType( AxisType.LINEAR_LITERAL );<br />
yAxisPrimary.getMajorGrid().setTickStyle( TickStyle.RIGHT_LITERAL );<br />
yAxisPrimary.getTitle().getCaption().setValue( settings.getYAxisColumnTitles()[0] );<br />
yAxisPrimary.getTitle().setVisible( true );<br />
<br />
// X-Series<br />
Series seCategory = SeriesImpl.create();<br />
SeriesDefinition sdX = SeriesDefinitionImpl.create();<br />
<br />
<br />
xAxisPrimary.getSeriesDefinitions().clear();<br />
xAxisPrimary.getSeriesDefinitions().add( sdX );<br />
sdX.getSeries().add( seCategory );<br />
Query query1 = QueryImpl.create( "row["" + settings.getXAxisColumn() + ""]" );//$NON-NLS-1$<br />
seCategory.getDataDefinition().clear();<br />
seCategory.getDataDefinition().add( query1 );<br />
<br />
<br />
for ( int i = 0; i < settings.getYAxisColumns().length; i++ ) {<br />
LineSeries ls1 = ( LineSeries ) LineSeriesImpl.create();<br />
ls1.setSeriesIdentifier( settings.getYAxisColumnTitles()
);<br />
ls1.setVisible( true );<br />
ls1.getLineAttributes().setColor( ColorDefinitionImpl.GREY() );<br />
for ( int j = 0; j < ls1.getMarkers().size(); j++ ) {<br />
( ( Marker ) ls1.getMarkers().get( j ) ).setType( MarkerType.BOX_LITERAL );<br />
}<br />
ls1.getLabel().setVisible( true );<br />
// Y-Sereis<br />
SeriesDefinition sdY = SeriesDefinitionImpl.create();<br />
sdY.getSeriesPalette().shift( i );<br />
<br />
Query query2 = QueryImpl.create( "row["" + settings.getYAxisColumns()[i] + ""]" );//$NON-NLS-1$<br />
yAxisPrimary.getSeriesDefinitions().add( sdY );<br />
sdY.getSeries().add( ls1 );<br />
ls1.getDataDefinition().add( query2 );<br />
}<br />
<br />
return newChart;<br />
}<br />
<br />
I don't see any errors in the logs. Has anybody come across this problem?<br />
<br />
Thanks,<br />
Radhika
Find more posts tagged with
Comments
mwilliams
Hi Radhika,<br />
<br />
I have not used the setDataBindingReference() method myself, so this is just a suggestion. Have you tried not casting the table element to a TableHandle and just using the table item as the parameter in the setDataBindingReference() method. The reason I say this is because the documentation is sorta confusing. It says the following:<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
setDataBindingReference
public void setDataBindingReference(ReportItemHandle item)
throws SemanticException
Sets the report item of which data binding are referred by.
Parameters:
item - the report item
</pre>
<br />
Which shows the parameter as both a handle and just the report item. So, it's possible that it doesn't want the table handle. It's worth a shot.
vradhika
Hi Michael,
I am only able to set the ReportItemHandle as the data binding reference. It will not accept a ReportItem.
Radhika
mwilliams
Radhika,
This may be a long shot too, but are you putting the chart inside the table? If so, is there any way you can put the chart outside the table in the report and see if it works. If you're putting the chart in the table and using the table for data as well, you may be running into a problem where the chart tries to grab the data from the table before it's available.
Another question is, if the chart works correctly if you bind it to the dataSet, what is the purpose of binding it to the table? Are you trying to use a certain grouping or filter that is in the table, in the chart too? Let me know. Thanks.
vradhika
Michael,
The chart is not inside the table. I am checking the position of the table and inserting the chart before that. And, yes. We have some data-specific renderers and logic in the table which we want to use in the chart as well.
I should also mention that this problem started only after we upgraded from 2.3.0 to 2.3.1.
Thanks,
Radhika
mwilliams
Radhika,<br />
<br />
Oh, well, if this worked for you in 2.3.0 and just not since you upgraded to 2.3.1, I'd suggest moving back to 2.3.0 and reporting a bug for this at <a class='bbc_url' href='
http://www.eclipse.org/birt/phoenix/reportabug.php'>BIRT
: Reporting Bugs and Requesting Enhancements</a>.