Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » BIRT » Open a .chart file in the eclipse reporting platform?
Open a .chart file in the eclipse reporting platform? [message #757160] Wed, 16 November 2011 15:35 Go to next message
js Missing name is currently offline js Missing name
Messages: 73
Registered: July 2009
Member
I have downloaded the birt reporting eclipse platform (not the standalone chart editor). I have the created a simple chart that I write to disk:

    Chart myChart = ChartWithAxesImpl.create();
    Serializer si = SerializerImpl.instance();
    try {
      si.write(myChart, new FileOutputStream(new File(CHART_FILE)));
    } catch (IOException e) {
      e.printStackTrace();
    }


When I open the .chart file in eclipse (I have switched to the reporting perspective) I just get an xml file. Is it possible to import a .chart file as chart object somehow?
Re: Open a .chart file in the eclipse reporting platform? [message #757829 is a reply to message #757160] Wed, 16 November 2011 17:08 Go to previous message
Jason Weathersby is currently offline Jason Weathersby
Messages: 9167
Registered: July 2009
Senior Member

You can read it into a chart model like:
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
IGenerator 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( );

//Example of writting the xml file
//ce.getSerializer().write(cmf, new FileOutputStream(
"chartmodels/mycolorchart.chart" ));


Chart cmf = ce.getSerializer().read(new FileInputStream(
"chartmodels/testpie.chart" ));
Chart cm = (Chart) EcoreUtil.copy( (Chart) cmf );

Remember data is not stored in the .chart file so you will have to bind
it to data
//SerializerExample.bindChart((ChartWithAxes)cm);

Something like:
public static void bindChart(ChartWithAxes cmb){

// Data Set
TextDataSet categoryValues = TextDataSetImpl.create( new String[]{
"Item 1", "Item 2", "Item 3", "Item 4", "Item 5"} ); //$NON-NLS-1$
//$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
NumberDataSet orthoValues1 = NumberDataSetImpl.create( new double[]{
25, 35, 15, 5, 20
} );
NumberDataSet orthoValues2 = NumberDataSetImpl.create( new double[]{
5, 10, 25, 10, 5
} );


Axis xaxis = cmb.getPrimaryBaseAxes()[0];
Axis yaxis = cmb.getPrimaryOrthogonalAxis(xaxis);

SeriesDefinition sdx =
(SeriesDefinition)xaxis.getSeriesDefinitions().get(0);
SeriesDefinition sdy =
(SeriesDefinition)yaxis.getSeriesDefinitions().get(0);

((Series)sdx.getSeries().get(0)).setDataSet(categoryValues);
((Series)sdy.getSeries().get(0)).setDataSet(orthoValues1);
((Series)sdy.getSeries().get(1)).setDataSet(orthoValues2);

}

Jason

On 11/16/2011 3:35 PM, js wrote:
> I have downloaded the birt reporting eclipse platform (not the
> standalone chart editor). I have the created a simple chart that I write
> to disk:
>
>
> Chart myChart = ChartWithAxesImpl.create();
> Serializer si = SerializerImpl.instance();
> try {
> si.write(myChart, new FileOutputStream(new File(CHART_FILE)));
> } catch (IOException e) {
> e.printStackTrace();
> }
>
>
> When I open the .chart file in eclipse (I have switched to the reporting
> perspective) I just get an xml file. Is it possible to import a .chart
> file as chart object somehow?


Jason Weathersby

BIRT Exchange
Previous Topic:Generating a chart image from an rptdesign file
Next Topic:Locating BIRT 3.7.1 Source Code
Goto Forum:
  


Current Time: Fri Apr 18 17:00:52 EDT 2014

Powered by FUDForum. Page generated in 0.10756 seconds