How To Order The"Break By" Alphabetically In Widgets

Comments

17 comments

  • Avatar
    Brad

    I think it would be more helpful to know how to stack them in whatever fashion we want, or at least ascending/descending by the values in the chart.  Can you help with that?

  • Avatar
    Max

    Agree with Brad. This is one of the many elementary features that are missing from the software

  • Avatar
    Joseph Peters

    I agree with Brad and Max, the ability to drag the categories up and down to select the order can be crucial for some graphing views.

  • Avatar
    Hila Kantor

    In order to set the bar chart legend to be in order of the values, use the following code snippet:

    widget.on('processresult',function(se,ev){

    var series = ev.result.series; 
    var numberOfSeries = ev.result.series.length; 
    for(var i=0;i < numberOfSeries;i++){ 
    series[i].legendIndex = numberOfSeries - i; 

    })

  • Avatar
    John Wright

    To reverse the order that the series are graphed in use this:

    widget.on('processresult',function(se,ev) {
    var series = ev.result.series;
    series.reverse();
    })

    If you want to do it without modifying the order of the legend, add Hila's code:

    widget.on('processresult',function(se,ev) {
    var series = ev.result.series;
    series.reverse();

    var numberOfSeries = ev.result.series.length; 
    for(var i=0;i < numberOfSeries;i++){ 
    series[i].legendIndex = numberOfSeries - i; 

    })

    If you want to further modify the order, research javascript arrays. You should be able to move the series around within the ev.result.series array and get the results you want.

  • Avatar
    John Wright

    oops...forgot a } at the end.  The last line of the second code block should be }})

    Wish we could edit our comments on here :-/

  • Avatar
    Ido Darnell

    Thank you @John!

  • Avatar
    Simon

    Reviving this thread... I used the snippet

     

    widget.on('processresult',function(se,ev){

    var series = ev.result.series; 
    var numberOfSeries = ev.result.series.length; 
    for(var i=0;i < numberOfSeries;i++){ 
    series[i].legendIndex = numberOfSeries - i; 

    })

     

    but, this did not sort descending / ascending when the "Break By" feature is enabled on a column chart. It is still sorted in alphabetical order. I'm just curious - why would you disable the sort descending / ascending functionality when break by is enabled? It is like the chart in 5. in the original post above - but with more variance - it makes sense to have the option to sort descending.

  • Avatar
    Troy Griffin

    I agree with Simon - I need a descending sort by value. However, when the Break By feature is enabled, that option goes away...it should be retained.

    I have been using the code snippets above with no success. Still sorting alphabetically -

  • Avatar
    Aryeh Primus

    As an alternative, if you do not want to modify anything in the ElastiCube, you can do the entire thing in the widget's script.  Paste in the following code, and edit the "categories" array as explained in the comments.

     

    -------  COPY FROM BELOW THIS LINE ------

    // Edit the list of categories below.
    // The order in which the items appear is the order
    //   in which they will display in the stack.
     
    var categories = [ 'Apples', 'Oranges', 'Kiwis', 'Watermelon'];
     
    // ---------- DO NOT EDIT BELOW THIS LINE ----------
     
    var findIndex = function(txt) {
     return categories.indexOf(txt);
    };
     
    widget.on('processresult',function(se,ev){
     
     ev.result.series.sort(function(a,b){
      if (findIndex(a.name) < findIndex(b.name)) {
       return -1
      } else if (findIndex(a.name) > findIndex(b.name)) {
       return 1
      }
      return 0;
     });
    });

    -------  DO NOT COPY THIS LINE ------

     

  • Avatar
    James Walker

    Does anyone have an example of how to do this for the Pivot Widget on the Columns result?

  • Avatar
    Andrew Block

    Aryeh your script works great for a stacked chart.....can you tell me if there is a way to utilize that functionality to control the order on a pie chart?

  • Avatar
    Nick Burleigh

    I agree with Troy and Simon. I need to sort each column by value, so that the largest values are at the bottom of each column, and each segment gets smaller and smaller as you go up the column. Is there a way to adjust the above code snippets to accomplish this?

    I've been searching far and wide in the forums for an answer to this, and have yet to find it. Who can solve this mystery??

  • Avatar
    Nick Burleigh

    Andrew,

    A little late to the game here, but I figured out the following code for doing the same thing on pie charts (variation on Aryeh's code above):

    // Edit the list of categories below.
    // The order in which the items appear is the order
    // in which they will display in the stack.

    var categories = [ 'Apples','Oranges','Kiwis','Watermelon'];

    // ---------- DO NOT EDIT BELOW THIS LINE ---------- //

    var findIndex = function(txt) {
    return categories.indexOf(txt);
    };

    widget.on('processresult',function(se,ev){

    ev.result.series[0].data.sort(function(a,b){
    if (findIndex(a.name) < findIndex(b.name)) {
    return -1
    } else if (findIndex(a.name) > findIndex(b.name)) {
    return 1
    }
    return 0;
    });
    });

    Hope that helps,

    Nick

  • Avatar
    Adi Hecht

    With 7.02, It seems Arye's script is no longer working correctly.

    When the dashboard is first loaded, the break-by sections are not sorted.

    But then if you change anything on any dashboard filter -  then the sections become sorted correctly.

    After reloading the dashboard - the sorting is ignored again until a change is made in one of the dashboard filters.

     

    Does anyone have a fix for this?

  • Avatar
    Carl Larochelle

    Anyone?

  • Avatar
    Praveena Panigrahy

    Does anyone have a fix for this?

Please sign in to leave a comment.