Skip to main content



      Home
Home » Archived » BIRT » Stacked bar chart
Stacked bar chart [message #259715] Mon, 29 October 2007 02:22 Go to next message
Eclipse UserFriend
I've extended the birt.chart.examples.api.data.autobinding example to
include several more rows of data and create a stacked bar chart. The
chart only uses the first two rows of data even though I have checked the
other rows being created. Has anyone used the data row expression
evaluator adapter?
Re: Stacked bar chart [message #259720 is a reply to message #259715] Mon, 29 October 2007 09:37 Go to previous messageGo to next message
Eclipse UserFriend
I believe the adapter works fine, can you post your code?

Thanks,

David

"Chery McNamara" <cheryl.mcnamara@csiro.au> wrote in message
news:1bfe0022f97493c080d1828ecdffd89f$1@www.eclipse.org...
> I've extended the birt.chart.examples.api.data.autobinding example to
> include several more rows of data and create a stacked bar chart. The
> chart only uses the first two rows of data even though I have checked the
> other rows being created. Has anyone used the data row expression
> evaluator adapter?
>
Re: Stacked bar chart [message #259871 is a reply to message #259720] Mon, 29 October 2007 23:27 Go to previous messageGo to next message
Eclipse UserFriend
This is the extended code. Thanks for any suggestions.

private static final Chart createSimpleChart() {
ChartWithAxes cwaBar = ChartWithAxesImpl.create();
cwaBar.setType("Bar Chart"); //$NON-NLS-1$
cwaBar.setSubType("Stacked"); //$NON-NLS-1$

// X-Axis
Axis xAxisPrimary = cwaBar.getPrimaryBaseAxes()[0];
xAxisPrimary.setType(AxisType.TEXT_LITERAL);
xAxisPrimary.getOrigin().setType(IntersectionType.VALUE_LITE RAL);
xAxisPrimary.getTitle().setVisible(true);

// Y-Axis
Axis yAxisPrimary = cwaBar.getPrimaryOrthogonalAxis(xAxisPrimary);
yAxisPrimary.getMajorGrid().setTickStyle(TickStyle.LEFT_LITE RAL);
yAxisPrimary.setType(AxisType.LINEAR_LITERAL);
yAxisPrimary.getTitle().setVisible(true);

// X-Series
Series seCategory = SeriesImpl.create();
Query query = QueryImpl.create("Items");//$NON-NLS-1$
seCategory.getDataDefinition().add(query);

SeriesDefinition sdX = SeriesDefinitionImpl.create();
xAxisPrimary.getSeriesDefinitions().add(sdX);
sdX.getSeries().add(seCategory);

// Y-Series
BarSeries bs1 = (BarSeries) BarSeriesImpl.create();
Query query1 = QueryImpl.create("Amounts1");//$NON-NLS-1$
bs1.getDataDefinition().add(query1);
bs1.getLabel().setVisible(true);
bs1.setVisible(true);

// Y-Series
BarSeries bs2 = (BarSeries) BarSeriesImpl.create();
Query query2 = QueryImpl.create("Amounts2");//$NON-NLS-1$
bs2.getDataDefinition().add(query2);
bs2.getLabel().setVisible(true);
bs2.setStacked(true);

// Y-Series
BarSeries bs3 = (BarSeries) BarSeriesImpl.create();
Query query3 = QueryImpl.create("Amounts3");//$NON-NLS-1$
bs3.getDataDefinition().add(query3);
bs3.getLabel().setVisible(true);
bs3.setStacked(true);

SeriesDefinition sdY = SeriesDefinitionImpl.create();
yAxisPrimary.getSeriesDefinitions().add(sdY);
sdY.getSeries().add(bs1);
sdY.getSeries().add(bs2);
sdY.getSeries().add(bs3);

return cwaBar;
}

public void paintControl(PaintEvent e) {
this.idr.setProperty(IDeviceRenderer.GRAPHICS_CONTEXT, e.gc);
Composite co = (Composite) e.getSource();
Rectangle re = co.getClientArea();
Bounds bo = BoundsImpl.create(0, 0, re.width, re.height);
bo.scale(72d / this.idr.getDisplayServer().getDpiResolution());

RunTimeContext context = new RunTimeContext();
context.setULocale(ULocale.getDefault());

String[] set = { "Items", "Amounts1", "Amounts2", "Amounts3" };
Object[][] data = { { "A", "B", "C" },
{ new Integer(5), new Integer(7), new Integer(3) },
{ new Integer(7), new Integer(2), new Integer(5) },
{ new Integer(3), new Integer(4), new Integer(1) } };

this.dree = new DataRowExpressionEvaluator(set, data);
Generator gr = Generator.instance();
try {
gr.bindData(this.dree, this.cm, context);
gr.render(this.idr, gr.build(this.idr.getDisplayServer(), this.cm,
bo, null, context, null));
} catch (ChartException ce) {
ce.printStackTrace();
}
}
Re: Stacked bar chart [message #259924 is a reply to message #259871] Tue, 30 October 2007 06:01 Go to previous messageGo to next message
Eclipse UserFriend
This looks fine, can you also post the DataRowExpressionEvaluator code?

Thanks,

David

"Chery McNamara" <cheryl.mcnamara@csiro.au> wrote in message
news:f92dd632523c6b4b650c0f79a1276cd6$1@www.eclipse.org...
> This is the extended code. Thanks for any suggestions.
>
> private static final Chart createSimpleChart() {
> ChartWithAxes cwaBar = ChartWithAxesImpl.create();
> cwaBar.setType("Bar Chart"); //$NON-NLS-1$
> cwaBar.setSubType("Stacked"); //$NON-NLS-1$
>
> // X-Axis
> Axis xAxisPrimary = cwaBar.getPrimaryBaseAxes()[0];
> xAxisPrimary.setType(AxisType.TEXT_LITERAL);
> xAxisPrimary.getOrigin().setType(IntersectionType.VALUE_LITE RAL);
> xAxisPrimary.getTitle().setVisible(true);
>
> // Y-Axis
> Axis yAxisPrimary = cwaBar.getPrimaryOrthogonalAxis(xAxisPrimary);
> yAxisPrimary.getMajorGrid().setTickStyle(TickStyle.LEFT_LITE RAL);
> yAxisPrimary.setType(AxisType.LINEAR_LITERAL);
> yAxisPrimary.getTitle().setVisible(true);
>
> // X-Series
> Series seCategory = SeriesImpl.create();
> Query query = QueryImpl.create("Items");//$NON-NLS-1$
> seCategory.getDataDefinition().add(query);
>
> SeriesDefinition sdX = SeriesDefinitionImpl.create();
> xAxisPrimary.getSeriesDefinitions().add(sdX);
> sdX.getSeries().add(seCategory);
>
> // Y-Series
> BarSeries bs1 = (BarSeries) BarSeriesImpl.create();
> Query query1 = QueryImpl.create("Amounts1");//$NON-NLS-1$
> bs1.getDataDefinition().add(query1);
> bs1.getLabel().setVisible(true);
> bs1.setVisible(true);
>
> // Y-Series
> BarSeries bs2 = (BarSeries) BarSeriesImpl.create();
> Query query2 = QueryImpl.create("Amounts2");//$NON-NLS-1$
> bs2.getDataDefinition().add(query2);
> bs2.getLabel().setVisible(true);
> bs2.setStacked(true);
>
> // Y-Series
> BarSeries bs3 = (BarSeries) BarSeriesImpl.create();
> Query query3 = QueryImpl.create("Amounts3");//$NON-NLS-1$
> bs3.getDataDefinition().add(query3);
> bs3.getLabel().setVisible(true);
> bs3.setStacked(true);
>
> SeriesDefinition sdY = SeriesDefinitionImpl.create();
> yAxisPrimary.getSeriesDefinitions().add(sdY);
> sdY.getSeries().add(bs1);
> sdY.getSeries().add(bs2);
> sdY.getSeries().add(bs3);
>
> return cwaBar;
> }
>
> public void paintControl(PaintEvent e) {
> this.idr.setProperty(IDeviceRenderer.GRAPHICS_CONTEXT, e.gc);
> Composite co = (Composite) e.getSource();
> Rectangle re = co.getClientArea();
> Bounds bo = BoundsImpl.create(0, 0, re.width, re.height);
> bo.scale(72d / this.idr.getDisplayServer().getDpiResolution());
>
> RunTimeContext context = new RunTimeContext();
> context.setULocale(ULocale.getDefault());
>
> String[] set = { "Items", "Amounts1", "Amounts2", "Amounts3" };
> Object[][] data = { { "A", "B", "C" },
> { new Integer(5), new Integer(7), new Integer(3) },
> { new Integer(7), new Integer(2), new Integer(5) },
> { new Integer(3), new Integer(4), new Integer(1) } };
>
> this.dree = new DataRowExpressionEvaluator(set, data);
> Generator gr = Generator.instance();
> try {
> gr.bindData(this.dree, this.cm, context);
> gr.render(this.idr, gr.build(this.idr.getDisplayServer(), this.cm,
> bo, null, context, null));
> } catch (ChartException ce) {
> ce.printStackTrace();
> }
> }
>
>
>
Re: Stacked bar chart [message #260001 is a reply to message #259924] Tue, 30 October 2007 18:58 Go to previous messageGo to next message
Eclipse UserFriend
Thanks David. Haven't changed the code from example. Have an idea this is
where my problem is and tried lots but with no success.


/*********************************************************** ********************
* Copyright (c) 2004 Actuate Corporation.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Actuate Corporation - initial API and implementation
************************************************************ *******************/

package org.eclipse.birt.chart.examples.api.data.autobinding;

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

import org.eclipse.birt.chart.factory.DataRowExpressionEvaluatorAda pter;

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#e valuate(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#f irst()
*/
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#n ext()
*/
public boolean next( )
{
if ( column != null && k < ( column.length - 1 ) )
{
k++;
return true;
}
return false;
}

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

}
Re: Stacked bar chart [message #260074 is a reply to message #260001] Wed, 31 October 2007 10:00 Go to previous messageGo to next message
Eclipse UserFriend
Chery,

I need to debug that code to find out the problem, which I will do when I
get the time. But before I do that, did you try debugging it on your side?
See if it iterates through the data in the evaluator?

Thanks,

David

"Chery McNamara" <cheryl.mcnamara@csiro.au> wrote in message
news:6a861d4291891acb468353b34d20ab28$1@www.eclipse.org...
> Thanks David. Haven't changed the code from example. Have an idea this is
> where my problem is and tried lots but with no success.
>
>
> /*********************************************************** ********************
> * Copyright (c) 2004 Actuate Corporation.
> * All rights reserved. This program and the accompanying materials
> * are made available under the terms of the Eclipse Public License v1.0
> * which accompanies this distribution, and is available at
> * http://www.eclipse.org/legal/epl-v10.html
> *
> * Contributors:
> * Actuate Corporation - initial API and implementation
> ************************************************************ *******************/
>
> package org.eclipse.birt.chart.examples.api.data.autobinding;
>
> import java.util.HashMap;
> import java.util.Map;
>
> import org.eclipse.birt.chart.factory.DataRowExpressionEvaluatorAda pter;
>
> 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#e valuate(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#f irst()
> */
> 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#n ext()
> */
> public boolean next( )
> {
> if ( column != null && k < ( column.length - 1 ) )
> {
> k++;
> return true;
> }
> return false;
> }
>
> /*
> * (non-Javadoc)
> * * @see
> org.eclipse.birt.chart.factory.IDataRowExpressionEvaluator#c lose()
> */
> public void close( )
> {
> // Doing nothing.
> }
>
> }
>
Re: Stacked bar chart [message #260160 is a reply to message #260074] Wed, 31 October 2007 21:44 Go to previous messageGo to next message
Eclipse UserFriend
David I have tried to debug. I have found that the evaluate method is only
passed the first two expression (Items and Amount1). Unsure of what is
triggering this method only know it never evaluates the remaining data.

If you are able to look at this sometime it would be greatly appreciated.

thanks Cheryl
Re: Stacked bar chart [message #260288 is a reply to message #260160] Thu, 01 November 2007 16:49 Go to previous messageGo to next message
Eclipse UserFriend
I found the problem, you had only one SeriesDefinition, you need one
seriesdef for each series. They can hold more series, in the case they are
dynamically created due to dynamic grouping. Anyway, here is the right code:

SeriesDefinition sdY = SeriesDefinitionImpl.create();

yAxisPrimary.getSeriesDefinitions().add(sdY);

sdY.getSeries().add(bs1);


SeriesDefinition sdY2 = SeriesDefinitionImpl.create();

yAxisPrimary.getSeriesDefinitions().add(sdY2);

sdY2.getSeries().add(bs2);


SeriesDefinition sdY3 = SeriesDefinitionImpl.create();

yAxisPrimary.getSeriesDefinitions().add(sdY3);

sdY3.getSeries().add(bs3);

You also want to ensure you setStacked(true) to all series, or you will have
a mix of side-by-side and stacked.

Thanks,

David



"Chery McNamara" <cheryl.mcnamara@csiro.au> wrote in message
news:b1aa382bffc05e9dd97a0c71548f3516$1@www.eclipse.org...
> David I have tried to debug. I have found that the evaluate method is only
> passed the first two expression (Items and Amount1). Unsure of what is
> triggering this method only know it never evaluates the remaining data.
>
> If you are able to look at this sometime it would be greatly appreciated.
>
> thanks Cheryl
>
>
Re: Stacked bar chart [message #260311 is a reply to message #260288] Thu, 01 November 2007 21:01 Go to previous messageGo to next message
Eclipse UserFriend
The solution you have suggested is the work around I am already using. It
does stack correctly but doesn’t color correctly. The whole stack is the
same color.

The birt example stacked chart and others I have seen all put the stacked
series into the one SeriesDefinition. This produces a stacked bar with
different colors.

It is important for me to do it this way as I also will have to chart data
that will have groups of stacked bars.

Looks like the solution for me is to do away with the
DataRowExpressionEvaluator and enter the data differently.

Thanks for all you time.
Cheryl
Re: Stacked bar chart [message #260599 is a reply to message #260311] Mon, 05 November 2007 08:07 Go to previous message
Eclipse UserFriend
Here is an updated code that will show a different color for each series,
you have to set a different palette for each of the seriesDefinition:
SeriesDefinition sdY = SeriesDefinitionImpl.create();

yAxisPrimary.getSeriesDefinitions().add(sdY);

sdY.getSeries().add(bs1);

sdY.setSeriesPalette( PaletteImpl.create( ColorDefinitionImpl.create(
255,255,0 ) ) );


SeriesDefinition sdY2 = SeriesDefinitionImpl.create();

yAxisPrimary.getSeriesDefinitions().add(sdY2);

sdY2.getSeries().add(bs2);

sdY2.setSeriesPalette( PaletteImpl.create( ColorDefinitionImpl.create(
255,0,255 ) ) );


SeriesDefinition sdY3 = SeriesDefinitionImpl.create();

yAxisPrimary.getSeriesDefinitions().add(sdY3);

sdY3.getSeries().add(bs3);

sdY3.setSeriesPalette( PaletteImpl.create( ColorDefinitionImpl.create(
0,255,0 ) ) );




If you really want to use a single seriesdefinition, you will need to use
the bindData() method, and define a grouping on the y series to
automatically generate runtime series. In that case, you will need to define
only one palette with multiple colors.

Thanks,

David



"Chery McNamara" <cheryl.mcnamara@csiro.au> wrote in message
news:66eafd2afdcbb23b3632393940fdfe41$1@www.eclipse.org...
> The solution you have suggested is the work around I am already using. It
> does stack correctly but doesn
Previous Topic:retrieve a message from JDBC ?
Next Topic:BIRT 2.2.1 and WAS CE 2.0 - can't start BIRT.
Goto Forum:
  


Current Time: Wed May 14 08:00:29 EDT 2025

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

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

Back to the top