Value Formatting in Legend #934
-
I currently have a chart with Title X, Value 600, Title Y Value 700. I would like the legend to read Title X Value 600.00, Title Y Value 700.00, but can only find details on how to make values show as percent in legend. I have tried updating the formatting on the axis, replicating a script based on this eclipse thread https://www.eclipse.org/forums/index.php/t/204633/ and formatted the value in the data set. I'm guessing I need a script, but I cannot figure out what elements I need to call out for it. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
This is my script function beforeDrawLegendItem( lerh, bounds, icsc ) What comes up with this is 600###,###.00 which is not what I am looking for. I feel like I am very close to getting to the right thing for this... |
Beta Was this translation helpful? Give feedback.
-
After an extensive amount of trial and error - here's what worked: function beforeDrawLegendItem( lerh, bounds, icsc ) } 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! |
Beta Was this translation helpful? Give feedback.
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!