Home
Analytics
JSP, JSF, Facelets and Chart Engine API
cgswtsu78
Hello,
I've looked over this forum, imported some of the examples and I've yet to find a working use of a jsp page that dynamically loads a chart. Can anyone help point me in the direction of a full tutorial?
I'm looking at both dynamically creating a chart using the chart engine api and then loading than into a web page. At first I will try JPS then move onto JSF/Facelets. I know several topics have pointed towards using a servlet to load the chart as an image, but each time I download an example there are runtime issues with the servlet and or servlet config.
any help would be greatly appreciated!
Thanks,
Colin
Find more posts tagged with
Comments
JasonW
Colin,
Have you tried to use the Chart tag libs? In order to get them to work you have to have the WTP Integration downloaded and installed in your BIRT install. After that you can create a dynamic web application and add the chart engine tag libs.
Jason
JasonW
Colin,<br />
<br />
I just uploaded an example on DevShare. Here is the link:<br />
<a class='bbc_url' href='
http://www.birt-exchange.org/devshare/deploying-birt-reports/1026-calling-the-chart-engine-from-a-servlet/#description'>Calling
the Chart Engine from a servlet - Designs & Code - BIRT Exchange</a><br />
<br />
Jason
cgswtsu78
Hi Jason,
Thanks for the quick response. I tried out your sample and I'm experiencing a runtime exception in the ChartEnginerNoOSGI.java class when the gr.render(dRenderer, gcs); statement is executed. I don't have the source beyond that call. Below is the tomcat stack trace. This may be due to a classpath difference as I noticed you were using a different version of the chart engine jars. I was attempting to use the same jars that were packaged with the ChartWebWiz sample. I've looked for the latest chart engine runtime but I haven't been successful in finding it. How should I go about this? Will this fix the below issue? Thanks for all your help!
javax.servlet.ServletException: output == null!
DynamicChart.doGet(DynamicChart.java:55)
javax.servlet.http.HttpServlet.service(HttpServlet.java:627)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
root cause
org.eclipse.birt.chart.exception.ChartException: output == null!
org.eclipse.birt.chart.device.image.JavaxImageIOWriter.after(JavaxImageIOWriter.java:592)
org.eclipse.birt.chart.factory.Generator.render(Generator.java:1292)
ChartEngineNoOSGi.buildChart(ChartEngineNoOSGi.java:124)
DynamicChart.doGet(DynamicChart.java:48)
javax.servlet.http.HttpServlet.service(HttpServlet.java:627)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
root cause
java.lang.IllegalStateException: output == null!
com.sun.imageio.plugins.png.PNGImageWriter.write(Unknown Source)
javax.imageio.ImageWriter.write(Unknown Source)
org.eclipse.birt.chart.device.image.JavaxImageIOWriter.after(JavaxImageIOWriter.java:587)
org.eclipse.birt.chart.factory.Generator.render(Generator.java:1292)
ChartEngineNoOSGi.buildChart(ChartEngineNoOSGi.java:124)
DynamicChart.doGet(DynamicChart.java:48)
javax.servlet.http.HttpServlet.service(HttpServlet.java:627)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
JasonW
Look at this link:<br />
<a class='bbc_url' href='
http://download.eclipse.org/birt/downloads/build.php?build=R-R1-2_5_0-200906180630'>Eclipse
BIRT Home</a><br />
<br />
Download the chart engine and use the deploymentruntime directory. Keep in mind there are three jars that are out of sync in that download you will need to get them from the allinone download. Look at the listed bug for details.<br />
<br />
Jason
cgswtsu78
Jason,
I've done as you've stated and I'm still facing issues. For some reason when the ChartEngineNoOSGI's gr.render(dRenderer, gcs); statement is executed the sampel is looking for the below file, any ideas?
java.io.FileNotFoundException: C:codebasebirt.metadata.pluginsorg.eclipse.wst.server.coretmp1wtpwebappsChartWebWizimagesstandalone1253723351386.png (The system cannot find the path specified)
at java.io.RandomAccessFile.open(Native Method)
at java.io.RandomAccessFile.<init>(Unknown Source)
at javax.imageio.stream.FileImageOutputStream.<init>(Unknown Source)
at com.sun.imageio.spi.FileImageOutputStreamSpi.createOutputStreamInstance(Unknown Source)
at javax.imageio.ImageIO.createImageOutputStream(Unknown Source)
at org.eclipse.birt.chart.util.SecurityUtil$14.run(SecurityUtil.java:507)
at org.eclipse.birt.chart.util.SecurityUtil$14.run(SecurityUtil.java:1)
at java.security.AccessController.doPrivileged(Native Method)
at org.eclipse.birt.chart.util.SecurityUtil.newImageOutputStream(SecurityUtil.java:503)
at org.eclipse.birt.chart.device.image.JavaxImageIOWriter.after(JavaxImageIOWriter.java:683)
at org.eclipse.birt.chart.factory.Generator.render(Generator.java:1277)
at ChartEngineNoOSGi.buildChart(ChartEngineNoOSGi.java:124)
at DynamicChart.doGet(DynamicChart.java:48)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:627)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:172)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:873)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
at java.lang.Thread.run(Unknown Source)
org.eclipse.birt.chart.exception.ChartException: output == null!
at org.eclipse.birt.chart.device.image.JavaxImageIOWriter.after(JavaxImageIOWriter.java:697)
at org.eclipse.birt.chart.factory.Generator.render(Generator.java:1277)
at ChartEngineNoOSGi.buildChart(ChartEngineNoOSGi.java:124)
at DynamicChart.doGet(DynamicChart.java:48)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:627)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:172)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:873)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.IllegalStateException: output == null!
at com.sun.imageio.plugins.png.PNGImageWriter.write(Unknown Source)
at javax.imageio.ImageWriter.write(Unknown Source)
at org.eclipse.birt.chart.device.image.JavaxImageIOWriter.after(JavaxImageIOWriter.java:692)
... 19 more
JasonW
How are you running this servlet? What app server do you have deployed to? The example was meant as a standalone servlet. I ran it on Tomcat 5.5. I can tell by the stack trace that the image path is getting messed up:
String imgPth = sc.getRealPath("/images") + "/standalone" + lg +".png";
//You will need to cleanup the images
dRenderer.setProperty(IDeviceRenderer.FILE_IDENTIFIER, imgPth);
This code looks for and images directory in your webapp. Attached is my deployed servlet in a zip file minus the libs you need to get from the chart engine deployment.
Jason
cgswtsu78
thanks Jason, the image was missing from my images directory and now the sample works. Instead of loading a static image it is possible to use the chart engine API and build the chart at runtime correct? We would have a webpage where the user would be shown a default implementation of a chart and then they will be able to enter a few criteria on the web page and click a reload link or button...etc. Then our web app would need to rebuild the chart given the users criteria. Are there any drawbacks to meeting those requirements using the runtime api? Any suggestions?
JasonW
That example regens the image everytime you refresh, so modifying it to put parameters in should be fairly simple. Also notice it supports interactivity using image maps.
Jason
cgswtsu78
Is there a developers guide to using the charting apis? What is the best place to get detailed information on implementing these apis?
JasonW
There are alot of examples here in the dev share.<br />
You can get information out of the BIRT FAQ -<br />
<a class='bbc_url' href='
http://wiki.eclipse.org/BIRT/FAQ/Charts2.2'>BIRT/FAQ/Charts2.2
- Eclipsepedia</a><br />
The JavaDocs are available in the Help system.<br />
There are also a couple of books on BIRT:<br />
<a class='bbc_url' href='
http://www.eclipse.org/birt/phoenix/birthelp.php'>How
to Get Help on Using BIRT</a><br />
<br />
We are in the process of adding more information on the BIRT site about charting.<br />
<br />
Jason
cgswtsu78
Jason,
I still don't see the purpose of the sample application and its most likely due to my inexperience with Birt. In the ChartEngineNoOSGI.buildChart method a static image with surrounding html is sent back to the browser after clicking the submit button on test.jsp. It seems like the ChartEngineNoOSGI.createstackedBar method does dynamically create a bar chart, but then it's never rendered to the browser, instead the static standalone.png image is just sent. How would I render the dynamically created bar chart (cm property) to the browser? Isn't that the point of the example or did I misunderstand the purpose?
Thanks for the help!
Colin
JasonW
I created the image and then the html for the purpose of supporting chart interactivity. I you look there is an image map generated as well.
cgswtsu78
Hi Jason, <br />
<br />
A follow-up question that I have that relates somewhat to my initial topic. <br />
<br />
I need to configure a Birt report to support the following:<br />
-the user initiates a HTTP GET request (say <a class='bbc_url' href='
http://localhost:8080/reports/report1)'>http://localhost:8080/reports/report1)</a>
. That context "reports/report1", calls my REST web service which calls the database (using hibernate) and populates a POJO object(s). I then need to sync my birt report up to read from that pojo and then render the report in the browser. <br />
<br />
The problem is I don't see how I can let Birt knows it's data is ready and how to configure it to consume the pojo structure and then render the report. <br />
<br />
Any suggestions?<br />
<br />
Thanks for your help!!!<br />
<br />
-Colin
JasonW
Are you using the RE API to run the report?
Jason
cgswtsu78
currently my approach was to create a report in the eclipse designer and try to use a scripted dataset to call the rest api in the open method. I don't think that will work since I need to pass parameters to my rest api so that I can use them to make my database call and thusly filter my birt result set. should I be trying a different approach?
JasonW
Why can you get the parameters from report parameters?
Jason
cgswtsu78
your right Jason, I should just get the parms in my scripted data set from the report parms. This worked, thanks.
cgswtsu78
Hi Jason,
When using the birt chart engine api, what series objects are the pyramid and cone and tube. I'm able to use the below to create a bar graph, but I can't find the appropriated classes for the other types.
BarSeries bs1 = (BarSeries) BarSeriesImpl.create()
JasonW
Those are just riser types for the bar chart:
BarSeries bs = (BarSeries) BarSeriesImpl.create( );
bs.setRiser( RiserType.TUBE_LITERAL );
Jason
cgswtsu78
Thanks again, that fixed it. Another issue that I'm facing is that I'm unable to setup my scripted datasource when using the fetch or open functions. The script works fine for the beforeOpenScript, but the fetch and open never get executed. I've even pointed the open script to a class that doesn't exist and it doesn't error out. Is the below valid for combinging script functions at runtime?
//BEFOREOPEN SCRIPT
String beforeOpenScript = "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.BLACK() );"
+ " cm.getLegend().getOutline( ).setVisible( true );} ";
//OPEN SCRIPT
String openScript = "function open()"
+ "{count = 0;"
+ "stub = new Packages.com.proofpoint.resources.TopSpamSender(); "
+ "items = stub.getChartData();}";
//FETCH SCRIPT
String fetchScript = "function fetch()"
+ "{if(count < items.size()){"
+ "row = items.get(count).getTotal();"
+ "row = items.get(count).getEnvFrom();"
+ "count++;"
+ "return true;}"
+ "return false;}";
//SET THE SCRIPT
cwaBar.setScript(beforeOpenScript + openScript + fetchScript);
JasonW
open and fetch scripts do not exist for the chart only BIRT reports.
So
cwaBar.setScript
will not do anything with them. Your beforeOpen script is really a beforeGeneration script which does exist for the chart engine.
Jason
cgswtsu78
Ok, thanks. One more question...
How do you change from a 2D chart to 3D? I've tried the below (its what works for 2D to 2D with depth, but get the below exception). Is there a better place to find answers like these?
Attempted code:
ChartWithAxes cwaBar = ChartWithAxesImpl.create();
cwaBar.setDimension(ChartDimension.THREE_DIMENSIONAL_LITERAL);
Exception:
javax.servlet.ServletException: org.eclipse.birt.chart.exception.ChartException
DynamicChart.doGet(DynamicChart.java:65)
javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.eclipse.birt.chart.exception.ChartException
org.eclipse.birt.chart.factory.Generator.build(Generator.java:998)
ChartEngineNoOSGi.buildChart(ChartEngineNoOSGi.java:132)
DynamicChart.doGet(DynamicChart.java:58)
javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
java.lang.NullPointerException
org.eclipse.birt.chart.computation.withaxes.PlotWithAxes.validateAxis(PlotWithAxes.java:310)
org.eclipse.birt.chart.computation.withaxes.PlotWith3DAxes.buildAxes(PlotWith3DAxes.java:1519)
org.eclipse.birt.chart.computation.withaxes.PlotWith3DAxes.<init>(PlotWith3DAxes.java:104)
org.eclipse.birt.chart.factory.Generator.build(Generator.java:985)
ChartEngineNoOSGi.buildChart(ChartEngineNoOSGi.java:132)
DynamicChart.doGet(DynamicChart.java:58)
javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
JasonW
In 3d you have to set up a z axis. Take a look at this example:
public static final Chart createBar( )
{
ChartWithAxes cwaBar = ChartWithAxesImpl.create( );
cwaBar.setDimension( ChartDimension.THREE_DIMENSIONAL_LITERAL );
cwaBar.setType( "Bar Chart" ); //$NON-NLS-1$
cwaBar.setSubType( "Side-by-side" ); //$NON-NLS-1$
// Plot
cwaBar.getBlock( ).setBackground( ColorDefinitionImpl.WHITE( ) );
cwaBar.getBlock( ).getOutline( ).setVisible( true );
// Title
cwaBar.getTitle( ).getLabel( ).getCaption( ).setValue( "3D Bar Chart" );//$NON-NLS-1$
// Legend
cwaBar.getLegend( ).setItemType( LegendItemType.CATEGORIES_LITERAL );
// X-Axis
Axis xAxisPrimary = cwaBar.getPrimaryBaseAxes( )[0];
xAxisPrimary.setType( AxisType.TEXT_LITERAL );
xAxisPrimary.getMajorGrid( ).setTickStyle( TickStyle.BELOW_LITERAL );
xAxisPrimary.getOrigin( ).setType( IntersectionType.MIN_LITERAL );
xAxisPrimary.getLabel( ).getCaption( ).getFont( ).setRotation( 90 );
// Y-Axis
Axis yAxisPrimary = cwaBar.getPrimaryOrthogonalAxis( xAxisPrimary );
yAxisPrimary.getMajorGrid( ).setTickStyle( TickStyle.LEFT_LITERAL );
yAxisPrimary.setType( AxisType.LINEAR_LITERAL );
//yAxisPrimary.getLabel( ).getCaption( ).getFont( ).setRotation( 90 );
// Z-Axis
Axis zAxis = AxisImpl.create( Axis.ANCILLARY_BASE );
zAxis.setType( AxisType.TEXT_LITERAL );
zAxis.setLabelPosition( Position.BELOW_LITERAL );
zAxis.setTitlePosition( Position.BELOW_LITERAL );
zAxis.getMajorGrid( ).setTickStyle( TickStyle.BELOW_LITERAL );
zAxis.setOrientation( Orientation.HORIZONTAL_LITERAL );
xAxisPrimary.getAncillaryAxes( ).add( zAxis );
// 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
} );
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( categoryValues );
SeriesDefinition sdX = SeriesDefinitionImpl.create( );
sdX.getSeriesPalette( ).shift( 0, 10 );
xAxisPrimary.getSeriesDefinitions( ).add( sdX );
sdX.getSeries( ).add( seCategory );
// Y-Series (1)
BarSeries bs1 = (BarSeries) BarSeriesImpl.create( );
bs1.setDataSet( orthoValues1 );
bs1.getLabel( ).setVisible( false );
bs1.setLabelPosition( Position.OUTSIDE_LITERAL );
bs1.setTranslucent(true);
Trigger tr1 = TriggerImpl.create(TriggerCondition.ONMOUSEOVER_LITERAL, ActionImpl.create(ActionType.SHOW_TOOLTIP_LITERAL, TooltipValueImpl.create(10, null)));
bs1.getTriggers().add(tr1);
// Y-Series (2)
BarSeries bs2 = (BarSeries) BarSeriesImpl.create( );
bs2.setDataSet( orthoValues2 );
bs2.getLabel( ).setVisible( false );
bs2.setLabelPosition( Position.OUTSIDE_LITERAL );
bs2.setTranslucent(true);
SeriesDefinition sdY = SeriesDefinitionImpl.create( );
yAxisPrimary.getSeriesDefinitions( ).add( sdY );
sdY.getSeries( ).add( bs1 );
sdY.getSeries( ).add( bs2 );
// Z-Series
SeriesDefinition sdZ = SeriesDefinitionImpl.create( );
zAxis.getSeriesDefinitions( ).add( sdZ );
// Rotate the chart
cwaBar.setRotation( Rotation3DImpl.create( new Angle3D[]{
Angle3DImpl.create( -10, 25, 0 )
} ) );
updateDataSet( cwaBar );
return cwaBar;
}
cgswtsu78
Jason,
I've reviewed the forums and wiki and I don't see anything that clearly defines how to setup a maven project deployment (what repositories and dependencies) for the chart engine api. Do you have any example pom.xmls or know of a documented approach?
Thanks,
Colin
cgswtsu78
Jason,
I have a question about the ChartEngineNoOSGI.buildChart method of the ChartWebWiz example.
It looks like the IDeviceRenderer and IGenerator classes are doing the work to write the image to the image path specified. I want to return a File object from the ChartEngineNoOSGI.buildChart that contains the acutal image without doing a lookup to retrieve the file. Is there anyway to us the IDeviceRenderer to store an image in Java memory so that I can return it to my rest web service api and push it to the browser that way?
cgswtsu78
Jason,
Why wouldn't the below work with your ChartWebWiz project? I don't want to store the image and would rather stream it straight to the browser. Is that possible with Birt's Chart Engine API? The rest of the code (the img construction) is as is, I just appended this at the end. When I create my own bufferedImage it streams out to the browser. I just want to make sure this isn't a limitation of Birt as we don't want to persist our chart images.
resp.setContentType("image/png");
OutputStream os = resp.getOutputStream();
ImageIO.write(img, "png", os);
os.close();
JasonW
That should work. With problem are you having?
cgswtsu78
A blank image (set to the appropriate weidth/height) gets displayed in the browser without the chart contents. The image file with the chart contents still gets pushed to the /images directory in tomcat, but the BufferedImage (img variable) is not streamed out with the chart. Below is the code I'm trying to execute...any ideas?
cm = ChartEngineNoOSGi.createStackedBar(parameters, env);
BufferedImage img = new BufferedImage(600, 600,
BufferedImage.TYPE_INT_ARGB);
Graphics g = img.createGraphics();
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);
long lg =System.currentTimeMillis();
String imgPth = sc.getRealPath("/images") + "/standalone" + lg +".png";
//You will need to cleanup the images
dRenderer.setProperty(IDeviceRenderer.FILE_IDENTIFIER, imgPth); //$NON-NLS-1$
//Set the bounds for the entire chart
double width = Double.parseDouble((String) parameters.get("width"));
double height = Double.parseDouble((String) parameters.get("height"));
Bounds bo = BoundsImpl.create(0, 0, width, height);
bo.scale(72d / dRenderer.getDisplayServer().getDpiResolution());
gcs = gr.build(dServer, cm, bo, null, null, null);
dRenderer.setProperty(IDeviceRenderer.UPDATE_NOTIFIER,
new EmptyUpdateNotifier(cm, gcs.getChartModel()));
gr.render(dRenderer, gcs);
dRenderer.setProperty(IDeviceRenderer.FILE_IDENTIFIER, "chart.png");
gr.render(dRenderer, gcs);
String im = ((IImageMapEmitter) dRenderer).getImageMap();
String src = "images/standalone" + lg + ".png";
resp.setContentType("image/png");
OutputStream os1 = resp.getOutputStream();
ImageIO.write(img, "png", os1);
os1.close();
JasonW
Comment out the file_identifier line. Take a look at this:
public void doGet( HttpServletRequest request, HttpServletResponse response )
throws ServletException, IOException
{
HttpSession session = request.getSession( false );
if ( session == null )
{
response.sendRedirect( "
http://localhost:8080/error.html"
; ); //$NON-NLS-1$
}
// load Chart model
chart = ChartModels.loadChart( this.getServletContext() );
// retrieve request parameters
retrieveParameters( request );
// Set the Content-Type header for the image output
response.setHeader( "Cache-Control", "no-store" ); //$NON-NLS-1$//$NON-NLS-2$
response.setDateHeader( "Expires", 0 ); //$NON-NLS-1$
response.setContentType( "image/png" ); //$NON-NLS-1$
RunTimeContext context;
try {
// Set scripting into model
setScript( );
// Prepare Could just use new RuntimeContext
context = Generator.instance().prepare(chart, null, null,
ULocale.getDefault());
// Bind Data
ChartModels.bindData(chart, context);
// Render
createImage((OutputStream) response.getOutputStream());
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private void createImage( OutputStream out )
{
// Create a buffered image
BufferedImage image = new BufferedImage( 600,
400,
BufferedImage.TYPE_INT_RGB );
// Draw the chart in the buffered image
Graphics2D g2d = (Graphics2D) image.getGraphics( );
idr.setProperty( IDeviceRenderer.GRAPHICS_CONTEXT, g2d );
Bounds bo = BoundsImpl.create( 0, 0, 600, 400 );
// convert pixels to points (1 inch = 72 points = dpi pixels )
// 1 pixel = 72/dpi points
bo.scale( 72d / idr.getDisplayServer( ).getDpiResolution( ) );
IGenerator gr = ce.getGenerator();
try
{
GeneratedChartState gcs =
gr.build( idr.getDisplayServer( ),
chart,
bo,
null,
null,
null );
gr.render( idr, gcs ); // Style processor
}
catch ( ChartException ex )
{
ex.printStackTrace( );
}
g2d.dispose( );
// Output the image
try
{
ImageIO.write( image, "PNG", out ); //$NON-NLS-1$
}
catch ( IOException io )
{
io.printStackTrace( );
}
}
cgswtsu78
I tried your suggestions and the image just comes out all black. I even took your suggested changes into your DynamicChart, ChartEngineNoOSGI classes and got the same result....am I missing something?