JFreeChart - Server side (Servlet) Style Questions

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
untz
Posts: 5
Joined: Sat May 17, 2008 2:30 am

JFreeChart - Server side (Servlet) Style Questions

Post by untz » Sat May 17, 2008 2:39 am

Hello there,

I am using JFreeChart 1.0.9 on JDK 1.5.

Am new to JFreeChart and am generating charts as PNG images through Java Servlets...

Am wondering about the style capabilities...

Seems like everything works through the Java 2D package...

Question(s):

(1) Can I specify something like this:

- Graph Size=155px x 155px
- Background=FFFFFF
- Border=CCCCCC, 1px
- X/Y Axis Values=000000, Arial
- X/Y Axis Names=000000, Arial
- Bar Selection Color=478C3E
- Bar Default Color=999999
- No Title, No Legend

For the colors, I am hoping we can do 32 bit hex (HTML) colors with alpha. So FFFFFFFF would be 100% opaque white, 88FFFFFF would be 50% opaque white.

(2) Can I define graph colors in opacity? Meaning that I would choose a hex color and then vary data with 90%, 80%, etc.

(3) For fonts can I specify Helvetica, Times, and Courier?

Happy programming,

Unnsse

Taqua
JFreeReport Project Leader
Posts: 698
Joined: Fri Mar 14, 2003 3:34 pm
Contact:

Post by Taqua » Sat May 17, 2008 11:18 pm

The good news: You can do all the things you listed here.

The bad news: You have to code it all by yourself.

To convert a hex-number into a Color, use Color#decode(..). All colors used in JFreeChart can have an alpha-channel, but again, there is no automatic global property, you have to manually define it for each color you use.

Fonts in JFreeChart use the AWT-fonts, so assuming that Helvetica & co are installed on your system, then yes, you can use these fonts. But in Java, it is usually safer to use the logical fonts in Java (Serif, SansSerif, Monospaced) which then get mapped into their system-dependent counterparts (ie, Serif becomes Times on Unix, but Times New Roman on Windows).

untz
Posts: 5
Joined: Sat May 17, 2008 2:30 am

Post by untz » Tue May 20, 2008 5:20 am

Taqua,

Thanks for the response!

Some issue(s):

(1) For some odd reason, setting it to 0x88000000:

Code: Select all

renderer.setBaseItemLabelFont(new Font("SanSerif", Font.PLAIN, 5)); 
renderer.setBaseItemLabelPaint(Color.decode("0x88000000"));
breaks the image (shows only a "?" thumbnail image in Safari inside the generated image map, and doesn't display anything in Firefox)...

When I commented out the 2nd line, it worked and displayed the image on both browsers...

Also, it broke when I tried to set the domain and axis range colors to 0x88000000.

(2) Setting the Font to size 5 didn't seem to change the size from size 9?

Is it because the font size 9 is the minimum, which is typically the smallest
system font?

Is there a more straightforward way of changing the font size and / or color?

(3) How do set the image size in px?

Is this:

Code: Select all

ChartUtilities.writeChartAsPNG(out, chart, 155, 155);
The same as setting the image to:

155px X 155px ?

Happy programming,

Unnsse

Locked