Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » BIRT » help with "Chart Builder Example"
help with "Chart Builder Example" [message #526340] Fri, 09 April 2010 17:38 Go to next message
roadblock2thesun is currently offline roadblock2thesunFriend
Messages: 14
Registered: April 2010
Junior Member
I have been looking into this example posted on the BirtExchange devShare: http:// www.birt-exchange.org/devshare/designing-birt-reports/1184-c hart-builder-example/#description

But I am having some trouble. I am not super familiar with java, and am stretching far outside my comfort zone and got kind of lost. I managed to create the project and fix the class paths, but I am not sure what to do next. I tried running "ChartWizardLauncher.java" as an eclipse application but get a null pointer exception.

Any help is much appreciated.

RB

ps. Here is the stack trace:

java.lang.NullPointerException at:
org.eclipse.birt.chart.ui.swt.wizard.TaskSelectType.doPreview(TaskSelectType.java:1926)
org.eclipse.birt.chart.ui.swt.wizard.TaskSelectType.createControl(TaskSelectType.java:247)
org.eclipse.birt.core.ui.frameworks.taskwizard.WizardBaseDialog.switchTask(WizardBaseDialog.java:317)
org.eclipse.birt.core.ui.frameworks.taskwizard.WizardBase.switchTo(WizardBase.java:229)
org.eclipse.birt.chart.ui.swt.wizard.ChartWizard.switchTo(ChartWizard.java:280)
org.eclipse.birt.core.ui.frameworks.taskwizard.WizardBaseDialog.initializeBounds(WizardBaseDialog.java:175)
org.eclipse.jface.window.Window.create(Window.java:435)
org.eclipse.jface.dialogs.Dialog.create(Dialog.java:1089)
org.eclipse.birt.core.ui.frameworks.taskwizard.WizardBaseDialog.create(WizardBaseDialog.java:185)
org.eclipse.jface.window.Window.open(Window.java:790)
org.eclipse.birt.core.ui.frameworks.taskwizard.WizardBase.open(WizardBase.java:87)
org.eclipse.birt.chart.ui.swt.wizard.ChartWizard.open(ChartWizard.java:234)
org.eclipse.birt.core.ui.frameworks.taskwizard.WizardBase.open(WizardBase.java:100)
ChartWizardLauncher.launch(ChartWizardLauncher.java:113)
ChartWizardLauncher.main(ChartWizardLauncher.java:187)

Caused By:null
org.eclipse.birt.chart.ui.swt.wizard.TaskSelectType.doPreview(TaskSelectType.java:1926)
org.eclipse.birt.chart.ui.swt.wizard.TaskSelectType.createControl(TaskSelectType.java:247)
org.eclipse.birt.core.ui.frameworks.taskwizard.WizardBaseDialog.switchTask(WizardBaseDialog.java:317)
org.eclipse.birt.core.ui.frameworks.taskwizard.WizardBase.switchTo(WizardBase.java:229)
org.eclipse.birt.chart.ui.swt.wizard.ChartWizard.switchTo(ChartWizard.java:280)
org.eclipse.birt.core.ui.frameworks.taskwizard.WizardBaseDialog.initializeBounds(WizardBaseDialog.java:175)
org.eclipse.jface.window.Window.create(Window.java:435)
org.eclipse.jface.dialogs.Dialog.create(Dialog.java:1089)
org.eclipse.birt.core.ui.frameworks.taskwizard.WizardBaseDialog.create(WizardBaseDialog.java:185)
org.eclipse.jface.window.Window.open(Window.java:790)
org.eclipse.birt.core.ui.frameworks.taskwizard.WizardBase.open(WizardBase.java:87)
org.eclipse.birt.chart.ui.swt.wizard.ChartWizard.open(ChartWizard.java:234)
org.eclipse.birt.core.ui.frameworks.taskwizard.WizardBase.open(WizardBase.java:100)
ChartWizardLauncher.launch(ChartWizardLauncher.java:113)
ChartWizardLauncher.main(ChartWizardLauncher.java:187)

[Updated on: Fri, 09 April 2010 17:38]

Report message to a moderator

Re: help with "Chart Builder Example" [message #526357 is a reply to message #526340] Fri, 09 April 2010 19:23 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason WeathersbyFriend
Messages: 9167
Registered: July 2009
Senior Member

Try the same project in
http://www.birt-exchange.org/devshare/deploying-birt-reports /1187-eclipsecon-2010-birt-metal-ppt/#description
examples. It is the ChartBuilder project.

Jason

cekali@gmail.com wrote:
> I have been looking into this example posted on the BirtExchange
> devShare: [url=http://www.birt-exchange.org/devshare/designing-birt-re
> ports/1184-chart-builder-example/#description][ /url]
>
> But I am having some trouble. I am not super familiar with java, and am
> stretching far outside my comfort zone and got kind of lost. I managed
> to create the project and fix the class paths, but I am not sure what to
> do next. I tried running "ChartWizardLauncher.java" as an eclipse
> application but get a null pointer exception.
> Any help is much appreciated.
>
> RB
>
> ps. Here is the stack trace:
>
>
> java.lang.NullPointerException at:
> org.eclipse.birt.chart.ui.swt.wizard.TaskSelectType.doPrevie w(TaskSelectType.java:1926)
>
> org.eclipse.birt.chart.ui.swt.wizard.TaskSelectType.createCo ntrol(TaskSelectType.java:247)
>
> org.eclipse.birt.core.ui.frameworks.taskwizard.WizardBaseDia log.switchTask(WizardBaseDialog.java:317)
>
> org.eclipse.birt.core.ui.frameworks.taskwizard.WizardBase.sw itchTo(WizardBase.java:229)
>
> org.eclipse.birt.chart.ui.swt.wizard.ChartWizard.switchTo(Ch artWizard.java:280)
>
> org.eclipse.birt.core.ui.frameworks.taskwizard.WizardBaseDia log.initializeBounds(WizardBaseDialog.java:175)
>
> org.eclipse.jface.window.Window.create(Window.java:435)
> org.eclipse.jface.dialogs.Dialog.create(Dialog.java:1089)
> org.eclipse.birt.core.ui.frameworks.taskwizard.WizardBaseDia log.create(WizardBaseDialog.java:185)
>
> org.eclipse.jface.window.Window.open(Window.java:790)
> org.eclipse.birt.core.ui.frameworks.taskwizard.WizardBase.op en(WizardBase.java:87)
>
> org.eclipse.birt.chart.ui.swt.wizard.ChartWizard.open(ChartW izard.java:234)
> org.eclipse.birt.core.ui.frameworks.taskwizard.WizardBase.op en(WizardBase.java:100)
>
> ChartWizardLauncher.launch(ChartWizardLauncher.java:113)
> ChartWizardLauncher.main(ChartWizardLauncher.java:187)
>
> Caused By:null
> org.eclipse.birt.chart.ui.swt.wizard.TaskSelectType.doPrevie w(TaskSelectType.java:1926)
>
> org.eclipse.birt.chart.ui.swt.wizard.TaskSelectType.createCo ntrol(TaskSelectType.java:247)
>
> org.eclipse.birt.core.ui.frameworks.taskwizard.WizardBaseDia log.switchTask(WizardBaseDialog.java:317)
>
> org.eclipse.birt.core.ui.frameworks.taskwizard.WizardBase.sw itchTo(WizardBase.java:229)
>
> org.eclipse.birt.chart.ui.swt.wizard.ChartWizard.switchTo(Ch artWizard.java:280)
>
> org.eclipse.birt.core.ui.frameworks.taskwizard.WizardBaseDia log.initializeBounds(WizardBaseDialog.java:175)
>
> org.eclipse.jface.window.Window.create(Window.java:435)
> org.eclipse.jface.dialogs.Dialog.create(Dialog.java:1089)
> org.eclipse.birt.core.ui.frameworks.taskwizard.WizardBaseDia log.create(WizardBaseDialog.java:185)
>
> org.eclipse.jface.window.Window.open(Window.java:790)
> org.eclipse.birt.core.ui.frameworks.taskwizard.WizardBase.op en(WizardBase.java:87)
>
> org.eclipse.birt.chart.ui.swt.wizard.ChartWizard.open(ChartW izard.java:234)
> org.eclipse.birt.core.ui.frameworks.taskwizard.WizardBase.op en(WizardBase.java:100)
>
> ChartWizardLauncher.launch(ChartWizardLauncher.java:113)
> ChartWizardLauncher.main(ChartWizardLauncher.java:187)
>
Re: help with "Chart Builder Example" [message #526612 is a reply to message #526357] Mon, 12 April 2010 12:19 Go to previous messageGo to next message
roadblock2thesun is currently offline roadblock2thesunFriend
Messages: 14
Registered: April 2010
Junior Member
Thanks, I have it running now.

How do I provide the input data?

RB
Re: help with "Chart Builder Example" [message #526712 is a reply to message #526612] Mon, 12 April 2010 17:06 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason WeathersbyFriend
Messages: 9167
Registered: July 2009
Senior Member

Right now that example does not include data mapping using the gui, but
you should be able to take the model that it generates and map data to
it using the SerializerExample in the same download or by looking at the
bindGroupingData function in the code below. I will try to update the
example to support the data selection in the gui.

Jason


import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;

import org.eclipse.birt.chart.api.ChartEngine;
import org.eclipse.birt.chart.device.IDeviceRenderer;
import org.eclipse.birt.chart.device.IDisplayServer;
import org.eclipse.birt.chart.exception.ChartException;
import org.eclipse.birt.chart.factory.GeneratedChartState;
import org.eclipse.birt.chart.factory.Generator;
import org.eclipse.birt.chart.factory.IDataRowExpressionEvaluator;
import org.eclipse.birt.chart.factory.IGenerator;
import org.eclipse.birt.chart.factory.RunTimeContext;
import org.eclipse.birt.chart.model.Chart;
import org.eclipse.birt.chart.model.ChartWithAxes;
import org.eclipse.birt.chart.model.ChartWithoutAxes;
import org.eclipse.birt.chart.model.attribute.Anchor;
import org.eclipse.birt.chart.model.attribute.AxisType;
import org.eclipse.birt.chart.model.attribute.Bounds;
import org.eclipse.birt.chart.model.attribute.ChartDimension;
import org.eclipse.birt.chart.model.attribute.DataType;
import org.eclipse.birt.chart.model.attribute.SortOption;
import org.eclipse.birt.chart.model.attribute.impl.BoundsImpl;
import org.eclipse.birt.chart.model.attribute.impl.ColorDefinitionI mpl;
import org.eclipse.birt.chart.model.attribute.impl.GradientImpl;
import org.eclipse.birt.chart.model.component.Axis;
import org.eclipse.birt.chart.model.component.Series;
import org.eclipse.birt.chart.model.component.impl.SeriesImpl;
import org.eclipse.birt.chart.model.data.BaseSampleData;
import org.eclipse.birt.chart.model.data.DataFactory;
import org.eclipse.birt.chart.model.data.OrthogonalSampleData;
import org.eclipse.birt.chart.model.data.Query;
import org.eclipse.birt.chart.model.data.SampleData;
import org.eclipse.birt.chart.model.data.SeriesDefinition;
import org.eclipse.birt.chart.model.data.impl.QueryImpl;
import org.eclipse.birt.chart.model.data.impl.SeriesDefinitionImpl;
import org.eclipse.birt.chart.model.impl.ChartWithAxesImpl;
import org.eclipse.birt.chart.model.impl.ChartWithoutAxesImpl;
import org.eclipse.birt.chart.model.layout.Legend;
import org.eclipse.birt.chart.model.layout.Plot;
import org.eclipse.birt.chart.model.type.LineSeries;
import org.eclipse.birt.chart.model.type.PieSeries;
import org.eclipse.birt.chart.model.type.impl.LineSeriesImpl;
import org.eclipse.birt.chart.model.type.impl.PieSeriesImpl;
import org.eclipse.birt.core.framework.PlatformConfig;


/**
* Test decription:
* </p>
* Chart script: afterDataSetFilled()
* </p>
*/

public class AfterDatasetFilled
{
private static String OUTPUT = "output/DataRowEvaluator.png";

/**
* The swing rendering device
*/
private IDeviceRenderer dRenderer = null;
private IDisplayServer dServer = null;

private GeneratedChartState gcs = null;
private IGenerator gr = null;
/**
* A chart model instance
*/
private Chart cm = null;

/**
* execute application
*
* @param args
*/
public static void main( String[] args )
{
new AfterDatasetFilled( );
System.out.println("finished");
}

/**
* Constructor
*/
public AfterDatasetFilled( )
{
PlatformConfig pf = new PlatformConfig();
pf.setProperty("STANDALONE", true);

//Returns a singleton instance of the Chart Engine
ChartEngine ce = ChartEngine.instance(pf);
//Returns a singleton instance of the Generator
gr = ce.getGenerator();

try {
//device renderers for dv.SWT, dv.PNG, dv.JPG
//dv.PDF, dv.SVG, dv.SWING, dv.PNG24, div.BMP
dRenderer = ce.getRenderer("dv.PNG");
dServer = dRenderer.getDisplayServer();
} catch (Exception ex) {
ex.printStackTrace();
}

cm = createPieChart( );
bindGroupingData( cm );

BufferedImage img = new BufferedImage(
600,
600,
BufferedImage.TYPE_INT_ARGB );
Graphics g = img.getGraphics( );

Graphics2D g2d = (Graphics2D) g;
dRenderer.setProperty( IDeviceRenderer.GRAPHICS_CONTEXT, g2d );
dRenderer.setProperty( IDeviceRenderer.FILE_IDENTIFIER, OUTPUT );
//$NON-NLS-1$

Bounds bo = BoundsImpl.create( 0, 0, 600, 600 );
bo.scale( 72d / dRenderer.getDisplayServer( ).getDpiResolution( ) );



try
{
gcs = gr.build(
dServer,
cm,
bo,
null,
null,
null );
gr.render( dRenderer, gcs );
}
catch ( ChartException e )
{
// TODO Auto-generated catch block
e.printStackTrace( );
}



}
public Chart GetChartModel(){
return cm;
}

private void bindGroupingData( Chart chart )

{

//IDataRowExpressionEvaluator
// close, evaluate, first, and next
// Data Set
final Object[][] data =
new Object[][]
{{"x1", new Integer( 1 ), "g1"},
{"x1", new Integer( 2 ), "g2"},
{"x1", new Integer( 3 ), "g1"},
{"x1", new Integer( 4 ), "g3"},
{"x1", new Integer( 5 ), "g2"},
{"x2", new Integer( 6 ), "g1"},
{"x2", new Integer( 7 ), "g3"},
{"x2", new Integer( 8 ), "g2"},
{"x2", new Integer( 9 ), "g2"},
{"x0", new Integer( 0 ), "g2"},};
try
{
//Binds data to chart model
gr.bindData( new IDataRowExpressionEvaluator( ) {

int idx = 0;

public void close( )
{
}

public Object evaluate( String expression )
{
if ( "X".equals( expression ) )
{
return data[idx][0];
}
else if ( "Y".equals( expression ) )
{
return data[idx][1];
}
else if ( "G".equals( expression ) )
{
return data[idx][2];
}
return null;
}

public Object evaluateGlobal( String expression )
{
return evaluate( expression );
}

public boolean first( )
{
idx = 0;
return true;
}

public boolean next( )
{
idx++;
return ( idx < 9 );
}
}, chart, new RunTimeContext( ) );

}
catch ( ChartException e )
{
e.printStackTrace( );

}
}

private Chart createChart( )

{
ChartWithAxes cwaBar = ChartWithAxesImpl.create( );


// X-Axis
Axis xAxisPrimary = cwaBar.getPrimaryBaseAxes( )[0];
xAxisPrimary.setType( AxisType.TEXT_LITERAL );

// Y-Axis
Axis yAxisPrimary = cwaBar.getPrimaryOrthogonalAxis( xAxisPrimary );
yAxisPrimary.setType( AxisType.LINEAR_LITERAL );



// X-Series
Series seCategory = SeriesImpl.create( );
Query xQ = QueryImpl.create( "G" );
seCategory.getDataDefinition( ).add( xQ );
SeriesDefinition sdX = SeriesDefinitionImpl.create( );
xAxisPrimary.getSeriesDefinitions( ).add( sdX );
sdX.getSeries( ).add( seCategory );

// ------------------------------------------------------------ -

sdX.setSorting( SortOption.ASCENDING_LITERAL );
sdX.getGrouping( ).setEnabled( true );
sdX.getGrouping( ).setGroupType( DataType.TEXT_LITERAL );
sdX.getGrouping( ).setAggregateExpression( "Sum" );
sdX.getGrouping( ).setGroupingInterval( 0 );


// ------------------------------------------------------------ -

// Y-Series
LineSeries ls = (LineSeries) LineSeriesImpl.create( );
ls.getLabel( ).setVisible( true );
Query yQ = QueryImpl.create( "Y" );
ls.getDataDefinition( ).add( yQ );
SeriesDefinition sdY = SeriesDefinitionImpl.create( );
Query query = QueryImpl.create( "X" );//$NON-NLS-1$
sdY.setQuery( query );
yAxisPrimary.getSeriesDefinitions( ).add( sdY );
sdY.getSeriesPalette( ).shift( 0 );
sdY.getSeries( ).add( ls );

return cwaBar;

}
public final static Chart createPieChart( )
{
ChartWithoutAxes cwoaPie = ChartWithoutAxesImpl.create( );
cwoaPie.setDimension(
ChartDimension.TWO_DIMENSIONAL_WITH_DEPTH_LITERAL );
cwoaPie.setType( "Pie Chart" );
cwoaPie.setSubType( "Standard Pie Chart" );

// Plot
cwoaPie.getBlock( ).setBackground(
ColorDefinitionImpl.WHITE( ) );
Plot p = cwoaPie.getPlot( );
p.getClientArea( )
.setBackground( GradientImpl.create(
ColorDefinitionImpl.create( 225,
225,
255 ),
ColorDefinitionImpl.create( 255, 255,
225 ),
-35,
false ) );
p.getOutline( ).setVisible( true );

// Title

// Legend
Legend lg = cwoaPie.getLegend( );
lg.getText( ).getFont( ).setSize( 16 );
lg.getInsets( ).set( 10, 5, 0, 0 );
lg.setAnchor( Anchor.NORTH_LITERAL );


// Title
cwoaPie.getTitle( ).getLabel( ).getCaption( ).setValue(
"Pie Chart" );


SampleData sdata = DataFactory.eINSTANCE.createSampleData( );
BaseSampleData sdBase =
DataFactory.eINSTANCE.createBaseSampleData( );
sdBase.setDataSetRepresentation( "" );
sdata.getBaseSampleData( ).add( sdBase );

OrthogonalSampleData sdOrthogonal =
DataFactory.eINSTANCE.createOrthogonalSampleData( );
sdOrthogonal.setDataSetRepresentation( "" );
sdOrthogonal.setSeriesDefinitionIndex( 0 );
sdata.getOrthogonalSampleData( ).add( sdOrthogonal );

cwoaPie.setSampleData( sdata );

// Base Series

// X-Series

//**
Series seCategory = SeriesImpl.create( );

SeriesDefinition sd = SeriesDefinitionImpl.create( );
seCategory.setSeriesIdentifier("cs2");
Query query = QueryImpl.create( "X" );//$NON-NLS-1$
seCategory.getDataDefinition( ).add( query );

cwoaPie.getSeriesDefinitions( ).add( sd );
sd.getSeriesPalette( ).shift( 0 );
sd.getSeries( ).add( seCategory );

// Orthogonal Series
PieSeries sePie = (PieSeries) PieSeriesImpl.create( );

sePie.setSeriesIdentifier( "Events");
Query query1 = QueryImpl.create("Y");//$NON-NLS-1$
sePie.getDataDefinition().add(query1);
sePie.setExplosion( 5 );


sePie.getLabel().setVisible(true);
SeriesDefinition sd2 = SeriesDefinitionImpl.create( );
sd.getSeriesDefinitions( ).add( sd2 );
sd2.getSeries( ).add( sePie );

return cwoaPie;

}
}


roadblock2thesun wrote:
> Thanks, I have it running now.
> How do I provide the input data?
>
> RB
Re: help with "Chart Builder Example" [message #526733 is a reply to message #526712] Mon, 12 April 2010 18:31 Go to previous messageGo to next message
roadblock2thesun is currently offline roadblock2thesunFriend
Messages: 14
Registered: April 2010
Junior Member
Thanks for the information, I will have to look at it more closely.

I was originally tasked with creating some reports, which was easy enough. However my user wants a great variety of graphs with varying levels of customization so I thought giving them the chart builder would be the way to go. Unfortunately, I am not a developer and understanding the API's and the plugin architecture is proving to be rather difficult (and time consuming). So, I thank you very much for your help.

RB
Re: help with "Chart Builder Example" [message #1097576 is a reply to message #526357] Thu, 29 August 2013 22:59 Go to previous messageGo to next message
piyali deb is currently offline piyali debFriend
Messages: 1
Registered: August 2013
Junior Member
Hi,

I am having the same problem mentioned here. I tried to go to the address mentioned, but looks like the link is broken. Can you please help?

On a side note, this is what I am trying to do, can you please let me know if this makes sense?

Create some chart models (template) using the chart builder.
Use this models in my standalone java application and then build the data set at runtime.
Dynamically update the dataset, and bind it to the chart models.
Build the chart and render it.

Thanks,
Deb
Re: help with "Chart Builder Example" [message #1098437 is a reply to message #1097576] Sat, 31 August 2013 04:08 Go to previous message
Michael Williams is currently offline Michael WilliamsFriend
Messages: 1925
Registered: July 2009
Senior Member

Here are updated links for both of the links above.

http://www.birt-exchange.org/devshare/_/designing-birt-reports/1184-chart-builder-example

http://www.birt-exchange.org/devshare/_/designing-birt-reports/1187-eclipsecon-2010-birt-metal-ppt

As for your scenario, are you going to just be using the Chart Engine? Or building report templates?


Michael

Developer Evangelist, Silanis
Previous Topic:Concatenate Show All Values
Next Topic:How to call BIRT report
Goto Forum:
  


Current Time: Sun Sep 19 23:41:04 GMT 2021

Powered by FUDForum. Page generated in 0.01613 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top