Change Weekly formating "week x" to Date mm/dd/yyyy

Comments

2 comments

  • Avatar
    Yoni Lerner (Edited )

    For line chart you can use this script

    widget.on('processresult', function(widget, args ){
    var dates = args.result.xAxis.categories;
    var new_dates = [];
    dates.forEach(function(category){
    var new_date = new Date(category);
    new_date.setDate(new_date.getDate() - 3);
    new_date = (new_date.getMonth()+1) +'/'+ new_date.getDate()+ '/'+ new_date.getFullYear();
    new_dates.push(new_date)
    });
    args.result.xAxis.categories = new_dates;

    });
    0
    Comment actions Permalink
  • Avatar
    Max Bradley

    Using Yoni's script above is very helpful when customizing date formatting of the week. However, when you want to drill into Days, you will not want to apply the same formatting as this would adjust each day back by 3.

    Therefore, you can use the following extension of Yoni's script to enable drilling into Days from Weeks, while maintaining correct week formatting, without breaking the day specification:

    var convFlag; 
    var dateCol = 0; //set this to the index of the Date Field (i.e. column #1 is index 0)

    widget.on('processresult', function(se,ev){ 
    var dateType = ev.result.fields[dateCol].id; 
    if(dateType.includes('week')){ 
     
    convFlag = 1 

    else{ 

    convFlag = 0; 
    }

    });

    widget.on('ready', function(){

    if(convFlag == 1){ 
    $.each($("tbody .p-head-content span",element), function(){ 
    var span = this.textContent; 
    var new_date = new Date(span); 
    new_date.setDate(new_date.getDate() - 3) 
    new_date = (new_date.getMonth()+1) +'/'+ new_date.getDate()+ '/'+ new_date.getFullYear(); 
    this.textContent = new_date; 
    }); 

    });
    0
    Comment actions Permalink

Please sign in to leave a comment.