Text Wrapping for long x-axis labels & Legend sorting in stacked charts

Comments

11 comments

  • Avatar
    Sean Bous

    Very nice!!

    0
    Comment actions Permalink
  • Avatar
    Jim Thomas

    This does not seem to work on non-stacked charts which is our current need.  See attached screen shot.




    ChartLabelNOwrap.png
    0
    Comment actions Permalink
  • Avatar
    Eli

    Hi Jim,

    What version are you using?

     

    0
    Comment actions Permalink
  • Avatar
    Jim Thomas

    5.7.0.161

    0
    Comment actions Permalink
  • Avatar
    Jim Thomas

    One other point is that we have multiple scripts applied:

    /*
    Welcome to your Widget's Script.

     - You can access your Widget via the 'widget' variable name.
     - You can access your Widget's DOM via the 'element' variable name (undefined until DOM creation).
     - You can access your Dashboard by accessing the 'dashboard' variable name.

     - For a complete API reference for Widgets and Dashboards go here: https://docs.google.com/document/d/1nQBZtWAdNFAd9nBhPWGVT3qOMS4Qm0PzBZVIzz5DfE8/

    /* This script sets the limit on the number of series displayed */
    widget.on('processresult', function(se,ev){
            se.style.dataLimits.seriesCapacity = 500;
    })
    /* 
    THIS SCRIPT SETS THE FONTS ON THE WIDGETS   */
    var events = [
     "beforequery",
     "beforewidgetindashboardmenu",
     "beforewidgetmenu",
     "buildquery",
     "destroyed",
     "initialized",
     "processresult",
     "queryend",
     "querystart",
     "readjust", 
     "ready",
     "refreshed",
     "render",
     "resizeend",
     "resizestart",
     "resizing",
     "widgetchanged"
    ];


    events.forEach(function(event) {
     widget.on(event, function(widget) {
      prism.sps.globals.widgetEventHandler(widget, element, event);
     }); 
    });
    /* 
    THIS SCRIPT SETS THE CHART LABEL SPACING  
    widget.on('render', function (widget) {
    widget.queryResult.xAxis.labels.maxCharactersPerLabel = 50;
    })*/
    /* 
    THIS SCRIPT SETS THE CHART AXIS TITLES   */
    events.forEach(function(event) {
                    widget.on(event, function(widget) {
                                    prism.sps.globals.widgetEventHandler(widget, element, event, '', '# or Count', 'Hours');
                    });         
    });


    //  THE NEXT TWO SCRIPTS WRAP LABEL TEXT
    //this part of the script will break the white spaces into breaks, for every other white space.
    widget.on('beforeviewloaded', function(widget, ev){ 
    var newmaxCharactersPerLabel = 100;
    ev.options.xAxis.labels.maxCharactersPerLabel = newmaxCharactersPerLabel;
    ev.options.xAxis.labels.useHTML = true;
    ev.options.xAxis.labels.formatter = function(){ 
    var text = this.value;
    var newText = "";
    var array = text.split(" ");
    for (i=0; i<array.length; i++) {
     if (i%2 == 1) {
      newText += array[i-1] + ' ' + array[i] + '';
     }

    0
    Comment actions Permalink
  • Avatar
    Simon

    This is useful, but can I request this be made as a standard feature? There seems to be text-wrapping and cut-off text issues all over the place (including the filters on the right). Please roadmap!

    2
    Comment actions Permalink
  • Avatar
    Arik

    For truncating labels for Pie charts  you can use the following script:

    widget.on("beforeviewloaded",function(widget,args){
    var maxCharNum = 5,
    originFormatter = args.options.plotOptions.pie.dataLabels.formatter;

    args.options.plotOptions.pie.dataLabels.formatter = function (){
    var value = originFormatter.call(this);

    if(value.length > maxCharNum){
    value = value.substring(0,4)+'...';
    }

    return value;
    }
    });

     

     

    1
    Comment actions Permalink
  • Avatar
    Chris Laughton

    Hi Arik,

    We have tried to use your script for truncating Pie Chart labels but it does not seem to work?

    Is there any other advice you can provide?

    Kind regards,

    1
    Comment actions Permalink
  • Avatar
    Yoni Lerner

    Hi Chris,

    Can you share the script you used?

     

    0
    Comment actions Permalink
  • Avatar
    Lisa H

    This is useful, but can I request this be made as a standard feature? There seems to be text-wrapping and cut-off text issues all over the place (including the filters on the right). Please roadmap!

    2
    Comment actions Permalink
  • Avatar
    Jessica Orlando

    Did anyone get the script working for truncating Pie Chart labels? The script above just cuts off the labels more than Sisense does.. 

    0
    Comment actions Permalink

Please sign in to leave a comment.