Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » BIRT » How to render a chart (standalone)?
How to render a chart (standalone)? [message #85108] Fri, 28 October 2005 02:53 Go to next message
Eclipse UserFriend
Originally posted by: none.none.none

Hello,
I'm trying to use BIRT charting independent of a report. So, for example, I
have a web application that will generate a chart and render it to a PNG
image. Once I have the org.eclipse.birt.chart.model.Chart object, what do I
do?? I can't seem to even come close to figuring out how to turn this into
a viewable image.

Any ideas?

Thanks!
Re: How to render a chart (standalone)? [message #85141 is a reply to message #85108] Fri, 28 October 2005 08:11 Go to previous messageGo to next message
David Michonneau is currently offline David MichonneauFriend
Messages: 1145
Registered: July 2009
Senior Member
Hi,

Please check the existing chart engine API:
http://www.eclipse.org/birt/wiki/index.php?n=BPS.BPS39

Thanks,

David

"chris" <none@none.none> wrote in message
news:djs3qr$mvl$1@news.eclipse.org...
> Hello,
> I'm trying to use BIRT charting independent of a report. So, for example,
> I have a web application that will generate a chart and render it to a PNG
> image. Once I have the org.eclipse.birt.chart.model.Chart object, what do
> I do?? I can't seem to even come close to figuring out how to turn this
> into a viewable image.
>
> Any ideas?
>
> Thanks!
>
Re: How to render a chart (standalone)? [message #85327 is a reply to message #85141] Fri, 28 October 2005 16:05 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: none.none.none

Thanks David. I had actually not located that document. However, it looks
very similar to the examples given in the FAQ. Both of which show how to
render an image to a Swing or SWT device. I'm not familiar with either one
of those other than I believe you would only do that if you wanted to render
the chart in a desktop app. I need to render it to web/HTML client. I
still haven't seen anything about how to render it to a common image format
such as PNG, JPG, etc.
What am I missing?

"David Michonneau" <dmichonneau@actuate.com> wrote in message
news:djsmgb$aaj$1@news.eclipse.org...
> Hi,
>
> Please check the existing chart engine API:
> http://www.eclipse.org/birt/wiki/index.php?n=BPS.BPS39
>
> Thanks,
>
> David
Re: How to render a chart (standalone)? [message #85366 is a reply to message #85327] Fri, 28 October 2005 16:44 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: none.none.none

Actually, after a bit more searching I came across another useful document.
I haven't tested it out yet, but it looks like it has what I need here (so
far the most comprehensive doc I've seen on the chart engine)... It's a
little confusing because it's a FAQ Word document which I just assumed was
the same as the FAQ web page... but it's not.

Anyway, for those interested, it is located here:
http://eclipse.org/birt/faq/Charts_FAQ.doc

The relevant code I was looking for below....




IDeviceRenderer idr = null;

try {

idr = ps.getDevice("dv.PNG");

} catch (PluginException pex)

{

DefaultLoggerImpl.instance().log(pex);

}



// DEFINE THE BOUNDS AND CONVERT INTO POINTS

Bounds bo = BoundsImpl.create(0, 0, 800, 600); // IN PIXELS

bo.scale(72d/idr.getDisplayServer().getDpiResolution()); // CONVERTED TO
POINTS



// BUILD THE RENDERED CHART STRUCTURE

Generator gr = Generator.instance();

GeneratedChartState gcs = null;

try {

gcs = gr.build(

idr.getDisplayServer(),

cm, null,

bo, null

);

} catch (GenerationException gex)

{

DefaultLoggerImpl.instance().log(gex);

System.exit(0);

}



// RENDER THE CHART TO A PNG FILE

Image img = new BufferedImage(

(int) bo.getWidth(), (int) bo.getHeight(), BufferedImage.TYPE_INT_ARGB

);

idr.setProperty(IDeviceRenderer.FILE_IDENTIFIER, "chart.png");

try {

gr.render(idr, gcs);

} catch (RenderingException rex)

{

DefaultLoggerImpl.instance().log(rex);

}



"chris" <none@none.none> wrote in message
news:djti7j$hgg$1@news.eclipse.org...
> Thanks David. I had actually not located that document. However, it
> looks very similar to the examples given in the FAQ. Both of which show
> how to render an image to a Swing or SWT device. I'm not familiar with
> either one of those other than I believe you would only do that if you
> wanted to render the chart in a desktop app. I need to render it to
> web/HTML client. I still haven't seen anything about how to render it to
> a common image format such as PNG, JPG, etc.
> What am I missing?
>
Re: How to render a chart (standalone)? [message #85388 is a reply to message #85327] Fri, 28 October 2005 16:47 Go to previous messageGo to next message
David Michonneau is currently offline David MichonneauFriend
Messages: 1145
Registered: July 2009
Senior Member
Hi Chris,

Rendering in PNG or JPG is quite easy, simply use a PNG device renderer.
Then set the file path on the renderer:

File fChartImage = File.createTempFile( "chart.png");
IDeviceRenderer idr = PluginSettings.instance( ).getDevice( "dv.PNG" );
idr.setProperty( IDeviceRenderer.FILE_IDENTIFIER, fChartImage.getPath( ));

The file will be rendered at the specified path.

You can use all these device renderers, and even implement new ones if you
like:
dv.SWING
dv.SWT
dv.PNG
dv.GIF
dv.JPG
dv.BMP
dv.SVG

Hope this helps,

Thanks,

David

"chris" <none@none.none> wrote in message
news:djti7j$hgg$1@news.eclipse.org...
> Thanks David. I had actually not located that document. However, it
> looks very similar to the examples given in the FAQ. Both of which show
> how to render an image to a Swing or SWT device. I'm not familiar with
> either one of those other than I believe you would only do that if you
> wanted to render the chart in a desktop app. I need to render it to
> web/HTML client. I still haven't seen anything about how to render it to
> a common image format such as PNG, JPG, etc.
> What am I missing?
>
> "David Michonneau" <dmichonneau@actuate.com> wrote in message
> news:djsmgb$aaj$1@news.eclipse.org...
>> Hi,
>>
>> Please check the existing chart engine API:
>> http://www.eclipse.org/birt/wiki/index.php?n=BPS.BPS39
>>
>> Thanks,
>>
>> David
>
>
>
Re: How to render a chart (standalone)? [message #85400 is a reply to message #85388] Fri, 28 October 2005 16:54 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: none.none.none

Looks like we were both responding at the same time, when I had found that
other doc. You're right, it does look easy now ;) Thanks a bunch for your
help.

"David Michonneau" <dmichonneau@actuate.com> wrote in message
news:djtkno$l0q$1@news.eclipse.org...
> Hi Chris,
>
> Rendering in PNG or JPG is quite easy, simply use a PNG device renderer.
> Then set the file path on the renderer:
>
> File fChartImage = File.createTempFile( "chart.png");
> IDeviceRenderer idr = PluginSettings.instance( ).getDevice( "dv.PNG" );
> idr.setProperty( IDeviceRenderer.FILE_IDENTIFIER, fChartImage.getPath( ));
>
> The file will be rendered at the specified path.
>
> You can use all these device renderers, and even implement new ones if you
> like:
> dv.SWING
> dv.SWT
> dv.PNG
> dv.GIF
> dv.JPG
> dv.BMP
> dv.SVG
>
> Hope this helps,
>
> Thanks,
>
> David
Re: How to render a chart (standalone)? [message #85460 is a reply to message #85108] Fri, 28 October 2005 19:29 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: none.none.none

Sorry to keep dragging this thing out, I'm closer, but still not quite
there. So I've gotten over the hurdle of understanding, in general, how to
render an image through code. However, I think I'm still having a problem
with the 'standalone' part.

So here's how I'm trying to run this.. My IDE is Eclipse 3.1 using the
Tomcat plugin. I'm trying to generate a simple chart (createLineChart()
taken from samples) into a PNG. I am currently on 2.0 M1, but I also
initially tried the 1.0.1 standalone charting download. The code to
generate the chart and render it is in a servlet.

I've taken the brute-force approach to try to get this thing working. So,
in my web-inf directory (where I point BIRT_HOME), I have a plugins
directory with ALL of the Birt 2.0 plugins in there. In my Eclipse
build-path to get the servlet to compile, I have the following libs...

birt.core
device.extension
chart.engine

When running the code (at the bottom of this message) as-is, I get the
following error which occurs on the gr.build() call:
------------------------------------------------------------ ------------------
Oct 28, 2005 1:05:49 PM org.eclipse.birt.chart.log.impl.JavaUtilLoggerImpl
log

SEVERE: Exception

org.eclipse.birt.chart.exception.ChartException: $NO-RB$
org.eclipse.birt.chart.render.Line

at
org.eclipse.birt.chart.util.PluginSettings.newInstance(Plugi nSettings.java:595)

at
org.eclipse.birt.chart.util.PluginSettings.getRenderer(Plugi nSettings.java:306)

at
org.eclipse.birt.chart.render.BaseRenderer.instances(BaseRen derer.java:1537)

at org.eclipse.birt.chart.factory.Generator.build(Generator.jav a:239)



If I remove the "STANDALONE" property, then I get this error:

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

java.lang.VerifyError: Cannot inherit from final class

at java.lang.ClassLoader.defineClass1(Native Method)

at java.lang.ClassLoader.defineClass(Unknown Source)

at java.security.SecureClassLoader.defineClass(Unknown Source)

at java.net.URLClassLoader.defineClass(Unknown Source)

at java.net.URLClassLoader.access$100(Unknown Source)

at java.net.URLClassLoader$1.run(Unknown Source)

at java.security.AccessController.doPrivileged(Native Method)

at java.net.URLClassLoader.findClass(Unknown Source)

at
org.eclipse.birt.core.framework.server.PluginClassLoader.fin dLocalClass(PluginClassLoader.java:116)

at
org.eclipse.birt.core.framework.server.PluginClassLoader.fin dClass(PluginClassLoader.java:36)

at java.lang.ClassLoader.loadClass(Unknown Source)

at java.lang.ClassLoader.loadClass(Unknown Source)

at
org.eclipse.birt.core.framework.server.PluginClassLoader.loa dExportedClass(PluginClassLoader.java:98)

at
org.eclipse.birt.core.framework.server.PluginClassLoader.doL oadImportClass(PluginClassLoader.java:84)

at
org.eclipse.birt.core.framework.server.PluginClassLoader.loa dImportedClass(PluginClassLoader.java:54)

at
org.eclipse.birt.core.framework.server.PluginClassLoader.fin dClass(PluginClassLoader.java:30)









Code:

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

System.setProperty("STANDALONE", "true");
System.setProperty("BIRT_HOME",
"C:\\EclipseWorkspace\\Test\\web\\WEB-INF");
Chart chart = createLineChart();
PluginSettings ps = PluginSettings.instance();
IDeviceRenderer idr = null;
try
{
idr = ps.getDevice("dv.PNG");
} catch (ChartException e)
{
logger.error(e.getMessage(), e);
}

// DEFINE THE BOUNDS AND CONVERT INTO POINTS
Bounds bo = BoundsImpl.create(0, 0, 800, 600); // IN PIXELS
bo.scale(72d / idr.getDisplayServer().getDpiResolution()); // CONVERTED
// TO
// POINTS

// BUILD THE RENDERED CHART STRUCTURE
Generator gr = Generator.instance();
GeneratedChartState gcs = null;
try
{
gcs = gr.build(idr.getDisplayServer(), chart, null, bo, null);
} catch (ChartException e)
{
logger.error(e.getMessage(), e);
}
------------------------------------------------------------ ---------------------------


If I remove the STANDALONE and BIRT_HOME properties, then it says something
about not being able to find a plugins.xml and dv.PNG.

Any ideas?
Thanks
Re: How to render a chart (standalone)? [message #85695 is a reply to message #85460] Mon, 31 October 2005 13:22 Go to previous messageGo to next message
David Michonneau is currently offline David MichonneauFriend
Messages: 1145
Registered: July 2009
Senior Member
If you remove STANDALONE, you need to specify BIRT_HOME for the path to your
plugins parent directory.

For the exception, can you try to enable tracing on the chart engine plugin,
and see what exactly is the exception about in the log?

Thanks,

David

"chris" <none@none.none> wrote in message
news:djtu7b$248$1@news.eclipse.org...
>
> Sorry to keep dragging this thing out, I'm closer, but still not quite
> there. So I've gotten over the hurdle of understanding, in general, how
> to render an image through code. However, I think I'm still having a
> problem with the 'standalone' part.
>
> So here's how I'm trying to run this.. My IDE is Eclipse 3.1 using the
> Tomcat plugin. I'm trying to generate a simple chart (createLineChart()
> taken from samples) into a PNG. I am currently on 2.0 M1, but I also
> initially tried the 1.0.1 standalone charting download. The code to
> generate the chart and render it is in a servlet.
>
> I've taken the brute-force approach to try to get this thing working. So,
> in my web-inf directory (where I point BIRT_HOME), I have a plugins
> directory with ALL of the Birt 2.0 plugins in there. In my Eclipse
> build-path to get the servlet to compile, I have the following libs...
>
> birt.core
> device.extension
> chart.engine
>
> When running the code (at the bottom of this message) as-is, I get the
> following error which occurs on the gr.build() call:
> ------------------------------------------------------------ ------------------
> Oct 28, 2005 1:05:49 PM org.eclipse.birt.chart.log.impl.JavaUtilLoggerImpl
> log
>
> SEVERE: Exception
>
> org.eclipse.birt.chart.exception.ChartException: $NO-RB$
> org.eclipse.birt.chart.render.Line
>
> at
> org.eclipse.birt.chart.util.PluginSettings.newInstance(Plugi nSettings.java:595)
>
> at
> org.eclipse.birt.chart.util.PluginSettings.getRenderer(Plugi nSettings.java:306)
>
> at
> org.eclipse.birt.chart.render.BaseRenderer.instances(BaseRen derer.java:1537)
>
> at org.eclipse.birt.chart.factory.Generator.build(Generator.jav a:239)
>
>
>
> If I remove the "STANDALONE" property, then I get this error:
>
> ------------------------------------------------------------ -----------------
>
> java.lang.VerifyError: Cannot inherit from final class
>
> at java.lang.ClassLoader.defineClass1(Native Method)
>
> at java.lang.ClassLoader.defineClass(Unknown Source)
>
> at java.security.SecureClassLoader.defineClass(Unknown Source)
>
> at java.net.URLClassLoader.defineClass(Unknown Source)
>
> at java.net.URLClassLoader.access$100(Unknown Source)
>
> at java.net.URLClassLoader$1.run(Unknown Source)
>
> at java.security.AccessController.doPrivileged(Native Method)
>
> at java.net.URLClassLoader.findClass(Unknown Source)
>
> at
> org.eclipse.birt.core.framework.server.PluginClassLoader.fin dLocalClass(PluginClassLoader.java:116)
>
> at
> org.eclipse.birt.core.framework.server.PluginClassLoader.fin dClass(PluginClassLoader.java:36)
>
> at java.lang.ClassLoader.loadClass(Unknown Source)
>
> at java.lang.ClassLoader.loadClass(Unknown Source)
>
> at
> org.eclipse.birt.core.framework.server.PluginClassLoader.loa dExportedClass(PluginClassLoader.java:98)
>
> at
> org.eclipse.birt.core.framework.server.PluginClassLoader.doL oadImportClass(PluginClassLoader.java:84)
>
> at
> org.eclipse.birt.core.framework.server.PluginClassLoader.loa dImportedClass(PluginClassLoader.java:54)
>
> at
> org.eclipse.birt.core.framework.server.PluginClassLoader.fin dClass(PluginClassLoader.java:30)
>
>
>
>
>
>
>
>
>
> Code:
>
> ------------------------------------------------------------ -------------------------------------------------------
>
> System.setProperty("STANDALONE", "true");
> System.setProperty("BIRT_HOME",
> "C:\\EclipseWorkspace\\Test\\web\\WEB-INF");
> Chart chart = createLineChart();
> PluginSettings ps = PluginSettings.instance();
> IDeviceRenderer idr = null;
> try
> {
> idr = ps.getDevice("dv.PNG");
> } catch (ChartException e)
> {
> logger.error(e.getMessage(), e);
> }
>
> // DEFINE THE BOUNDS AND CONVERT INTO POINTS
> Bounds bo = BoundsImpl.create(0, 0, 800, 600); // IN PIXELS
> bo.scale(72d / idr.getDisplayServer().getDpiResolution()); // CONVERTED
> // TO
> // POINTS
>
> // BUILD THE RENDERED CHART STRUCTURE
> Generator gr = Generator.instance();
> GeneratedChartState gcs = null;
> try
> {
> gcs = gr.build(idr.getDisplayServer(), chart, null, bo, null);
> } catch (ChartException e)
> {
> logger.error(e.getMessage(), e);
> }
> ------------------------------------------------------------ ---------------------------
>
>
> If I remove the STANDALONE and BIRT_HOME properties, then it says
> something about not being able to find a plugins.xml and dv.PNG.
>
> Any ideas?
> Thanks
>
Re: How to render a chart (standalone)? [message #87234 is a reply to message #85695] Thu, 03 November 2005 20:15 Go to previous message
Eclipse UserFriend
Originally posted by: none.none.none

Magically started working after upgrading to M2.

"David Michonneau" <dmichonneau@actuate.com> wrote in message
news:dk55r1$8mp$1@news.eclipse.org...
> If you remove STANDALONE, you need to specify BIRT_HOME for the path to
> your plugins parent directory.
>
> For the exception, can you try to enable tracing on the chart engine
> plugin, and see what exactly is the exception about in the log?
>
> Thanks,
>
> David
Previous Topic:t
Next Topic:trim in select statement
Goto Forum:
  


Current Time: Mon Jul 08 14:29:15 GMT 2024

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

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

Back to the top