Skip to content

Value Formatting in Legend #934

Answered by JBirtQueen
JBirtQueen asked this question in Q&A
Discussion options

You must be logged in to vote

After an extensive amount of trial and error - here's what worked:

function beforeDrawLegendItem( lerh, bounds, icsc )
{
var curr = lerh.getValueLabel().getCaption().getValue()
var stri=curr.toString()
var str2=stri.replace(",","")
var nf = Number(str2).toFixed(2)
var nf2 = nf.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',')
var str = nf2
lerh.getValueLabel().getCaption().setValue(str);

}

The original value is a string object, so it has to be converted first to a string. Then replace the ',' because that stops it from becoming a number. Then put the "," back by using RegExp.

Thank you @claesrosell for the assist!

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
2 replies
@claesrosell
Comment options

@JBirtQueen
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by claesrosell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants