Modifying the ‘Others’ Slice in the Pie Chart

Comments

3 comments

  • Avatar
    Jessica Orlando

    This is great, but is there a way to manually choose which values get grouped into 'Others' instead of the dynamic percentage?

    I have a client with a list of 6 values they want to see and everything else is grouped into Others. One of the values they want to see is Executive w/ only 0.43%, but they do not want to see Company or Accountant  so a percentage threshold will not work.

    0
    Comment actions Permalink
  • Avatar
    Elliott Herz (Edited )

    Hey Jessica,

    There are a few solutions that could work in this case. The easiest would be to create a new field in the backend that is either the name of one of the 6 required values, or will default to Others if not one of the 6. Then you can group off of that new field, and everything that is Others will get grouped there.

     

    Another option would be to add a widget script that goes through the series and starts regrouping the categories that are in other. First would be to leverage the plugin to make the minimum slice % 0. Then another widget script which would be something like this:

    var displayCategories = ["Andrew Green", "Ben Franklin", "Rahul Patel"];

    widget.on('processresult', (el, args) => {
    //args.result.series[0].data.push();
    var newSeries = Object.assign({}, args.result.series[0]);
    newSeries.data = [];
    var series = Object.assign({}, args.result.series[0]);
    var otherCategory = Object.assign({}, series.data[0]);
    otherCategory.queryResultIndex = series.data.length;
    otherCategory.sliced = false;
    otherCategory.x = series.data.length;
    otherCategory.name = 'Others';
    otherCategory.y = 0; //Temporarily store 0 as the value
    otherCategory.selectionData = {};
    otherCategory.color = 'black';
    otherCategory.content = [];
    otherCategory.drilldown = 'Others';

    var dataPoints = 0;
    series.data.forEach((item, index) => {
    if(displayCategories.indexOf(item.name) === -1) {
    otherCategory.y += item.y;
    otherCategory.selectionData[dataPoints] = item.name;
    otherCategory.content.push(item);
    dataPoints += 1;
    } else {
    newSeries.data.push(item);
    }
    });

    newSeries.data.push(otherCategory);
    args.result.series[0] = newSeries;
    });

    This is definitely a work in progress, but illustrates the idea that you can group things in any way you want.

     

    Hope this gives you a good framework for solving this usecase.

     

    Best, Elliott

    0
    Comment actions Permalink
  • Avatar
    Jessica Orlando

    Thanks Elliot. I ended up making a case statement field in the ElastiCube that groups the remaining fields under 'Other'.

    1
    Comment actions Permalink

Please sign in to leave a comment.