Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
RE: [birt-charting-dev] Pie Chart Autobinding

Thanks a lot. Saved my Easter holidays J



Jason Weathersby wrote:

Here is an example of a pie chart that uses a datarowexpressionevaluator.


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.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.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.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 = createPie( );
       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;

   }
   private static Chart createPie( )
   {
       ChartWithoutAxes cwoaPie = ChartWithoutAxesImpl.create( );
       cwoaPie.setDimension( ChartDimension.TWO_DIMENSIONAL_WITH_DEPTH_LITERAL );
       cwoaPie.setType( "Pie Chart" ); //$NON-NLS-1$          cwoaPie.setSubType( "Standard Pie Chart" ); //$NON-NLS-1$
             // Plot
       cwoaPie.setSeriesThickness( 10 );

       // Legend
       Legend lg = cwoaPie.getLegend( );
       lg.getOutline( ).setVisible( true );

       // Title
       cwoaPie.getTitle( ).getLabel( ).getCaption( ).setValue( "Pie Chart" );//$NON-NLS-1$
             SampleData sdata = DataFactory.eINSTANCE.createSampleData( );
       BaseSampleData sdBase = DataFactory.eINSTANCE.createBaseSampleData( );
       sdBase.setDataSetRepresentation( "" );//$NON-NLS-1$
       sdata.getBaseSampleData( ).add( sdBase );

       OrthogonalSampleData sdOrthogonal = DataFactory.eINSTANCE.createOrthogonalSampleData( );
       sdOrthogonal.setDataSetRepresentation( "" );//$NON-NLS-1$
       sdOrthogonal.setSeriesDefinitionIndex( 0 );
       sdata.getOrthogonalSampleData( ).add( sdOrthogonal );

       cwoaPie.setSampleData( sdata );

       // Base Series
       Query xQ = QueryImpl.create( "X" );

       Series seCategory = SeriesImpl.create( );
       seCategory.getDataDefinition().add(xQ);
             //seCategory.setDataSet( categoryValues );

       SeriesDefinition sd = SeriesDefinitionImpl.create( );
       cwoaPie.getSeriesDefinitions( ).add( sd );
       sd.getSeriesPalette( ).shift( 0 );
       sd.getSeries( ).add( seCategory );

       // Orthogonal Series
       Query yQ = QueryImpl.create( "Y" );
       PieSeries sePie = (PieSeries) PieSeriesImpl.create( );
       //sePie.setDataSet( seriesOneValues );
       sePie.getDataDefinition().add(yQ);
       sePie.setSeriesIdentifier( "myser" );//$NON-NLS-1$
       sePie.setExplosion( 5 );
             SeriesDefinition sdCity = SeriesDefinitionImpl.create( );
       sd.getSeriesDefinitions( ).add( sdCity );
       sdCity.getSeries( ).add( sePie );

       return cwoaPie;
   }   }

Jason



birt-charting-dev-request@xxxxxxxxxxx wrote:

Send birt-charting-dev mailing list submissions to
    
birt-charting-dev@xxxxxxxxxxx

To subscribe or unsubscribe via the World Wide Web, visit
    
https://dev.eclipse.org/mailman/listinfo/birt-charting-dev
or, via email, send a message with subject or body 'help' to
    
birt-charting-dev-request@xxxxxxxxxxx

You can reach the person managing the list at
    
birt-charting-dev-owner@xxxxxxxxxxx

When replying, please edit your Subject line so it is more specific
than "Re: Contents of birt-charting-dev digest..."


Today's Topics:

   1. data autobinding & piechart rendering (H C)


----------------------------------------------------------------------

Message: 1
Date: Thu, 9 Apr 2009 17:52:10 +0100
From: H C
<d24334344@xxxxxxxxx>
Subject: [birt-charting-dev] data autobinding & piechart rendering
To:
birt-charting-dev@xxxxxxxxxxx
Message-ID:
    
<e13aa4760904090952h56e42138y74549ceef3b60033@xxxxxxxxxxxxxx>
Content-Type: text/plain; charset="iso-8859-1"

Hi,

I am looking into using the birt charting API to render an image from the
chart. In the example below I try to create a PIE chart with autobinding to
feed my data into the chart model dynamically and render it.

 I have just started looking at the birt framework. I got the png image
rendering working for other examples but not for the pie chart. Is there any
working example for autobinding and piecharts? Also any good tutorials on
the chart api and its series, datadefinitions, autobinding etc? I'd like to
keep my code flexible and would like to dynamically bind data for PIE
charts.

Any help is appreciated.

Thanks!




When running the (modified) example below I see a

Exception in thread "main" *java.lang.NullPointerException
*

at
org.eclipse.birt.chart.internal.datafeed.GroupingLookupHelper.addLookupForBaseSeries(
*GroupingLookupHelper.java:262*)

at
org.eclipse.birt.chart.internal.datafeed.GroupingLookupHelper.initRowExpressions(
*GroupingLookupHelper.java:419*)

at org.eclipse.birt.chart.internal.datafeed.GroupingLookupHelper.<init>(*
GroupingLookupHelper.java:95*)

at
org.eclipse.birt.chart.internal.datafeed.DataProcessor.mapToChartResultSet(*
DataProcessor.java:318*)

at
org.eclipse.birt.chart.internal.datafeed.DataProcessor.generateRuntimeSeries(
*DataProcessor.java:496*)

at org.eclipse.birt.chart.factory.Generator.bindData(*Generator.java:642*)

at org.eclipse.birt.chart.factory.Generator.bindData(*Generator.java:594*)

at PieChartBuilder.createImg(*PieChartBuilder.java:128*)

at PieChartBuilder.build(*PieChartBuilder.java:78*)

at PieChartBuilder.main(*PieChartBuilder.java:63*)



The snippet below is the actual code that binds the data to the chart model

String[] set = { "Items" };

Object[][] data = { { *new* Integer(7), *new* Integer(2), *new* Integer(5) }
};

 IDataRowExpressionEvaluator dree = *new*DataRowExpressionEvaluator(set,data);

*try* {

gr.bindData(dree, chart, *new* RunTimeContext());  // protected IGenerator
gr = null;

...





*

import* java.awt.Graphics;
*

import* java.awt.Graphics2D;
*

import* java.awt.image.BufferedImage;
*

import* java.io.File;
*

import* java.io.IOException;

*

import* javax.imageio.ImageIO;

*

import* org.eclipse.birt.chart.api.ChartEngine;
*

import* org.eclipse.birt.chart.device.IDeviceRenderer;
*

import* org.eclipse.birt.chart.exception.ChartException;
*

import* *org.eclipse.birt.chart.factory.Generator*;
*

import* org.eclipse.birt.chart.factory.IDataRowExpressionEvaluator;
*

import* org.eclipse.birt.chart.factory.RunTimeContext;
*

import* *org.eclipse.birt.chart.model.ChartWithoutAxes*;
*

import* org.eclipse.birt.chart.model.attribute.Bounds;
*

import* org.eclipse.birt.chart.model.attribute.ChartDimension;
*

import* org.eclipse.birt.chart.model.attribute.impl.BoundsImpl;
*

import* org.eclipse.birt.chart.model.attribute.impl.ColorDefinitionImpl;
*

import* org.eclipse.birt.chart.model.component.Series;
*

import* org.eclipse.birt.chart.model.component.impl.SeriesImpl;
*

import* *org.eclipse.birt.chart.model.data.NumberDataSet*;
*

import* org.eclipse.birt.chart.model.data.Query;
*

import* org.eclipse.birt.chart.model.data.SeriesDefinition;
*

import* org.eclipse.birt.chart.model.data.TextDataSet;
*

import* *org.eclipse.birt.chart.model.data.impl.NumberDataSetImpl*;
*

import* org.eclipse.birt.chart.model.data.impl.QueryImpl;
*

import* org.eclipse.birt.chart.model.data.impl.SeriesDefinitionImpl;
*

import* org.eclipse.birt.chart.model.data.impl.TextDataSetImpl;
*

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.PieSeries;
*

import* org.eclipse.birt.chart.model.type.impl.PieSeriesImpl;
*

import* org.eclipse.birt.core.framework.PlatformConfig;

*

import* *com.ibm.icu.util.ULocale*;

/**

* Builds pie chart.

*

* *@author* *Qi* *Liang
*

*/
*

public* *class* PieChartBuilder *extends* AbstractChartBuilder {

SeriesDefinition sdX = *null*;

/**

* Constructor.

*

* *@param* dataSet

* data for chart

*/

*public* PieChartBuilder(DataSet dataSet) {

*super*(dataSet);

title = "Pie Chart";

}

*public* *static* *void* main(String[] args) {

PieChartBuilder p = *new* PieChartBuilder(DataSet.*getInstance*());

p.build();

}

/**

* Builds one chart.

*/

*public* *void* build() {

createChart();

buildPlot();

buildLegend();

buildTitle();

buildXAxis();

// buildYAxis();

buildXSeries();

// buildYSeries();

createImg();

}

*public* *void* createImg() {

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();

}

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/DataRowEvaluator.png"); //$NON-NLS-1$

// dRenderer.setProperty(IDeviceRenderer.CACHED_IMAGE, *img*); //$NON-NLS-1$

Bounds bo = BoundsImpl.*create*(0, 0, 600, 600);

bo.scale(72d / dRenderer.getDisplayServer().getDpiResolution());

// String[] set = { "Items", "Amounts" };//$NON-NLS-1$ //$NON-NLS-2$

String[] set = { "Items" };//$NON-NLS-1$ //$NON-NLS-2$

// Object[][] data = { { "A", "B", "C" },

// { new Integer(7), new Integer(2), new Integer(5) } };

 Object[][] data = { { *new* Integer(7), *new* Integer(2), *new* Integer(5)
} };

 // Binds data to chart model

IDataRowExpressionEvaluator dree = *new* DataRowExpressionEvaluator(set,

data);

*try* {

gr.bindData(dree, chart, *new* RunTimeContext());

gcs = gr.build(dServer, chart, bo, *null*, *null*, *null*);

gr.render(dRenderer, gcs);

ImageIO.*write*(img, "png", *new* File("output/DataRowEvaluator.png"));

// System.out.*println*(*img*.getGraphics().toString());

// // O P E N

// ByteArrayOutputStream *baos* = new ByteArrayOutputStream( 1000 );

//

// try {

// // W R I T E

// ImageIO.write(*img*, "*png*", *baos*);

//

// // C L O S E

// *baos*.flush();

// this.iceImage = *baos*.toByteArray();

//

// *baos*.close();

//

// // System.out.*println*(getIceImage());

//

// } catch (IOException e) {

// e.printStackTrace();

// }

} *catch* (ChartException e) {

e.printStackTrace();

} *catch* (IOException e) {

e.printStackTrace();

}

}

/*

* (non-*Javadoc*)

*

* @see

* com.ibm.examples.chart.widget.chart.AbstractChartBuilder#createChart()

*/

*protected* *void* createChart() {

chart = ChartWithoutAxesImpl.*create*();

chart.setDimension( ChartDimension.*TWO_DIMENSIONAL_WITH_DEPTH_LITERAL* );

chart.setType("Pie Chart");

chart.setSubType("Standard Pie Chart");

}

/*

* (non-*Javadoc*)

*

* @see com.ibm.examples.chart.widget.AbstractChartBuilder#buildPlot()

*/

*protected* *void* buildPlot() {

chart.setSeriesThickness(25);

chart.getBlock().setBackground(ColorDefinitionImpl.*WHITE*());

Plot p = chart.getPlot();

p.getClientArea().setBackground(*null*);

p.getClientArea().getOutline().setVisible(*true*);

p.getOutline().setVisible(*true*);

}

/*

* (non-*Javadoc*)

*

* @see com.ibm.examples.chart.widget.AbstractChartBuilder#buildLegend()

*/

*protected* *void* buildLegend() {

Legend lg = chart.getLegend();

lg.getText().getFont().setSize(16);

lg.getOutline().setVisible(*true*);

}

/*

* (non-*Javadoc*)

*

* @see com.ibm.examples.chart.widget.AbstractChartBuilder#buildXSeries()

*/

*protected* *void* buildXSeries() {

 // CREATE THE CATEGORY SERIES

Series seCategory = SeriesImpl.*create*();

TextDataSet categoryValues = TextDataSetImpl

.*create*(*new* String[]{"A","B","C"});

seCategory.setDataSet(categoryValues);

// CREATE THE PRIMARY DATASET

PieSeries ls = (PieSeries) PieSeriesImpl.*create*();

ls.setSeriesIdentifier("My Pie Series");

ls.setSliceOutline(ColorDefinitionImpl.*CREAM*());

ls.getLabel().setVisible(*true*);

*seCategory.getDataDefinition().add(QueryImpl.create("G"))*;

SeriesDefinition sdX = SeriesDefinitionImpl.*create*();

*sdX.getSeriesPalette().update(0)*; // SET THE COLORS IN THE PALETTE



SeriesDefinition sdY = SeriesDefinitionImpl.*create*();

*sdY.getSeriesPalette().update(1)*; // SET THE COLORS IN THE PALETTE

sdY.setQuery(QueryImpl.*create*("Items"));

*sdX.getSeriesDefinitions().add(sdY)*;

*sdX.getSeries().add(seCategory)*;

*sdY.getSeries().add(ls)*;



*((ChartWithoutAxesImpl)chart).getSeriesDefinitions().add(sdX)*;

 // addSampleData(cwoaPie);



  //

//

//

//

//

//

//// TextDataSet categoryValues = TextDataSetImpl

//// .create(new String[]{"A","B","C"});

//

// Series seCategory = SeriesImpl.create();

// // Base Series

//// Query xQ = QueryImpl.create( "Items" );//$NON-NLS-1$

//

//

//

//

// // Apply the *color* *palette
*

// sdX = SeriesDefinitionImpl.create();

// ((ChartWithoutAxes)chart).getSeriesDefinitions().add(sdX);

//

// seCategory.getDataDefinition( ).add( xQ );

//

//// seCategory.setDataSet(categoryValues);

// seCategory.setSeriesIdentifier("Cities");

//

//

//// sdX.getSeriesPalette( ).shift( 0 );

// sdX.getSeries( ).add( seCategory );

//

//

//// sdX.getSeriesPalette().update(1);



 }

/*

* (non-*Javadoc*)

*

* @see

* com.ibm.examples.chart.widget.chart.AbstractChartBuilder#buildYSeries()

*/

*protected* *void* buildYSeries() {

// NumberDataSet orthoValuesDataSet = NumberDataSetImpl.create(dataSet

// .getTechnitians());

// Orthogonal Series

Query qY = QueryImpl.*create*( "Y" );//$NON-NLS-1$

PieSeries sePie = (PieSeries) PieSeriesImpl.*create*();

*sePie.getDataDefinition( ).add( qY )*;

// sePie.setDataSet(orthoValuesDataSet);

// sePie.setSeriesIdentifier("Amounts");

SeriesDefinition sdY = SeriesDefinitionImpl.*create*();

*sdX.getSeriesDefinitions().add(sdY)*;

*sdY.getSeries().add(sePie)*;

}

}



****




import java.util.HashMap;
import java.util.Map;

import org.eclipse.birt.chart.factory.DataRowExpressionEvaluatorAdapter;

public class DataRowExpressionEvaluator extends
  DataRowExpressionEvaluatorAdapter {

 private int k = 0;
 private Object[] column;
 private Map map;

 public DataRowExpressionEvaluator(String[] set, Object[][] data) {
  if (set == null) {
   throw new IllegalArgumentException();
  }

  map = new HashMap();
  for (int i = 0; i < set.length; i++) {
   map.put(set[i], data[i]);
  }
 }

 /*
  * (non-Javadoc)
  *
  * @see
  * org.eclipse.birt.chart.factory.IDataRowExpressionEvaluator#evaluate(java
  * .lang.String)
  */
 public Object evaluate(String _expression_) {
  column = (Object[]) map.get(_expression_);
  return column[k];
 }

 /*
  * (non-Javadoc)
  *
  * @see org.eclipse.birt.chart.factory.IDataRowExpressionEvaluator#first()
  */
 public boolean first() {
  k = 0;

  if (map.size() > 0) {
   column = (Object[]) map.values().iterator().next();

   if (column != null && k < column.length) {
    return true;
   }
  }

  return false;
 }

 /*
  * (non-Javadoc)
  *
  * @see org.eclipse.birt.chart.factory.IDataRowExpressionEvaluator#next()
  */
 public boolean next() {
  if (column != null && k < (column.length - 1)) {
   k++;
   return true;
  }
  return false;
 }

 /*
  * (non-Javadoc)
  *
  * @see org.eclipse.birt.chart.factory.IDataRowExpressionEvaluator#close()
  */
 public void close() {
  // Doing nothing.
 }

}

*****
*

import* *java.awt.Graphics*;
*

import* *java.awt.Graphics2D*;
*

import* *java.awt.image.BufferedImage*;
*

import* *java.io.ByteArrayOutputStream*;
*

import* *java.io.File*;
*

import* *java.io.IOException*;

*

import* *javax.imageio.ImageIO*;

*

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.attribute.Bounds*;
*

import* *org.eclipse.birt.chart.model.attribute.impl.BoundsImpl*;
*

import* *org.eclipse.birt.core.framework.PlatformConfig*;

*

import* *com.ibm.icu.util.ULocale*;



/**

* Provides the common members and the framework to build one chart.

*

* *@author* *Qi* *Liang
*

*/
*

public* *abstract* *class* AbstractChartBuilder {

*protected* *byte*[] iceImage;

/**

* The swing rendering device

*/

*protected* IDeviceRenderer dRenderer = *null*;

*protected* IDisplayServer dServer = *null*;

*protected* GeneratedChartState gcs = *null*;

*protected* IGenerator gr = *null*;

 /**

* Font name for all titles, labels, and values.

*/

*protected* *final* *static* String *FONT_NAME* = "MS Sans Serif";

/**

* Provides data for chart.

*/

*protected* DataSet dataSet = *null*;

/**

* Chart instance.

*/

*protected* Chart chart = *null*;

/**

* Chart title.

*/

*protected* String title = *null*;

/**

* Constructs one chart builder and associate it to one data set.

*

* *@param* dataSet

* data set

*/

*public* AbstractChartBuilder(DataSet dataSet) {

*this*.dataSet = dataSet;

}

/**

* Builds one chart.

*/

*public* *void* build() {

createChart();

buildPlot();

buildLegend();

buildTitle();

buildXAxis();

buildYAxis();

buildXSeries();

buildYSeries();

}



*public* *byte*[] getIceImage() {

*return* iceImage;

}

 /**

* Creates chart instance.

*/

*protected* *abstract* *void* createChart();

/**

* Builds plot.

*/

*protected* *void* buildPlot() {

}

/**

* Builds X axis.

*/

*protected* *void* buildXAxis() {

}

/**

* Builds Y axis.

*/

*protected* *void* buildYAxis() {

}

/**

* Builds X series.

*/

*protected* *void* buildXSeries() {

}

/**

* Builds Y series.

*/

*protected* *void* buildYSeries() {

}

/**

* Builds legend.

*

*/

*protected* *void* buildLegend() {

}

/**

* Builds the chart title.

*/

*protected* *void* buildTitle() {

chart.getTitle().getLabel().getCaption().setValue(title);

chart.getTitle().getLabel().getCaption().getFont().setSize(14);

chart.getTitle().getLabel().getCaption().getFont().setName(*FONT_NAME*);

}

/**

* Returns the chart instance.

*

* *@return* the chart instance

*/

*public* Chart getChart() {

*return* chart;

}

}
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
https://dev.eclipse.org/mailman/private/birt-charting-dev/attachments/20090409/f89bfa6b/attachment.html

------------------------------

_______________________________________________
birt-charting-dev mailing list
birt-charting-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/birt-charting-dev


End of birt-charting-dev Digest, Vol 32, Issue 1
************************************************

 


_______________________________________________
birt-charting-dev mailing list
birt-charting-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/birt-charting-dev


Back to the top