Jump to content

How can I adjust the font of the label of the bar?


flhs

Recommended Posts

Hi All

I'm using ireport to design a bar chart, I want to show the value above each bar, but the value of the tallest bar only can be displayed half, and if the value reach four digits, they will cover each other. I didn't find any parameter about it, who can help me?

The attachment is the issue pic.

 

Regards!

Samuel size=345]http://www.jasperforge.org/components/com_joomlaboard/uploaded/images/ireport1.GIF

Link to comment
Share on other sites

  • Replies 6
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

  • 2 weeks later...

I can set you in the right direction, but unfortunately I do not have a specific solution for you. JFreeChart is the chart engine used by JasperReports. iReport does not expose all the capabilities of JFreeChart yet, so you need to write a chart customizer class to get the functionality you need, specifically rendering the value labels differently.

These should get you started:

And just as an example, this is what I did to make the pie chart labels smaller (credits--I used this forum to get started--thanks to jmaher plus JasperSoft support).

Code:

Getting it to compile was my big problem--I'm not a Java programmer, and it took me a while to figure out my classpath (yours will be different, but the point is that you need to include the paths to the jars that are included in the class, in my example, jasperreports, jfreechart including jcommon. ):

[root@mycentos root]# CLASSPATH=$CLASSPATH:/opt/tomcat/webapps/jasperserver/WEB-INF/lib/jfreechart-1.0.1.jar:/opt/tomcat/webapps/jasperserver/WEB-INF/lib/jasperreports-ver:/opt/tomcat/webapps/jasperserver/WEB-INF/lib/jcommon-1.0.0.jar;.;export CLASSPATH

I've pretty much exhausted what I can tell you. Good luck!!!

Mary

Link to comment
Share on other sites

org.jfree.chart.renderer.category.BarRenderer.setBaseItemLabelFont(new Font("Arial",Font.BOLD,8))

 

thanks your reply ,but i find the method not exist.

 

could you please tell me how to use this method.

 

thanks very much

Link to comment
Share on other sites

You can not refer to the method setBaseItemLabelFont directly.

 

You need to get the render object using

 

BarRenderer renderer = (BarRenderer) chart.getCategoryPlot().getRenderer();

 

You can then apply the setBaseItemLabelFont method to the render object.

 

To get a better understanding you should look at the Jasper Reports API and JFreeChart API.

 

Jasper Reports API

 

http://jasperreports.sourceforge.net/api/index.html

 

JFreeChart API

http://www.jfree.org/jfreechart/api/javadoc/index.html

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...