Setting X-axis category name (ex: month number to name)

Comments

4 comments

  • Official comment
    Avatar
    Camille Desrochers (Edited )

    Here's a more recent and tested Sisense Community post that achieves this: https://support.sisense.com/hc/en-us/community/posts/360023171814-Create-Widgets-with-Month-or-Day-names-by-the-correct-order

     

    Comment actions Permalink
  • Avatar
    Steve Ardis

    Thanks for posting this!  I did make a minor change that IMHO is a little cleaner: 

    var abbreviations = [ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' ];

    widget.on('processresult', function(se, ev) {
    var months = ev.result.xAxis.categories

    for (i = 0; i < months.length; i++) {
    months[i] = abbreviations[months[i] - 1];
    }
    });

    1
    Comment actions Permalink
  • Avatar
    Amit Kumar

    Hi Ido,

     

    In the line chart, i have a field of integer type and values are like- 201601,201602....201612.

    And to manipulate this field, I have written the below code:-

    widget.on('processresult',function (se, ev) {
    var month1 = ev.result.xAxis.categories;
    var month = month1%100;
    for(i=0;i<12;i++){

    if(month[i]==1){month[i]="JAN";i++;
    }
    if(month[i]==2){month[i]="FEB";i++;
    }
    if(month[i]==3){month[i]="MAR";i++;
    }
    if(month[i]==4){month[i]="APR";i++;
    }
    if(month[i]==5){month[i]="MAY";i++;
    }
    if(month[i]==6){month[i]="JUN";i++;
    }
    if(month[i]==7){month[i]="JUL";i++;
    }
    if(month[i]==8){month[i]="AUG";i++;
    }
    if(month[i]==9){month[i]="SEP";i++;
    }
    if(month[i]==10){month[i]="OCT";i++;
    }
    if(month[i]==11){month[i]="NOV";i++;
    }
    if(month[i]==12){month[i]="DEC";i++;
    }

    }});

    But, still there is no impact on the X axis values!!.

     

     

    0
    Comment actions Permalink
  • Avatar
    Amit Kumar

    Yes, I resolved it.

    Below code is working fine.

     

    Below query is also working fine.

    widget.on('processresult',function (se, ev) {
    var month = ev.result.xAxis.categories
    for(i=0;i<12;i++){
    var test=month[i].substr(0, 4);

    if(month[i]%100==7){month[i]="Jul "+test;i++;
    }

    if(month[i]%100==8){month[i]="Aug "+test;i++;
    }

    if(month[i]%100==9){month[i]="Sep "+test;i++;
    }


    if(month[i]%100==10){month[i]="Oct "+test;i++;
    }


    if(month[i]%100==11){month[i]="Nov "+test;i++;
    }


    if(month[i]%100==12){month[i]="Dec "+test;i++;
    }


    if(month[i]%100==1){month[i]="Jan "+test;i++;
    }


    if(month[i]%100==1){month[i]="Feb "+test;i++;
    }


    if(month[i]%100==3){month[i]="Mar "+test;i++;
    }


    if(month[i]%100==4){month[i]="Apr "+test;i++;
    }


    if(month[i]%100==5){month[i]="May "+test;i++;
    }


    if(month[i]%100==6){month[i]="Jun "+test;i++;
    }

    }})

    ;

     

    Regards,

    Ganesh

    0
    Comment actions Permalink

Please sign in to leave a comment.