Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
THRUST SERVICES & TOOLS
CLOUD EDITIONS
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
Missing Class - Birt Chart Engine
cgswtsu78
Hello,
I'm getting a runtime exception when trying to create a Birt Bar report dynamically using the Birt Chart Engine API. It's unable to find the org.eclipse.birt.chart.extension.render.Bar on the classpath. I'm using all 2.5 jars from the 2.5 chart engine downloaddeploymentruntimechartengine directory....any suggestions?
java.lang.ClassNotFoundException: org.eclipse.birt.chart.extension.render.Bar
Find more posts tagged with
Comments
JasonW
How are you calling the API?<br />
I assume you added all the libs in that directory to your classpath.<br />
<br />
Does it look similar to the following?<br />
<br />
import java.awt.Graphics;<br />
import java.awt.Graphics2D;<br />
import java.awt.image.BufferedImage;<br />
import java.io.BufferedWriter;<br />
import java.io.FileWriter;<br />
<br />
import org.eclipse.birt.chart.api.ChartEngine;<br />
import org.eclipse.birt.chart.device.EmptyUpdateNotifier;<br />
import org.eclipse.birt.chart.device.IDeviceRenderer;<br />
import org.eclipse.birt.chart.device.IDisplayServer;<br />
import org.eclipse.birt.chart.device.IImageMapEmitter;<br />
import org.eclipse.birt.chart.factory.GeneratedChartState;<br />
import org.eclipse.birt.chart.factory.IGenerator;<br />
import org.eclipse.birt.chart.model.Chart;<br />
import org.eclipse.birt.chart.model.ChartWithAxes;<br />
import org.eclipse.birt.chart.model.attribute.AxisType;<br />
import org.eclipse.birt.chart.model.attribute.Bounds;<br />
import org.eclipse.birt.chart.model.attribute.IntersectionType;<br />
import org.eclipse.birt.chart.model.attribute.LegendItemType;<br />
import org.eclipse.birt.chart.model.attribute.Position;<br />
import org.eclipse.birt.chart.model.attribute.TickStyle;<br />
import org.eclipse.birt.chart.model.attribute.impl.BoundsImpl;<br />
import org.eclipse.birt.chart.model.attribute.impl.ColorDefinitionImpl;<br />
import org.eclipse.birt.chart.model.component.Axis;<br />
import org.eclipse.birt.chart.model.component.Series;<br />
import org.eclipse.birt.chart.model.component.impl.SeriesImpl;<br />
import org.eclipse.birt.chart.model.data.BaseSampleData;<br />
import org.eclipse.birt.chart.model.data.DataFactory;<br />
import org.eclipse.birt.chart.model.data.NumberDataSet;<br />
import org.eclipse.birt.chart.model.data.OrthogonalSampleData;<br />
import org.eclipse.birt.chart.model.data.SampleData;<br />
import org.eclipse.birt.chart.model.data.SeriesDefinition;<br />
import org.eclipse.birt.chart.model.data.TextDataSet;<br />
import org.eclipse.birt.chart.model.data.impl.NumberDataSetImpl;<br />
import org.eclipse.birt.chart.model.data.impl.SeriesDefinitionImpl;<br />
import org.eclipse.birt.chart.model.data.impl.TextDataSetImpl;<br />
import org.eclipse.birt.chart.model.impl.ChartWithAxesImpl;<br />
import org.eclipse.birt.chart.model.layout.Legend;<br />
import org.eclipse.birt.chart.model.layout.Plot;<br />
import org.eclipse.birt.chart.model.type.BarSeries;<br />
import org.eclipse.birt.chart.model.type.impl.BarSeriesImpl;<br />
import org.eclipse.birt.core.framework.PlatformConfig;<br />
<br />
<br />
public class StandaloneChart {<br />
<br />
private static String OUTPUT = "output/Standalone.png"; //$NON-NLS-1$<br />
private static String OUTPUT_HTML = "output/Standalone.html"; //$NON-NLS-1$<br />
<br />
/**<br />
* Comment for <code>serialVersionUID</code><br />
*/<br />
private static final long serialVersionUID = 1L;<br />
<br />
/**<br />
* A chart model instance<br />
*/<br />
private Chart cm = null;<br />
<br />
/**<br />
* The swing rendering device<br />
*/<br />
private IDeviceRenderer dRenderer = null;<br />
private IDisplayServer dServer = null;<br />
<br />
private GeneratedChartState gcs = null;<br />
<br />
/**<br />
* execute application<br />
* <br />
*
@param
args<br />
*/<br />
public static void main(String[] args) {<br />
new StandaloneChart();<br />
System.out.println("Finished");<br />
}<br />
<br />
/**<br />
* Constructor<br />
*/<br />
public StandaloneChart() {<br />
PlatformConfig pf = new PlatformConfig();<br />
pf.setProperty("STANDALONE", true);<br />
<br />
//Returns a singleton instance of the Chart Engine<br />
ChartEngine ce = ChartEngine.instance(pf);<br />
//Returns a singleton instance of the Generator<br />
IGenerator gr = ce.getGenerator();<br />
<br />
try {<br />
//device renderers for dv.SWT, dv.PNG, dv.JPG<br />
//dv.PDF, dv.SVG, dv.SWING, dv.PNG24, div.BMP<br />
dRenderer = ce.getRenderer("dv.PNG");<br />
dServer = dRenderer.getDisplayServer();<br />
} catch (Exception ex) {<br />
ex.printStackTrace();<br />
}<br />
<br />
cm = StandaloneChart.createStackedBar();<br />
<br />
<br />
BufferedImage img = new BufferedImage(600, 600,<br />
BufferedImage.TYPE_INT_ARGB);<br />
Graphics g = img.getGraphics();<br />
<br />
Graphics2D g2d = (Graphics2D) g;<br />
//Look at IDeviceRenderer.java for all properties<br />
//like DPI_RESOLUTION<br />
//FILE_IDENTIFIER<br />
//FORMAT_IDENTIFIER<br />
//UPDATE_NOTIFIER<br />
dRenderer.setProperty(IDeviceRenderer.GRAPHICS_CONTEXT, g2d);<br />
dRenderer.setProperty(IDeviceRenderer.FILE_IDENTIFIER, OUTPUT); //$NON-NLS-1$<br />
<br />
//Set the bounds for the entire chart<br />
Bounds bo = BoundsImpl.create(0, 0, 600, 600);<br />
bo.scale(72d / dRenderer.getDisplayServer().getDpiResolution());<br />
<br />
try {<br />
<br />
gcs = gr.build(dServer, cm, bo, null, null, null);<br />
//gcs.getRunTimeContext().setActionRenderer( new MyActionRenderer());<br />
dRenderer.setProperty(IDeviceRenderer.UPDATE_NOTIFIER,<br />
new EmptyUpdateNotifier(cm, gcs.getChartModel()));<br />
<br />
gr.render(dRenderer, gcs);<br />
String im = ((IImageMapEmitter) dRenderer).getImageMap();<br />
<br />
BufferedWriter out = new BufferedWriter(new FileWriter(OUTPUT_HTML));<br />
<br />
out.write("<html>");<br />
out.newLine();<br />
out.write("<body>");<br />
out.newLine();<br />
out.write("<div>");<br />
out.newLine();<br />
out.write("<map name='testmap'>");<br />
out.write(im);<br />
out.write("</map>");<br />
out.newLine();<br />
out<br />
.write("standalone.png</img>");<br />
out.newLine();<br />
out.write("</div>");<br />
out.newLine();<br />
out.write("</body>");<br />
out.newLine();<br />
out.write("</html>");<br />
out.newLine();<br />
out.close();<br />
<br />
System.out.println(im);<br />
<br />
} catch (Exception e) {<br />
// TODO Auto-generated catch block<br />
e.printStackTrace();<br />
}<br />
}<br />
<br />
<br />
public static final Chart createStackedBar()<br />
{<br />
ChartWithAxes cwaBar = ChartWithAxesImpl.create();<br />
cwaBar.setType("Bar Chart"); //$NON-NLS-1$<br />
cwaBar.setSubType("Stacked"); //$NON-NLS-1$<br />
<br />
// Plot<br />
cwaBar.getBlock().setBackground(ColorDefinitionImpl.WHITE());<br />
cwaBar.getBlock().getOutline().setVisible(true);<br />
Plot p = cwaBar.getPlot();<br />
p.getClientArea().setBackground(ColorDefinitionImpl.create(255,<br />
255,<br />
225));<br />
// Title<br />
cwaBar.getTitle()<br />
.getLabel()<br />
.getCaption()<br />
.setValue("Stacked Bar Chart"); //$NON-NLS-1$<br />
<br />
// Legend<br />
Legend lg = cwaBar.getLegend();<br />
<br />
lg.setItemType(LegendItemType.CATEGORIES_LITERAL);<br />
// X-Axis<br />
Axis xAxisPrimary = cwaBar.getPrimaryBaseAxes()[0];<br />
xAxisPrimary.setType(AxisType.TEXT_LITERAL);<br />
xAxisPrimary.getMajorGrid().setTickStyle(TickStyle.BELOW_LITERAL);<br />
xAxisPrimary.getOrigin().setType(IntersectionType.MIN_LITERAL);<br />
// Y-Axis<br />
Axis yAxisPrimary = cwaBar.getPrimaryOrthogonalAxis(xAxisPrimary);<br />
yAxisPrimary.getMajorGrid().setTickStyle(TickStyle.LEFT_LITERAL);<br />
yAxisPrimary.setType(AxisType.LINEAR_LITERAL);<br />
yAxisPrimary.setLabelPosition(Position.RIGHT_LITERAL);<br />
yAxisPrimary.getLabel().getCaption().getFont().setRotation(45);<br />
// Data Set<br />
TextDataSet categoryValues = TextDataSetImpl.create(new String[] {<br />
"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$<br />
NumberDataSet orthoValues1 = NumberDataSetImpl.create(new double[] {<br />
<br />
25, 35, 15, 5, 20<br />
<br />
});<br />
NumberDataSet orthoValues2 = NumberDataSetImpl.create(new double[] {<br />
<br />
5, 10, 25, 10, 5<br />
<br />
});<br />
SampleData sd = DataFactory.eINSTANCE.createSampleData();<br />
BaseSampleData sdBase = DataFactory.eINSTANCE.createBaseSampleData();<br />
sdBase.setDataSetRepresentation("");//$NON-NLS-1$<br />
sd.getBaseSampleData().add(sdBase);<br />
OrthogonalSampleData sdOrthogonal1 = DataFactory.eINSTANCE<br />
.createOrthogonalSampleData();<br />
sdOrthogonal1.setDataSetRepresentation("");//$NON-NLS-1$<br />
sdOrthogonal1.setSeriesDefinitionIndex(0);<br />
sd.getOrthogonalSampleData().add(sdOrthogonal1);<br />
OrthogonalSampleData sdOrthogonal2 = DataFactory.eINSTANCE<br />
.createOrthogonalSampleData();<br />
sdOrthogonal2.setDataSetRepresentation("");//$NON-NLS-1$<br />
sdOrthogonal2.setSeriesDefinitionIndex(1);<br />
sd.getOrthogonalSampleData().add(sdOrthogonal2);<br />
cwaBar.setSampleData(sd);<br />
<br />
// X-Series<br />
Series seCategory = SeriesImpl.create();<br />
seCategory.setDataSet(categoryValues);<br />
SeriesDefinition sdX = SeriesDefinitionImpl.create();<br />
xAxisPrimary.getSeriesDefinitions().add(sdX);<br />
sdX.getSeries().add(seCategory);<br />
sdX.getSeriesPalette().shift(0);<br />
<br />
// Y-Series<br />
BarSeries bs1 = (BarSeries) BarSeriesImpl.create();<br />
bs1.setDataSet(orthoValues1);<br />
bs1.setStacked(true);<br />
bs1.getLabel().setVisible(true);<br />
bs1.setLabelPosition(Position.INSIDE_LITERAL);<br />
bs1.setRiserOutline(ColorDefinitionImpl.TRANSPARENT());<br />
BarSeries bs2 = (BarSeries) BarSeriesImpl.create();<br />
bs2.setDataSet(orthoValues2);<br />
bs2.setStacked(true);<br />
bs2.setRiserOutline(ColorDefinitionImpl.TRANSPARENT());<br />
bs2.getLabel().setVisible(true);<br />
bs2.setLabelPosition(Position.INSIDE_LITERAL);<br />
<br />
SeriesDefinition sdY = SeriesDefinitionImpl.create();<br />
sdY.getSeriesPalette().shift(0);<br />
yAxisPrimary.getSeriesDefinitions().add(sdY);<br />
sdY.getSeries().add(bs1);<br />
sdY.getSeries().add(bs2);<br />
return cwaBar;<br />
<br />
}<br />
<br />
}
cgswtsu78
This ended up being a build error. We included some of the 2.5.0 and some of the 2.5.1 brit chart engine jars. This was fixed by using all 2.5.1 jars.