|
Re: .chart vs .rptdesign format difference? [message #523277 is a reply to message #522972] |
Thu, 25 March 2010 18:06 |
|
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 #523707 is a reply to message #523411] |
Sun, 28 March 2010 22:30 |
|
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 );
>> }
>>
>>
>
|
|
|
|
Powered by
FUDForum. Page generated in 0.03332 seconds