Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
PUBLIC CLOUD
PRIVATE CLOUD
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
Expression js to change Series Labels
cdoniat
Hi everyone,
I would like to convert Value Data format in Series Labels (see attached picture) from unformatted values format to HH:mm values format. I looked for to add a javascript expression to do that. But I didn't find it. Is it a way to do it ? Another way ?
Thanks for your help in advance,
Christophe
Find more posts tagged with
Comments
mwilliams
You can do so in your chart script following the below format:
function beforeDrawDataPointLabel( dph, label, icsc )
{
temp = parseFloat(label.getCaption().getValue()); //grab label value in float form
*code* //format value using temp variable
label.getCaption().setValue(temp.toString()); //set label to new formatted value
}
Hope this helps.
cdoniat
Hi Michael,
Thanks a lots, you avoid me to lost time to find this way.
I share my code to convert 'Hours,decimals' to 'Hours:minutes' that could be useful for anyone:
function beforeDrawDataPointLabel( dph, label, icsc )
{
var temp = new String(label.getCaption().getValue()); //grab label value in string form
// format value using temp variable
var hrs = new String(temp.split(",")[0]);
var val_h = hrs + '';
var lh = val_h.length;
if (lh > 2) {
val_h = val_h.substr(0,2);
}
if (val_h < 10) {
val_h = "0" + val_h;
}
var mn = new String(temp.split(",")[1]);
var decminutes = parseFloat(mn);
var val_dec = decminutes + '';
var a = val_dec.length;
if (a < 4) { decminutes = decminutes*10; }
var minutes = Math.round((decminutes*0.6)/100);
var val_m = minutes + '';
var l = val_m.length;
if (l > 2) {
val_m = val_m.substr(0,2);
}
if (val_m < 10) {
val_m = "0" + val_m;
}
temp = val_h + ':' + val_m;
label.getCaption().setValue(temp.toString()); //set label to new formatted value
}
Ta,
Christophe.