Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Show Graph Labels as Percent

 
Steve Dyke
Ranch Hand
Posts: 1679
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not sure what the issue is.
 
Steve Dyke
Ranch Hand
Posts: 1679
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1679
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic