Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » BIRT » Bar chart x-axis labels changed to letters after upgrade
Bar chart x-axis labels changed to letters after upgrade [message #674396] Thu, 26 May 2011 18:38 Go to next message
Jason Woods is currently offline Jason WoodsFriend
Messages: 13
Registered: July 2009
Junior Member
I've recently upgraded from Eclipse 3.4 to 3.6.2. I'm using the BIRT chart engine standalone in some SWT code I have. I have several bar charts that prior to upgrading showed the numeric values of the data along the x-axis (with type AxisType.LINEAR_LITERAL). After upgrading, all these charts are showing a character (or set of characters) instead of a number. Example...1 would show as N, and higher numbers would show as something like NLMM, etc. The data being charted is simple integer values for both x/y values (think of a size/frequency distribution chart). Both data sets are NumberDataSet instances.

Has something in the API changed? What should I be looking at to fix this?

[Updated on: Thu, 26 May 2011 18:41]

Report message to a moderator

Re: Bar chart x-axis labels changed to letters after upgrade [message #674402 is a reply to message #674396] Thu, 26 May 2011 19:05 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason WeathersbyFriend
Messages: 9167
Registered: July 2009
Senior Member

Can you post the code?

Jason

On 5/26/2011 2:38 PM, Jason Woods wrote:
> I've recently upgraded from Eclipse 3.4 to 3.6.2. I'm using the BIRT
> chart engine standalone in some SWT code I have. I have several bar
> charts that prior to upgrading showed the numeric values of the data
> along the x-axis (with type AxisType.LINEAR_LITERAL). After upgrading,
> all these charts are showing a character (or set of characters) instead
> of a number. Example...1 would show as N, and higher numbers would show
> as something like NLMM, etc. The data being charted is simple integer
> values for both x/y values (think of a size/frequency distribution chart).
>
> Has something in the API changed? What should I be looking at to fix this?
Re: Bar chart x-axis labels changed to letters after upgrade [message #674405 is a reply to message #674402] Thu, 26 May 2011 19:40 Go to previous messageGo to next message
Jason Woods is currently offline Jason WoodsFriend
Messages: 13
Registered: July 2009
Junior Member
Here is the code to create one of the charts:

ChartWithAxes chart = ChartWithAxesImpl.create();
chart.setDimension(ChartDimension.TWO_DIMENSIONAL_LITERAL);

// CUSTOMIZE THE PLOT
Plot p = chart.getPlot();
p.getOutline().setVisible(false);
chart.getTitle().setVisible(false);
chart.getLegend().setVisible(false);

// CUSTOMIZE THE X-AXIS
xAxisPrimary = chart.getPrimaryBaseAxes()[0];
xAxisPrimary.setType(AxisType.LINEAR_LITERAL);

xAxisPrimary.getMajorGrid().setTickStyle(TickStyle.BELOW_LITERAL);
xAxisPrimary.getTitle().setVisible(true);
xAxisPrimary.getTitle().getCaption().setValue("Size");
xAxisPrimary.getTitle().getCaption().getFont().setSize(10);
xAxisPrimary.getLabel().getCaption().getFont().setSize(8);
xAxisPrimary.getLabel().getCaption().getFont().setRotation(-90);

// CUSTOMIZE THE Y-AXIS
yAxisPrimary = chart.getPrimaryOrthogonalAxis(xAxisPrimary);
yAxisPrimary.getMajorGrid().setTickStyle(TickStyle.LEFT_LITERAL);
yAxisPrimary.setType(AxisType.LOGARITHMIC_LITERAL);
yAxisPrimary.getScale().setMin(NumberDataElementImpl.create(1));
yAxisPrimary.getTitle().getCaption().setValue("Count");
yAxisPrimary.getTitle().getCaption().getFont().setSize(10);
yAxisPrimary.getLabel().getCaption().getFont().setRotation(0);
yAxisPrimary.getLabel().getCaption().getFont().setSize(8);

// CREATE THE CATEGORY BASE SERIES
seCategory = SeriesImpl.create();

// CREATE THE PRIMARY VALUE ORTHOGONAL SERIES
ss1 = (BarSeries) BarSeriesImpl.create();
ss1.getLabel().setVisible(false);

// WRAP THE BASE SERIES IN THE X-AXIS SERIES DEFINITION
SeriesDefinition sdX = SeriesDefinitionImpl.create();
xAxisPrimary.getSeriesDefinitions().add(sdX);
sdX.getSeries().add(seCategory);

// WRAP THE PRIMARY ORTHOGONAL SERIES IN THE X-AXIS SERIES DEFINITION
SeriesDefinition sdY = SeriesDefinitionImpl.create();
yAxisPrimary.getSeriesDefinitions().add(sdY);
sdY.getSeries().add(ss1);


And later on when I set the data into the chart (both sizeList and countList contain a list of Long values):

// INITIALIZE A COLLECTION WITH THE X-SERIES DATA (size)
NumberDataSet categoryValues = NumberDataSetImpl.create(sizeList);

// INITIALIZE A COLLECTION WITH THE PRIMARY Y-SERIES DATA (count)
NumberDataSet orthoValues1 = NumberDataSetImpl.create(countList);

seCategory.setDataSet(categoryValues);
ss1.setDataSet(orthoValues1);
Re: Bar chart x-axis labels changed to letters after upgrade [message #674415 is a reply to message #674405] Thu, 26 May 2011 20:36 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason WeathersbyFriend
Messages: 9167
Registered: July 2009
Senior Member

Any chance you could try with doubles instead of longs? I think the
NumberDataSet processing only supports the following:

if ( iDataType == IConstants.NUMERICAL )
{
if ( oContent instanceof Collection )
{
iContentType = IConstants.COLLECTION;
co = (Collection) oContent;
}
else if ( oContent instanceof double[] )
{
iContentType = IConstants.PRIMITIVE_ARRAY;
da = (double[]) oContent;
}
else if ( oContent instanceof Double[] )
{
iContentType = IConstants.NON_PRIMITIVE_ARRAY;
dda = (Double[]) oContent;
}
else if ( oContent instanceof BigNumber[])
{
iContentType = IConstants.BIG_NUMBER_PRIMITIVE_ARRAY;
cnda = (BigNumber[])oContent;
}
else if ( oContent instanceof Number[])
{
iContentType = IConstants.NUMBER_PRIMITIVE_ARRAY;
nda = (Number[])oContent;
}
}


Jason


On 5/26/2011 3:40 PM, Jason Woods wrote:
> Here is the code to create one of the charts:
>
> ChartWithAxes chart = ChartWithAxesImpl.create();
> chart.setDimension(ChartDimension.TWO_DIMENSIONAL_LITERAL);
> // CUSTOMIZE THE PLOT
> Plot p = chart.getPlot();
> p.getOutline().setVisible(false);
> chart.getTitle().setVisible(false);
> chart.getLegend().setVisible(false);
>
> // CUSTOMIZE THE X-AXIS xAxisPrimary = chart.getPrimaryBaseAxes()[0];
> xAxisPrimary.setType(AxisType.LINEAR_LITERAL);
>
> xAxisPrimary.getMajorGrid().setTickStyle(TickStyle.BELOW_LITERAL);
> xAxisPrimary.getTitle().setVisible(true);
> xAxisPrimary.getTitle().getCaption().setValue("Size");
> xAxisPrimary.getTitle().getCaption().getFont().setSize(10);
> xAxisPrimary.getLabel().getCaption().getFont().setSize(8);
> xAxisPrimary.getLabel().getCaption().getFont().setRotation(-90);
>
> // CUSTOMIZE THE Y-AXIS yAxisPrimary =
> chart.getPrimaryOrthogonalAxis(xAxisPrimary);
> yAxisPrimary.getMajorGrid().setTickStyle(TickStyle.LEFT_LITERAL);
> yAxisPrimary.setType(AxisType.LOGARITHMIC_LITERAL);
> yAxisPrimary.getScale().setMin(NumberDataElementImpl.create(1));
> yAxisPrimary.getTitle().getCaption().setValue("Count");
> yAxisPrimary.getTitle().getCaption().getFont().setSize(10);
> yAxisPrimary.getLabel().getCaption().getFont().setRotation(0);
> yAxisPrimary.getLabel().getCaption().getFont().setSize(8);
>
> // CREATE THE CATEGORY BASE SERIES seCategory = SeriesImpl.create();
> // CREATE THE PRIMARY VALUE ORTHOGONAL SERIES
> ss1 = (BarSeries) BarSeriesImpl.create();
> ss1.getLabel().setVisible(false);
> // WRAP THE BASE SERIES IN THE X-AXIS SERIES DEFINITION
> SeriesDefinition sdX = SeriesDefinitionImpl.create();
> xAxisPrimary.getSeriesDefinitions().add(sdX);
> sdX.getSeries().add(seCategory);
>
> // WRAP THE PRIMARY ORTHOGONAL SERIES IN THE X-AXIS SERIES DEFINITION
> SeriesDefinition sdY = SeriesDefinitionImpl.create();
> yAxisPrimary.getSeriesDefinitions().add(sdY); sdY.getSeries().add(ss1);
>
>
> And later on when I set the data into the chart (both sizeList and
> countList contain a list of Long values):
>
> // INITIALIZE A COLLECTION WITH THE X-SERIES DATA (size)
> NumberDataSet categoryValues = NumberDataSetImpl.create(sizeList);
> // INITIALIZE A COLLECTION WITH THE PRIMARY Y-SERIES DATA (count)
> NumberDataSet orthoValues1 = NumberDataSetImpl.create(countList);
> seCategory.setDataSet(categoryValues);
> ss1.setDataSet(orthoValues1);
>
Re: Bar chart x-axis labels changed to letters after upgrade [message #674418 is a reply to message #674415] Thu, 26 May 2011 20:53 Go to previous messageGo to next message
Jason Woods is currently offline Jason WoodsFriend
Messages: 13
Registered: July 2009
Junior Member
I tried, doesn't make a difference. I even tried turning all the x-values into their string equivalents and changed the x-axis type to TEXT_LITERAL and it's still showing the bizarre lettering for the scale values instead of the string values in the data.
Re: Bar chart x-axis labels changed to letters after upgrade [message #674436 is a reply to message #674418] Thu, 26 May 2011 22:02 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason WeathersbyFriend
Messages: 9167
Registered: July 2009
Senior Member

Take a look at this example. You should be able to switch the axis type
from LINEAR to TEXT or back and set the cat values to either:
seCategory.setDataSet(categoryValues);
or
seCategory.setDataSet(orthoValues2);

Jason


import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.BufferedWriter;
import java.io.FileWriter;

import org.eclipse.birt.chart.api.ChartEngine;
import org.eclipse.birt.chart.device.EmptyUpdateNotifier;
import org.eclipse.birt.chart.device.IDeviceRenderer;
import org.eclipse.birt.chart.device.IDisplayServer;
import org.eclipse.birt.chart.device.IImageMapEmitter;
import org.eclipse.birt.chart.factory.GeneratedChartState;
import org.eclipse.birt.chart.factory.IGenerator;
import org.eclipse.birt.chart.model.Chart;
import org.eclipse.birt.chart.model.ChartWithAxes;
import org.eclipse.birt.chart.model.attribute.ActionType;
import org.eclipse.birt.chart.model.attribute.AxisType;
import org.eclipse.birt.chart.model.attribute.Bounds;
import org.eclipse.birt.chart.model.attribute.IntersectionType;
import org.eclipse.birt.chart.model.attribute.LegendItemType;
import org.eclipse.birt.chart.model.attribute.Position;
import org.eclipse.birt.chart.model.attribute.TickStyle;
import org.eclipse.birt.chart.model.attribute.TriggerCondition;
import org.eclipse.birt.chart.model.attribute.impl.BoundsImpl;
import org.eclipse.birt.chart.model.attribute.impl.ColorDefinitionImpl;
import org.eclipse.birt.chart.model.attribute.impl.TooltipValueImpl;
import org.eclipse.birt.chart.model.attribute.impl.URLValueImpl;
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.NullDataSet;
import org.eclipse.birt.chart.model.data.NumberDataSet;
import org.eclipse.birt.chart.model.data.OrthogonalSampleData;
import org.eclipse.birt.chart.model.data.SampleData;
import org.eclipse.birt.chart.model.data.SeriesDefinition;
import org.eclipse.birt.chart.model.data.TextDataSet;
import org.eclipse.birt.chart.model.data.Trigger;
import org.eclipse.birt.chart.model.data.impl.ActionImpl;
import org.eclipse.birt.chart.model.data.impl.NullDataSetImpl;
import org.eclipse.birt.chart.model.data.impl.NumberDataSetImpl;
import org.eclipse.birt.chart.model.data.impl.SeriesDefinitionImpl;
import org.eclipse.birt.chart.model.data.impl.TextDataSetImpl;
import org.eclipse.birt.chart.model.data.impl.TriggerImpl;
import org.eclipse.birt.chart.model.impl.ChartWithAxesImpl;
import org.eclipse.birt.chart.model.layout.Legend;
import org.eclipse.birt.chart.model.layout.Plot;
import org.eclipse.birt.chart.model.type.BarSeries;
import org.eclipse.birt.chart.model.type.impl.BarSeriesImpl;
import org.eclipse.birt.core.framework.PlatformConfig;

/**
* Test decription:
* </p>
* Chart script: BeforeDrawLegendItem()
* </p>
*/

public class StandaloneChart {

private static String OUTPUT = "output/Standalone.png"; //$NON-NLS-1$
private static String OUTPUT_HTML = "output/Standalone.html"; //$NON-NLS-1$

/**
* Comment for <code>serialVersionUID</code>
*/
private static final long serialVersionUID = 1L;

/**
* A chart model instance
*/
private Chart cm = null;

/**
* The swing rendering device
*/
private IDeviceRenderer dRenderer = null;
private IDisplayServer dServer = null;

private GeneratedChartState gcs = null;

/**
* execute application
*
* @param args
*/
public static void main(String[] args) {
new StandaloneChart();
System.out.println("Finished");
}

/**
* Constructor
*/
public StandaloneChart() {
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();
} catch (Exception ex) {
ex.printStackTrace();
}

//cm = new AfterDatasetFilled().GetChartModel();
cm = StandaloneChart.createStackedBar();
//cm = StandaloneChart.createGrouponY();
//cm = StandaloneChart.createStockChart();
//cm = StandaloneChart.createTest();
BufferedImage img = new BufferedImage(600, 600,
BufferedImage.TYPE_INT_ARGB);
Graphics g = img.getGraphics();

Graphics2D g2d = (Graphics2D) g;

//Look at IDeviceRenderer.java for all properties
//like DPI_RESOLUTION
//FILE_IDENTIFIER
//FORMAT_IDENTIFIER
//UPDATE_NOTIFIER
dRenderer.setProperty(IDeviceRenderer.GRAPHICS_CONTEXT, g2d);
dRenderer.setProperty(IDeviceRenderer.FILE_IDENTIFIER, OUTPUT);
//$NON-NLS-1$

//Set the bounds for the entire chart
Bounds bo = BoundsImpl.create(0, 0, 600, 600);
bo.scale(72d / dRenderer.getDisplayServer().getDpiResolution());

try {

gcs = gr.build(dServer, cm, bo, null, null, null);
//gcs.getRunTimeContext().setActionRenderer( new MyActionRenderer());
//have to have this line if you want the image map generated
dRenderer.setProperty(IDeviceRenderer.UPDATE_NOTIFIER,
new EmptyUpdateNotifier(cm, gcs.getChartModel()));

gr.render(dRenderer, gcs);
String im = ((IImageMapEmitter) dRenderer).getImageMap();

BufferedWriter out = new BufferedWriter(new FileWriter(OUTPUT_HTML));

out.write("<html>");
out.newLine();
out.write("<body>");
out.newLine();
out.write("<div>");
out.newLine();
if( im != null){
out.write("<map name='testmap'>");
out.write(im);
out.write("</map>");
out.newLine();
}
out
.write("<img id=myimage src='standalone.png'
usemap='#testmap'></img>");
out.newLine();
out.write("</div>");
out.newLine();
out.write("</body>");
out.newLine();
out.write("</html>");
out.newLine();
out.close();

System.out.println(im);

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

public static final Chart createStackedBar()

{

ChartWithAxes cwaBar = ChartWithAxesImpl.create();

cwaBar.setType("Bar Chart"); //$NON-NLS-1$

cwaBar.setSubType("Stacked"); //$NON-NLS-1$

// Plot

cwaBar.getBlock().setBackground(ColorDefinitionImpl.WHITE());

cwaBar.getBlock().getOutline().setVisible(true);

Plot p = cwaBar.getPlot();

p.getClientArea().setBackground(ColorDefinitionImpl.create(255,

255,

225));

// Title

cwaBar.getTitle()

.getLabel()

.getCaption()

.setValue("Stacked Bar Chart"); //$NON-NLS-1$

// Legend

Legend lg = cwaBar.getLegend();

lg.setItemType(LegendItemType.CATEGORIES_LITERAL);

//Add Script

cwaBar
.setScript("function beforeGeneration( cm, icsc )"
+ "{importPackage(Packages.org.eclipse.birt.chart.model.attribute); "
+ "
importPackage(Packages.org.eclipse.birt.chart.model.attribute.impl); "
+ " cm.getLegend().getOutline( ).setStyle(
LineStyle.DASH_DOTTED_LITERAL );"
+ " cm.getLegend().getOutline( ).setColor(
ColorDefinitionImpl.GREEN() );"
+ " cm.getLegend().getOutline( ).setVisible( true );} ");

// X-Axis

Axis xAxisPrimary = cwaBar.getPrimaryBaseAxes()[0];

xAxisPrimary.setType(AxisType.LINEAR_LITERAL);

xAxisPrimary.getMajorGrid().setTickStyle(TickStyle.BELOW_LITERAL);

xAxisPrimary.getOrigin().setType(IntersectionType.MIN_LITERAL);

// Y-Axis

Axis yAxisPrimary = cwaBar.getPrimaryOrthogonalAxis(xAxisPrimary);

yAxisPrimary.getMajorGrid().setTickStyle(TickStyle.LEFT_LITERAL);

yAxisPrimary.setType(AxisType.LINEAR_LITERAL);

yAxisPrimary.setLabelPosition(Position.RIGHT_LITERAL);
yAxisPrimary.getLabel().getCaption().getFont().setRotation(45);

// Data Set

TextDataSet categoryValues = TextDataSetImpl.create(new String[] {
"Item 1a", "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

});
NullDataSet ortho = NullDataSetImpl.create(5);



SampleData sd = DataFactory.eINSTANCE.createSampleData();

BaseSampleData sdBase = DataFactory.eINSTANCE.createBaseSampleData();

sdBase.setDataSetRepresentation("");//$NON-NLS-1$

sd.getBaseSampleData().add(sdBase);

OrthogonalSampleData sdOrthogonal1 = DataFactory.eINSTANCE
.createOrthogonalSampleData();

sdOrthogonal1.setDataSetRepresentation("");//$NON-NLS-1$

sdOrthogonal1.setSeriesDefinitionIndex(0);

sd.getOrthogonalSampleData().add(sdOrthogonal1);

OrthogonalSampleData sdOrthogonal2 = DataFactory.eINSTANCE
.createOrthogonalSampleData();

sdOrthogonal2.setDataSetRepresentation("");//$NON-NLS-1$

sdOrthogonal2.setSeriesDefinitionIndex(1);

sd.getOrthogonalSampleData().add(sdOrthogonal2);

cwaBar.setSampleData(sd);

// X-Series

Series seCategory = SeriesImpl.create();

seCategory.setDataSet(orthoValues2);

SeriesDefinition sdX = SeriesDefinitionImpl.create();

xAxisPrimary.getSeriesDefinitions().add(sdX);

sdX.getSeries().add(seCategory);
sdX.getSeriesPalette().shift(0);

// Y-Series

BarSeries bs1 = (BarSeries) BarSeriesImpl.create();

bs1.setDataSet(orthoValues1);
//bs1.setDataSet(ortho);

bs1.setStacked(true);

bs1.getLabel().setVisible(true);

bs1.setLabelPosition(Position.INSIDE_LITERAL);
bs1.setRiserOutline(ColorDefinitionImpl.TRANSPARENT());
Trigger tr1 = TriggerImpl.create(TriggerCondition.ONMOUSEOVER_LITERAL,
ActionImpl.create(ActionType.SHOW_TOOLTIP_LITERAL,
TooltipValueImpl.create(200, null)));
Trigger tr2 = TriggerImpl.create(TriggerCondition.ONCLICK_LITERAL,
ActionImpl.create(ActionType.URL_REDIRECT_LITERAL, URLValueImpl
.create("https://www.google.com", null, "component",
"value", "")));
bs1.getTriggers().add(tr1);
bs1.getTriggers().add(tr2);

SeriesDefinition sdY = SeriesDefinitionImpl.create();

sdY.getSeriesPalette().shift(0);

yAxisPrimary.getSeriesDefinitions().add(sdY);

sdY.getSeries().add(bs1);

return cwaBar;

}


}


On 5/26/2011 4:53 PM, Jason Woods wrote:
> I tried, doesn't make a difference. I even tried turning all the
> x-values into their string equivalents and changed the x-axis type to
> TEXT_LITERAL and it's still showing the bizarre lettering for the scale
> values instead of the string values in the data.
Re: Bar chart x-axis labels changed to letters after upgrade [message #674629 is a reply to message #674436] Fri, 27 May 2011 15:46 Go to previous messageGo to next message
Jason Woods is currently offline Jason WoodsFriend
Messages: 13
Registered: July 2009
Junior Member
I found the line in my original code that is causing the problem:

xAxisPrimary.getLabel().getCaption().getFont().setRotation(-90);

If I set any rotation at all on the x-axis labels the chart will start spitting out letters instead of numbers along the x-axis. Left un-rotated, it behaves as expected. It would seem there has been a bug introduced somewhere along the line in the chart engine...
Re: Bar chart x-axis labels changed to letters after upgrade [message #675427 is a reply to message #674629] Tue, 31 May 2011 13:55 Go to previous message
Jason Weathersby is currently offline Jason WeathersbyFriend
Messages: 9167
Registered: July 2009
Senior Member

This does appear to be a bug with the SWT device renderer. Can you log
a bug for it?

Jason

On 5/27/2011 11:46 AM, Jason Woods wrote:
> I found the line in my original code that is causing the problem:
>
> xAxisPrimary.getLabel().getCaption().getFont().setRotation(-90);
>
> If I set any rotation at all on the x-axis labels the chart will start
> spitting out letters instead of numbers along the x-axis. Left
> un-rotated, it behaves as expected. It would seem there has been a bug
> introduced somewhere along the line in the chart engine...
Previous Topic:expand collapse rows and export to PDF
Next Topic:birt-viewer frameset SLOW
Goto Forum:
  


Current Time: Sun Dec 21 15:21:54 GMT 2014

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

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