Results 1 to 4 of 4

Thread: Displaying Pie Chart Percentages

  1. #1
    Sencha User
    Join Date
    Jun 2012
    Posts
    14
    Answers
    2
    Vote Rating
    -1
      0  

    Default 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 - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    39,326
    Answers
    3884
    Vote Rating
    1297
      0  

    Default

    Have you tried using the iteminfo interaction? Check out the Pie example.
    Mitchell Simoens @LikelyMitch
    Sencha Inc, Senior Software Engineer
    ________________
    Learn BBCode and use it!

    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
    Answers
    2
    Vote Rating
    -1
      -1  

    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
      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

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •