aspose file tools*
The moose likes Other Open Source Projects and the fly likes Show Graph Labels as Percent Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "Show Graph Labels as Percent" Watch "Show Graph Labels as Percent" New topic
Author

Show Graph Labels as Percent

Steve Dyke
Ranch Hand

Joined: Nov 16, 2004
Posts: 1446
    
    1
I have an XY line chart that I would like to display the series value labels(data points) as percent(75%, 45% etc.) I have everything working but the percent symbol.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Not sure what the issue is.
Steve Dyke
Ranch Hand

Joined: Nov 16, 2004
Posts: 1446
    
    1
David Newton wrote:Not sure what the issue is.


I think I have my problem narrowed down to the StandardXYItemLabelGenerator. I need help with the syntax of this method so it will format the labels to include a percent symbol.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

I'm still not sure what the actual problem you're having is.

If it's a printf-style format string then the percent character would need to be escaped so it isn't treated as a formatter prefix.
Steve Dyke
Ranch Hand

Joined: Nov 16, 2004
Posts: 1446
    
    1
David Newton wrote:I'm still not sure what the actual problem you're having is.

If it's a printf-style format string then the percent character would need to be escaped so it isn't treated as a formatter prefix.


I simply want to display the data point value labels in a percent format(like 75% etc). I can get the data point value label to display as 75 but I would prefer to have the percent symbol displayed with it. Again, I think the answer is in the StandardXYItemLabelGenerator call which has a method to define number formating. I just do not have the knowledge on how to set up the syntax of this method to define a percentage format.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41900
    
  63
It helps to know that this is about the JFreeChart library :-)

A look at the source code of the AbstractXYItemLabelGenerator class shows that the format string is used as the first parameter to a MessageFormat.format call, and that its default value is "{2}". The java.text.MessageFormat javadocs have much detail about how format strings are constructed, including -and that goes back to what David said- how to keep string literals in them.


Ping & DNS - my free Android networking tools app
 
jQuery in Action, 2nd edition
 
subject: Show Graph Labels as Percent