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)
Creating chart programatically getting warning
dlpraju
Hi ,
When i am creating a chart programatically i am getting a warning as follows
Warning:
org.eclipse.birt.chart.internal.datafeed.ResultSetWrapper initializeMeta
WARNING: Unable to determine data types from resultset
And it is drawing the chart in rptdesign file.But when i open the same in birt and select the chart and edit i am getting the following error.
Error:
"Column binding "row["Year"]" has referred to a binding "Year" which does not exist."
Thank you,
Laxmipathi Raju
Find more posts tagged with
Comments
mwilliams
Hi Laxmipathi Raju,
Are you sure you're getting it bound to the dataSet correctly? Also, you may double check your bindings for the chart to see if "Year" might be "year".
dlpraju
Hi Michael,
Thanks for your reply.And i have checked the binding value it is "Year" only and here i am sending my code to you can u please check it once.
/**
* Reads a BIRT report design file, adds a chart and writes a
* new report design file containing the added chart.
* Run this application with the following command line:
* java ChartReportApp origDesing modifiedDesign
*/
public class ChartReportApp
{
IDesignEngine dEngine = null;
IReportEngine engine = null;
public static class CustomOSGiPlatformContext implements IPlatformContext {
public String getPlatform() {
StringBuffer sb = new StringBuffer("D:/Omega/workspace/Omega_xlsMerging/platform_birt/platform_birt_2.5");
return sb.toString();
}
}
ChartReportApp () {
EngineConfig eC = new EngineConfig();
DesignConfig dC = new DesignConfig();
eC = new EngineConfig();
eC.setEngineHome("D:/Omega/workspace/Omega_xlsMerging/platform_birt/platform_birt_2.5");
eC.setPlatformContext(new CustomOSGiPlatformContext());
dC = new DesignConfig();
dC.setBIRTHome("D:/Omega/workspace/Omega_xlsMerging/platform_birt/platform_birt_2.5");
dC.setPlatformContext(new CustomOSGiPlatformContext());
try {
Platform.startup(eC);
Platform.startup(dC);
} catch (BirtException e) {
}
//try{
IDesignEngineFactory factory = (IDesignEngineFactory) Platform
.createFactoryObject( IDesignEngineFactory.EXTENSION_DESIGN_ENGINE_FACTORY );
dEngine = factory.createDesignEngine(dC);
IReportEngineFactory factory1 = (IReportEngineFactory) Platform
.createFactoryObject(IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY);
engine = factory1.createReportEngine(eC);
//}catch( Exception ex){
// ex.printStackTrace();
//}
}
/* Give default values to the original design, the new design,
* and the output format.
* Extract command line values, if any.
* Create an instance of this class, build a chart,
* and run the report
*/
public static void main(String[] args)
{
String reportDesign = "reports/SamPopulation.rptdesign";
String newReportDesign = "reports/Test_modified1.rptdesign";
String format = HTMLRenderOption.OUTPUT_FORMAT_HTML;
boolean showInfo = true;
if(args.length > 0){
reportDesign = args[0];
}
if(args.length > 1){
newReportDesign = args[1];
}
ChartReportApp cra = new ChartReportApp( );
cra.build( reportDesign, newReportDesign );
cra.run( newReportDesign, format );
}
/** Build a chart
*/
public void build ( String origDesign, String newDesign )
{
// Get a new DesignEngine session
SessionHandle sessionHandle = dEngine.newSessionHandle( (ULocale) null );
// Get a handle to the original report design
ReportDesignHandle designHandle = null;
try {
designHandle = sessionHandle.openDesign( origDesign );
} catch ( DesignFileException e1 ) {
e1.printStackTrace( );
}
// Create a new chart instance object
ChartWithAxes newChart = ChartWithAxesImpl.create( );
// Set the properties of the chart
newChart.setType( "Line Chart" );
newChart.setSubType( "Overlay" );
newChart.getBlock().setBackground(
ColorDefinitionImpl.WHITE() );
newChart.getBlock().setBounds(
BoundsImpl.create( 0, 0, 400, 250 ) );
//Plot
Plot p = newChart.getPlot();
p.getClientArea().setBackground(
ColorDefinitionImpl.create( 255, 255, 225 ));
p.getOutline().setVisible(true);
newChart.getTitle().getLabel().getCaption().setValue( "Europe" );
//Legend
Legend lg = newChart.getLegend();
LineAttributes lia = lg.getOutline();
lg.getText().getFont().setSize( 16 );
lia.setStyle( LineStyle.SOLID_LITERAL );
lg.getInsets().set( 1, 1, 1, 1 );
lg.getOutline().setVisible( false );
lg.setAnchor( Anchor.NORTH_LITERAL );
//X-axis
Axis xAxisPrimary = newChart.getPrimaryBaseAxes()[0];
xAxisPrimary.setType( AxisType.TEXT_LITERAL );
xAxisPrimary.getMajorGrid().setTickStyle(TickStyle.BELOW_LITERAL );
xAxisPrimary.getOrigin().setType(IntersectionType.VALUE_LITERAL );
xAxisPrimary.getTitle( ).getCaption( ).setValue( "EmpName" );
xAxisPrimary.getTitle( ).setVisible( false );
//Y-axis
Axis yAxisPrimary = newChart.getPrimaryOrthogonalAxis( xAxisPrimary );
yAxisPrimary.getMajorGrid().setTickStyle(TickStyle.LEFT_LITERAL );
yAxisPrimary.setType( AxisType.LINEAR_LITERAL );
yAxisPrimary.getTitle().getCaption().setValue( "EmpNum" );
// Create sample data.
SampleData sdt = DataFactory.eINSTANCE.createSampleData();
BaseSampleData sdBase =
DataFactory.eINSTANCE.createBaseSampleData();
sdBase.setDataSetRepresentation("A");
sdt.getBaseSampleData().add( sdBase );
OrthogonalSampleData sdOrthogonal =
DataFactory.eINSTANCE.createOrthogonalSampleData();
sdOrthogonal.setDataSetRepresentation( "1");
sdOrthogonal.setSeriesDefinitionIndex(0);
sdt.getOrthogonalSampleData().add( sdOrthogonal );
newChart.setSampleData(sdt);
Series seCategory = SeriesImpl.create();
Query query = QueryImpl.create( "row["Year"]" );
seCategory.getDataDefinition().add( query );
LineSeries ls1 = ( LineSeries ) LineSeriesImpl.create();
ls1.setSeriesIdentifier("Q1");
Query query1 = QueryImpl.create("row["Pop_in_million"]");
ls1.getDataDefinition().add(query1);
ls1.getLineAttributes().setColor(
ColorDefinitionImpl.RED());
ls1.getMarker().setType(MarkerType.TRIANGLE_LITERAL);
ls1.getLabel().setVisible(true);
ls1.getLabel().getCaption().setValue( "Q1" );
SeriesDefinition sdX = SeriesDefinitionImpl.create();
sdX.getSeriesPalette().shift( 0 );
xAxisPrimary.getSeriesDefinitions().add( sdX );
sdX.getSeries().add(seCategory);
SeriesDefinition sdY1 = SeriesDefinitionImpl.create();
sdY1.getSeriesPalette().shift( 0 );
yAxisPrimary.getSeriesDefinitions().add( sdY1 );
sdY1.getSeries().add( ls1 );
ElementFactory ef = designHandle.getElementFactory( );
ExtendedItemHandle extendedItemHandle =
ef.newExtendedItem( null, "Chart" );
try{
extendedItemHandle.getReportItem( ).setProperty( "chart.instance",
newChart );
} catch( ExtendedElementException e )
{
e.printStackTrace( );
}
OdaDataSetHandle dataSet = ( OdaDataSetHandle )
designHandle.getDataSets( ).get( 0 );
try {
extendedItemHandle.setDataSet( dataSet );
extendedItemHandle.setHeight( "250pt" );
extendedItemHandle.setWidth( "400pt" );
} catch ( SemanticException e ) {
e.printStackTrace( );
}
// Add the chart to the report design (TableHandle or ListHandle)
TableHandle li = (TableHandle) designHandle.
getBody( ).getContents( ).get( 0 );
try {
designHandle.getBody().add( extendedItemHandle );
} catch ( ContentException e3 ) {
e3.printStackTrace( );
} catch ( NameException e3 ) {
e3.printStackTrace( );
}
// Save the report design that now contains a chart
try {
designHandle.saveAs( newDesign );
} catch ( IOException e ) {
e.printStackTrace( );
}
designHandle.close();
}
/* Run the report design that contains the new chart.
* Depending on format parameter, this method creates either
* an HTML report or a PDF report.
*/
public void run( String reportDesign, String format )
{
// Create an image handler object
IReportRunnable report = null;
try
{
report = engine.openReportDesign( reportDesign );
}
catch ( EngineException e )
{
System.err.println( "Report " + reportDesign +
" not found!n" );
engine.destroy( );
return;
}
// Create a task to run the report
IRunAndRenderTask task = engine.createRunAndRenderTask( report );
HTMLRenderOption options = new HTMLRenderOption( );
// Set the output format, either HTML or PDF
options.setOutputFormat( format );
// Give the report the same name as the design,
// except give it the appropriate extension
String output = reportDesign.replaceFirst( ".rptdesign",
"." + format );
options.setOutputFileName( output );
task.setRenderOption( options );
EngineConstants.APPCONTEXT_HTML_RENDER_CONTEXT,
// renderContext );
try {
task.run( );
}
catch ( EngineException e1 )
{
System.err.println( "Report " + reportDesign +
" run failed.n" );
System.err.println( e1.toString( ) );
}
engine.destroy( );
}
}
And the Warning is :
Apr 24, 2010 12:25:02 PM org.eclipse.birt.chart.internal.datafeed.ResultSetWrapper initializeMeta
WARNING: Unable to determine data types from resultset
And if i see in birt the x-axis and y-axis values are not comming in and the graph is not drawn in the chart only x axis is drawn with null values and y axis is drawn with -2 to +2 values.
Thank you
Laxmipathi Raju
yangmichael
<pre class="_prettyXprint _lang-js">
cht = reportContext.getDesignHandle().findElement("yourChart");
var colbinds = cht.getColumnBindings( );
var cs1 = StructureFactory.createComputedColumn( );
cs1.setName("Year");
cs1.setExpression( "dataSetRow[\"Year"+"\"]" );
colbinds.addItem( cs1 );
//Create the query. The row value must correlate with the data set row value
var qry = QueryImpl.create("row[\"" + "Year" + "\"]" );
</pre>
<p>Hi <span style="color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;">Laxmipathi Raju,</span></p>
<p> </p>
<p><span style="color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;">I think you didn't bind the "year" data column to your chart.</span></p>
<p><span style="color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;">Use the code above, it should work.</span></p>