1. #1
    Sencha User
    Join Date
    Jun 2012
    Posts
    14
    Vote Rating
    0
    Answers
    2
    jcorredor is on a distinguished road

      0  

    Default Unanswered: Displaying Pie Chart Percentages

    Unanswered: Displaying Pie Chart Percentages


    My question is simple. How do I display (or get the value of) the percentages of each item in a pie graph? (Doesn't matter if it happens on click or it displays them in labels on render). Is there a way of displaying percentages so that they dynamically change when an item disappears by clicking on the legend?

    I've read similar questions, but it seems like everyone just keeps saying, "just use renderer", which is fine and all but my problem isn't really displaying the percentage as much as it is getting the values themselves.

    Thanks.

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,547
    Vote Rating
    872
    Answers
    3566
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    Have you tried using the iteminfo interaction? Check out the Pie example.
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  3. #3
    Sencha User
    Join Date
    Jun 2012
    Posts
    14
    Vote Rating
    0
    Answers
    2
    jcorredor is on a distinguished road

      0  

    Default


    Quote Originally Posted by mitchellsimoens View Post
    Have you tried using the iteminfo interaction? Check out the Pie example.
    Thanks for you answer mitchellsimoens.

    I have used iteminfo as it is an excellent way of displaying information about the item. But, that is exactly my problem. I don't know how to GET the percentages in the first place. If I were to find the sum of the values stored and simply apply: (item value/ total sum) * 100%, it would simply give me the percentage of the item as long as all items are visible.

    However, when clicking on an item in the legend, the item now occupies a different percentage of the total as it becomes invisible. The iteminfo should take this into account and display a different percentage. How is this done?

    For example: I have a pie with... red:50%, yellow:25%, blue: 25%. Now I click on red in the legend... I should have yellow:50%, blue:50%. My question is, what function can I use or what Sencha field is available so that I may CALCULATE or GET the percentage dynamically?

  4. #4
    Sencha User
    Join Date
    May 2013
    Posts
    1
    Vote Rating
    0
    zomco is on a distinguished road

      0  

    Default


    label: {

    field: 'defectName',

    display: 'rotate',

    contrast: true,

    renderer: function(val, label, storeItem, item, i, display, animate, index){


    var labelsGroup = item.series.group;
    var vulnDefectTotal = 0;
    var vulnDefectSum = storeItem.get('vulnDefectSum');
    var labelsStore = storeItem.store;


    Ext.Array.each(labelsGroup.items, function(rec, indx){
    if(!rec._to.hidden){
    vulnDefectTotal += labelsStore.getAt(indx).get('vulnDefectSum');
    }
    });

    var ret = (parseFloat(vulnDefectSum / vulnDefectTotal) * 100.0).toFixed(2) + '%';
    return ret;
    }

    }

    I get 'hidden' from param 'item', which indicated label is hidden

Thread Participants: 2

Tags for this Thread