cancel
Showing results for 
Search instead for 
Did you mean: 
intapiuser
Community Team Member
Community Team Member
In many databases,  the length in time of an action is stored as an integer. This allows for more analytic operations to be performed against the data, such as averages. However, we may want to present this information in a standard time format. (E.g. 72 seconds gets displayed as 1:12, 3795 seconds is 1:03:15). The script in the article converts the value labels and y-axis labels into this format.

Implementation

The code for this is in the attached file seconds_to_time.js, and its also been pasted below. We have instructions on how to add custom javascript here: https://docs.sisense.com/main/SisenseLinux/customizing-sisense-using-code.htm?Highlight=javascript
In the end, you should end up with this formatting:
The Code
widget.on("beforeviewloaded",function(w,args){
 
 function convertRawTime(num){
  var sign = num < 0 ? '-' : '';
  var hours = (parseInt( Math.abs(num) / 3600 )%24);
  var minutes = parseInt( Math.abs(num) / 60 )%60;
  var seconds = parseInt( Math.abs(num) % 60);
  
  var hoursText = hours < 10 ? "0" + hours : hours;
  var minutesText = minutes < 10 ? "0" + minutes : minutes;
  var secondsText = seconds < 10 ? "0" + seconds : seconds;
  if (hours==0){
   var secondsText = seconds < 10 ? "0" + seconds : seconds;
   return sign + minutes + ":" + secondsText
  } else {
   var hoursText = hours < 10 ? "0" + hours : hours;
   var minutesText = minutes < 10 ? "0" + minutes : minutes;
   var secondsText = seconds < 10 ? "0" + seconds : seconds;
   return sign + hoursText + ":" + minutesText + ":" + secondsText
  }
 };
 
 args.options.plotOptions.series.dataLabels.formatter = function(){
  return convertRawTime(this.y)
 }
 
 args.options.yAxis[0].labels.formatter = function(){
  return convertRawTime(this.value)
 }
})
Rate this article:
Version history
Last update:
‎02-07-2024 01:23 PM
Updated by: