Sunday, 15 August 2010

javascript - Calculate the percentage and put it into a progressbar -



javascript - Calculate the percentage and put it into a progressbar -

hi have info world cup 2014, store if person has bet correctly on matches.

it looks (data in angularjs-controller):

$scope.users= [{ id: 1, name: 'jake', loss: 22, win: 10 }, { id: 2, name: 'bran', loss: 18, win: 14 }];

i calculate percentage of how many wins there have been. done if split total wins total matches, 18/(18+14) = 56% example. need info each user in json , calculate percentage of wins. later add together percentage progressbar each user in view:

<div class="progress progress-striped"> <div class="progress-bar progress-bar-success" role="progressbar" aria-valuenow="40" aria-valuemin="0" aria-valuemax="100" style="width: 40%"> <span class="sr-only">40% wins</span> </div>

how can accomplish ?

you this:

<div class="progress progress-striped" ng-repeat="user in users"> <div class="progress-bar progress-bar-success" role="progressbar" aria-valuenow="40" aria-valuemin="0" aria-valuemax="100" style="width: {{(user.win)/(user.win+user.loss)}}%"> <span class="sr-only">{{(user.win)/(user.win+user.loss)}}% wins</span> </div> </div>

javascript angularjs twitter-bootstrap

No comments:

Post a Comment