Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » BIRT » .chart vs .rptdesign format difference?
.chart vs .rptdesign format difference? [message #522972] Wed, 24 March 2010 16:05 Go to next message
bob is currently offline bobFriend
Messages: 60
Registered: July 2009
Member
I need to use the standalone Chart API in my application. This way I can
simply load the chart using:

ChartWithAxes chart = ChartWithAxesImpl.create();
Serializer si = SerializerImpl.instance();
try {
si.write(chart, new FileOutputStream(new
File(c:\\myChart.rptdesign)));
} catch (Exception e) {
}


without having to specify the whole BIRT runtime dir.

But I would like to setup the style and color before loading the chart.
Currently I do this by adding a chart to a blank .rptdesign file but I
cannot load a .rptdesign file using the above approach (to load a .rptdesign
file the whole BIRT runtime lib must be specified).

Is it possible to extract a chart from a .rptdesign file to the .chart
format?

Or is it possible to get a stand alone chart editor for charts in the .chart
format for eclipse?

I have looked at this:

http://www.birt-exchange.org/devshare/interactive-reporting/ 145-standalone-chart-engine-and-builder-examples/#descriptio n

but it could be nice if charts could be edited using the BIRT plugin for
eclipse (based on the .rptdesign format) instead of installing a new editor.
Re: .chart vs .rptdesign format difference? [message #523277 is a reply to message #522972] Thu, 25 March 2010 18:06 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason WeathersbyFriend
Messages: 9167
Registered: July 2009
Senior Member

Bob,

Using the RE API you can get the chart model from a report design like:


import java.io.IOException;

import org.eclipse.birt.chart.model.Chart;
import org.eclipse.birt.chart.model.ChartWithAxes;
import org.eclipse.birt.chart.model.attribute.DataType;
import org.eclipse.birt.chart.model.attribute.SortOption;
import org.eclipse.birt.chart.model.component.Axis;
import org.eclipse.birt.chart.model.data.SeriesDefinition;
import org.eclipse.birt.core.framework.Platform;
import org.eclipse.birt.report.model.api.DesignConfig;
import org.eclipse.birt.report.model.api.DesignEngine;
import org.eclipse.birt.report.model.api.DesignFileException;
import org.eclipse.birt.report.model.api.ExtendedItemHandle;
import org.eclipse.birt.report.model.api.IDesignEngine;
import org.eclipse.birt.report.model.api.IDesignEngineFactory;
import org.eclipse.birt.report.model.api.ReportDesignHandle;
import org.eclipse.birt.report.model.api.SessionHandle;
import org.eclipse.birt.report.model.api.extension.ExtendedElementE xception;

import com.ibm.icu.util.ULocale;

/**
* Presents a bar chart with grouping on X series, which could be
acheived in
* the report designer as follows: Chart Builder -> Data -> X Series ->
Set Dat
* Sorting / Tick Grouping Enabled
*/
public class GroupOnXSeries
{

/**
* execute application
*
* @param args
*/
public static void main( String[] args )
{
new GroupOnXSeries( ).groupSeries( );

}

/**
* Get the chart instance from the design file and group X series of the
* chart.
*
* @return An instance of the simulated runtime chart model (containing
* filled datasets)
*/
void groupSeries( )
{


ReportDesignHandle designHandle = null;
DesignConfig config = new DesignConfig( );

config.setBIRTHome("C:/birt/birt-runtime-2_5_1/birt-runtime-2_5_1/ReportEngine ");
IDesignEngine engine = null;
try{

Platform.startup( config );
IDesignEngineFactory factory = (IDesignEngineFactory) Platform
.createFactoryObject(
IDesignEngineFactory.EXTENSION_DESIGN_ENGINE_FACTORY );
engine = factory.createDesignEngine( config );

}catch( Exception ex){
ex.printStackTrace();
}

SessionHandle sessionHandle = engine.newSessionHandle( (ULocale) null );


try
{
designHandle = sessionHandle.openDesign(
"report/NonGroupOnXSeries.rptdesign" );//$NON-NLS-1$
}
catch ( DesignFileException e )
{
// TODO Auto-generated catch block
e.printStackTrace( );
}

ExtendedItemHandle eih = (ExtendedItemHandle) designHandle.getBody( )
.getContents( ).get( 0 );

Chart cm = null;
try
{
cm = (Chart) eih.getReportItem( ).getProperty( "chart.instance" );
//$NON-NLS-1$
}
catch ( ExtendedElementException e )
{
// TODO Auto-generated catch block
e.printStackTrace( );
}

cm.getTitle( ).getLabel( ).getCaption( ).setValue( "Group On X Series"
);//$NON-NLS-1$

cm.getTitle( ).getLabel( ).getCaption( ).getFont().setSize(12);
cm.getTitle( ).getLabel( ).getCaption( ).getFont().setRotation(45);

SeriesDefinition sdX = (SeriesDefinition) ( (Axis) ( (ChartWithAxes) cm )
.getAxes( ).get( 0 ) ).getSeriesDefinitions( ).get( 0 );

sdX.setSorting( SortOption.ASCENDING_LITERAL );
sdX.getGrouping( ).setEnabled( true );
sdX.getGrouping( ).setAggregateExpression( "Sum" );//$NON-NLS-1$
sdX.getGrouping( ).setGroupType( DataType.NUMERIC_LITERAL );
sdX.getGrouping( ).setGroupingInterval( 1 );


try
{
designHandle.saveAs( "report/GroupOnXSeries.rptdesign" );//$NON-NLS-1$
}
catch ( IOException e )
{
e.printStackTrace( );
}
Platform.shutdown();

}

}

Jason

bob wrote:
> I need to use the standalone Chart API in my application. This way I can
> simply load the chart using:
>
> ChartWithAxes chart = ChartWithAxesImpl.create();
> Serializer si = SerializerImpl.instance();
> try {
> si.write(chart, new FileOutputStream(new
> File(c:\\myChart.rptdesign)));
> } catch (Exception e) {
> }
>
>
> without having to specify the whole BIRT runtime dir.
>
> But I would like to setup the style and color before loading the chart.
> Currently I do this by adding a chart to a blank .rptdesign file but I
> cannot load a .rptdesign file using the above approach (to load a
> .rptdesign file the whole BIRT runtime lib must be specified).
>
> Is it possible to extract a chart from a .rptdesign file to the .chart
> format?
>
> Or is it possible to get a stand alone chart editor for charts in the
> .chart format for eclipse?
>
> I have looked at this:
>
> http://www.birt-exchange.org/devshare/interactive-reporting/ 145-standalone-chart-engine-and-builder-examples/#descriptio n
>
>
> but it could be nice if charts could be edited using the BIRT plugin for
> eclipse (based on the .rptdesign format) instead of installing a new
> editor.
Re: .chart vs .rptdesign format difference? [message #523290 is a reply to message #523277] Thu, 25 March 2010 19:00 Go to previous messageGo to next message
bob is currently offline bobFriend
Messages: 60
Registered: July 2009
Member
Yes I am aware of that but then I have to include the whole BIRT runtime
with my application. I would like to include only the necessary lib files
which was why I tried this approach:

ChartWithAxes chart = ChartWithAxesImpl.create();
Serializer si = SerializerImpl.instance();
try {
si.write(chart, new FileOutputStream(new
File(c:\\myChart.rptdesign)));
} catch (Exception e) {
}

But when I render the chart using this code it does not compare to the chart
I get when I load it with:


ReportDesignHandle designHandle = null;
DesignConfig config = new DesignConfig( );
config.setBIRTHome("C:/birt/birt-runtime-2_5_1/birt-runtime-2_5_1/ReportEngine ");
IDesignEngine engine = null;
try{

Platform.startup( config );
IDesignEngineFactory factory = (IDesignEngineFactory) Platform
..createFactoryObject(
IDesignEngineFactory.EXTENSION_DESIGN_ENGINE_FACTORY );
engine = factory.createDesignEngine( config );

}catch( Exception ex){
ex.printStackTrace();
}

SessionHandle sessionHandle = engine.newSessionHandle( (ULocale) null );
try {
designHandle = sessionHandle.openDesign(
"c:\\myChart.rptdesign" );
} catch ( DesignFileException e ) {
e.printStackTrace( );
}


Is it only possible to load a chart specifying the path to the runtime?





"Jason Weathersby" <jasonweathersby@windstream.net> wrote in message
news:hog8ft$i2$1@build.eclipse.org...
> Bob,
>
> Using the RE API you can get the chart model from a report design like:
>
>
> import java.io.IOException;
>
> import org.eclipse.birt.chart.model.Chart;
> import org.eclipse.birt.chart.model.ChartWithAxes;
> import org.eclipse.birt.chart.model.attribute.DataType;
> import org.eclipse.birt.chart.model.attribute.SortOption;
> import org.eclipse.birt.chart.model.component.Axis;
> import org.eclipse.birt.chart.model.data.SeriesDefinition;
> import org.eclipse.birt.core.framework.Platform;
> import org.eclipse.birt.report.model.api.DesignConfig;
> import org.eclipse.birt.report.model.api.DesignEngine;
> import org.eclipse.birt.report.model.api.DesignFileException;
> import org.eclipse.birt.report.model.api.ExtendedItemHandle;
> import org.eclipse.birt.report.model.api.IDesignEngine;
> import org.eclipse.birt.report.model.api.IDesignEngineFactory;
> import org.eclipse.birt.report.model.api.ReportDesignHandle;
> import org.eclipse.birt.report.model.api.SessionHandle;
> import
> org.eclipse.birt.report.model.api.extension.ExtendedElementE xception;
>
> import com.ibm.icu.util.ULocale;
>
> /**
> * Presents a bar chart with grouping on X series, which could be acheived
> in
> * the report designer as follows: Chart Builder -> Data -> X Series ->
> Set Dat
> * Sorting / Tick Grouping Enabled
> */
> public class GroupOnXSeries
> {
>
> /**
> * execute application
> *
> * @param args
> */
> public static void main( String[] args )
> {
> new GroupOnXSeries( ).groupSeries( );
>
> }
>
> /**
> * Get the chart instance from the design file and group X series of the
> * chart.
> *
> * @return An instance of the simulated runtime chart model (containing
> * filled datasets)
> */
> void groupSeries( )
> {
>
>
> ReportDesignHandle designHandle = null;
> DesignConfig config = new DesignConfig( );
>
> config.setBIRTHome("C:/birt/birt-runtime-2_5_1/birt-runtime-2_5_1/ReportEngine ");
> IDesignEngine engine = null;
> try{
>
> Platform.startup( config );
> IDesignEngineFactory factory = (IDesignEngineFactory) Platform
> .createFactoryObject(
> IDesignEngineFactory.EXTENSION_DESIGN_ENGINE_FACTORY );
> engine = factory.createDesignEngine( config );
>
> }catch( Exception ex){
> ex.printStackTrace();
> }
> SessionHandle sessionHandle = engine.newSessionHandle( (ULocale) null );
>
>
> try
> {
> designHandle = sessionHandle.openDesign(
> "report/NonGroupOnXSeries.rptdesign" );//$NON-NLS-1$
> }
> catch ( DesignFileException e )
> {
> // TODO Auto-generated catch block
> e.printStackTrace( );
> }
>
> ExtendedItemHandle eih = (ExtendedItemHandle) designHandle.getBody( )
> .getContents( ).get( 0 );
>
> Chart cm = null;
> try
> {
> cm = (Chart) eih.getReportItem( ).getProperty( "chart.instance" );
> //$NON-NLS-1$
> }
> catch ( ExtendedElementException e )
> {
> // TODO Auto-generated catch block
> e.printStackTrace( );
> }
>
> cm.getTitle( ).getLabel( ).getCaption( ).setValue( "Group On X
> Series" );//$NON-NLS-1$
>
> cm.getTitle( ).getLabel( ).getCaption( ).getFont().setSize(12);
> cm.getTitle( ).getLabel( ).getCaption( ).getFont().setRotation(45);
>
> SeriesDefinition sdX = (SeriesDefinition) ( (Axis) ( (ChartWithAxes) cm )
> .getAxes( ).get( 0 ) ).getSeriesDefinitions( ).get( 0 );
>
> sdX.setSorting( SortOption.ASCENDING_LITERAL );
> sdX.getGrouping( ).setEnabled( true );
> sdX.getGrouping( ).setAggregateExpression( "Sum" );//$NON-NLS-1$
> sdX.getGrouping( ).setGroupType( DataType.NUMERIC_LITERAL );
> sdX.getGrouping( ).setGroupingInterval( 1 );
>
>
> try
> {
> designHandle.saveAs( "report/GroupOnXSeries.rptdesign" );//$NON-NLS-1$
> }
> catch ( IOException e )
> {
> e.printStackTrace( );
> }
> Platform.shutdown();
>
> }
>
> }
>
> Jason
>
> bob wrote:
>> I need to use the standalone Chart API in my application. This way I can
>> simply load the chart using:
>>
>> ChartWithAxes chart = ChartWithAxesImpl.create();
>> Serializer si = SerializerImpl.instance();
>> try {
>> si.write(chart, new FileOutputStream(new
>> File(c:\\myChart.rptdesign)));
>> } catch (Exception e) {
>> }
>>
>>
>> without having to specify the whole BIRT runtime dir.
>>
>> But I would like to setup the style and color before loading the chart.
>> Currently I do this by adding a chart to a blank .rptdesign file but I
>> cannot load a .rptdesign file using the above approach (to load a
>> .rptdesign file the whole BIRT runtime lib must be specified).
>>
>> Is it possible to extract a chart from a .rptdesign file to the .chart
>> format?
>>
>> Or is it possible to get a stand alone chart editor for charts in the
>> .chart format for eclipse?
>>
>> I have looked at this:
>>
>> http://www.birt-exchange.org/devshare/interactive-reporting/ 145-standalone-chart-engine-and-builder-examples/#descriptio n
>> but it could be nice if charts could be edited using the BIRT plugin for
>> eclipse (based on the .rptdesign format) instead of installing a new
>> editor.
Re: .chart vs .rptdesign format difference? [message #523410 is a reply to message #523290] Fri, 26 March 2010 06:14 Go to previous messageGo to next message
bob is currently offline bobFriend
Messages: 60
Registered: July 2009
Member
"bob" <bob@bobxxno.com> wrote in message
news:hogbse$dvu$1@build.eclipse.org...
> Yes I am aware of that but then I have to include the whole BIRT runtime
> with my application. I would like to include only the necessary lib files
> which was why I tried this approach:
>
> ChartWithAxes chart = ChartWithAxesImpl.create();
> Serializer si = SerializerImpl.instance();
> try {
> si.write(chart, new FileOutputStream(new
> File(c:\\myChart.rptdesign)));
> } catch (Exception e) {
> }



The above should of course be:

Chart chart = null;
Serializer si = SerializerImpl.instance();
try {
chart = serializer.read( new FileInputStream(
"c:\\myChart.rptdesign") );
}
catch ( Exception e )
{
WizardBase.displayException( e );
}
Re: .chart vs .rptdesign format difference? [message #523411 is a reply to message #523410] Fri, 26 March 2010 06:14 Go to previous messageGo to next message
bob is currently offline bobFriend
Messages: 60
Registered: July 2009
Member
Nevermind problem solved.



"bob" <bob@bobxxno.com> wrote in message
news:hoi2rd$bij$1@build.eclipse.org...
>
> "bob" <bob@bobxxno.com> wrote in message
> news:hogbse$dvu$1@build.eclipse.org...
>> Yes I am aware of that but then I have to include the whole BIRT runtime
>> with my application. I would like to include only the necessary lib files
>> which was why I tried this approach:
>>
>> ChartWithAxes chart = ChartWithAxesImpl.create();
>> Serializer si = SerializerImpl.instance();
>> try {
>> si.write(chart, new FileOutputStream(new
>> File(c:\\myChart.rptdesign)));
>> } catch (Exception e) {
>> }
>
>
>
> The above should of course be:
>
> Chart chart = null;
> Serializer si = SerializerImpl.instance();
> try {
> chart = serializer.read( new FileInputStream(
> "c:\\myChart.rptdesign") );
> }
> catch ( Exception e )
> {
> WizardBase.displayException( e );
> }
>
>
Re: .chart vs .rptdesign format difference? [message #523707 is a reply to message #523411] Sun, 28 March 2010 22:30 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason WeathersbyFriend
Messages: 9167
Registered: July 2009
Senior Member

Bob,

What did you end up going with?

Jason

bob wrote:
> Nevermind problem solved.
>
>
>
> "bob" <bob@bobxxno.com> wrote in message
> news:hoi2rd$bij$1@build.eclipse.org...
>>
>> "bob" <bob@bobxxno.com> wrote in message
>> news:hogbse$dvu$1@build.eclipse.org...
>>> Yes I am aware of that but then I have to include the whole BIRT
>>> runtime with my application. I would like to include only the
>>> necessary lib files which was why I tried this approach:
>>>
>>> ChartWithAxes chart = ChartWithAxesImpl.create();
>>> Serializer si = SerializerImpl.instance();
>>> try {
>>> si.write(chart, new FileOutputStream(new
>>> File(c:\\myChart.rptdesign)));
>>> } catch (Exception e) {
>>> }
>>
>>
>>
>> The above should of course be:
>>
>> Chart chart = null;
>> Serializer si = SerializerImpl.instance();
>> try {
>> chart = serializer.read( new FileInputStream(
>> "c:\\myChart.rptdesign") );
>> }
>> catch ( Exception e )
>> {
>> WizardBase.displayException( e );
>> }
>>
>>
>
Re: .chart vs .rptdesign format difference? [message #523740 is a reply to message #523707] Mon, 29 March 2010 06:40 Go to previous message
bob is currently offline bobFriend
Messages: 60
Registered: July 2009
Member
I just extract the

<model:ChartWithAxes ....>

......

</model:ChartWithAxes>

part of the .rptdesign file and store it in a .chart file. Then I can load
it correctly with the Serializer approach without having to specify the
runtime directory. It should be pretty easy to use eg. xstream for doing
this automatically.






"Jason Weathersby" <jasonweathersby@windstream.net> wrote in message
news:hool42$rtu$1@build.eclipse.org...
> Bob,
>
> What did you end up going with?
>
> Jason
>
> bob wrote:
>> Nevermind problem solved.
>>
>>
>>
>> "bob" <bob@bobxxno.com> wrote in message
>> news:hoi2rd$bij$1@build.eclipse.org...
>>>
>>> "bob" <bob@bobxxno.com> wrote in message
>>> news:hogbse$dvu$1@build.eclipse.org...
>>>> Yes I am aware of that but then I have to include the whole BIRT
>>>> runtime with my application. I would like to include only the necessary
>>>> lib files which was why I tried this approach:
>>>>
>>>> ChartWithAxes chart = ChartWithAxesImpl.create();
>>>> Serializer si = SerializerImpl.instance();
>>>> try {
>>>> si.write(chart, new FileOutputStream(new
>>>> File(c:\\myChart.rptdesign)));
>>>> } catch (Exception e) {
>>>> }
>>>
>>>
>>>
>>> The above should of course be:
>>>
>>> Chart chart = null;
>>> Serializer si = SerializerImpl.instance();
>>> try {
>>> chart = serializer.read( new FileInputStream(
>>> "c:\\myChart.rptdesign") );
>>> }
>>> catch ( Exception e )
>>> {
>>> WizardBase.displayException( e );
>>> }
>>>
>>>
>>
Previous Topic:Cannot find Chart class
Next Topic:Two tables: first on even page, second on odd page ?
Goto Forum:
  


Current Time: Thu Apr 25 11:32:52 GMT 2024

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

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

Back to the top