1

I am trying to make election map so I can draw chart and label with same chart color. So I have six election zone and running candidates may be up-to six or less. So if some election zone might have only two candidates so it should label only 2 not the empty value. Labeling should be stacked and should match with the color code of the charts. Here is my code which worked if all the column has value. On candidate 4 which has only 4 won,t label it. All the document is attached.

def FindLabel ( [Sheet1$.Candiate1], [Sheet1$.Candiate2], [Sheet1$.Candiate3], [Sheet1$.Candiate4], [Sheet1$.Candiate5], [Sheet1$.Candiate6], [Sheet1$.VoteCount1],[Sheet1$.VoteCount2],[Sheet1$.VoteCount3],[Sheet1$.VoteCount4],[Sheet1$.VoteCount5],[Sheet1$.VoteCount6] ):

if [Sheet1$.VoteCount1]> 0: [Sheet1$.Candiate1]= [Sheet1$.Candiate1]+" Vote Count= "+Sheet1$.VoteCount1]

if [Sheet1$.VoteCount2]> 0: [Sheet1$.Candiate2]= [Sheet1$.Candiate2]+" Vote Count= "+sheet1$.VoteCount2]

return "" +[Sheet1$.Candiate1]+"" +'\n'+""+[Sheet1$.Candiate2]+ ""enter image description here enter image description here

PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Jul 21, 2017 at 22:09

1 Answer 1

1

It's a little unclear what you're asking, but if you're looking for labels to include all candidates with non-zero vote counts, something like this should work.

def FindLabel ( [Sheet1$.Candiate1], [Sheet1$.Candiate2], [Sheet1$.Candiate3], [Sheet1$.Candiate4], [Sheet1$.Candiate5], [Sheet1$.Candiate6], [Sheet1$.VoteCount1],[Sheet1$.VoteCount2],[Sheet1$.VoteCount3],[Sheet1$.VoteCount4],[Sheet1$.VoteCount5],[Sheet1$.VoteCount6] ):
 results = []
 if [Sheet1$.VoteCount1] > 0:
 results.append('{} Vote Count = {}'.format([Sheet1$.Candiate1], [Sheet1$.VoteCount1]))
 if [Sheet1$.VoteCount2] > 0:
 results.append('{} Vote Count = {}'.format([Sheet1$.Candiate2], [Sheet1$.VoteCount2]))
 if [Sheet1$.VoteCount3] > 0:
 results.append('{} Vote Count = {}'.format([Sheet1$.Candiate3], [Sheet1$.VoteCount3]))
 if [Sheet1$.VoteCount4] > 0:
 results.append('{} Vote Count = {}'.format([Sheet1$.Candiate4], [Sheet1$.VoteCount4]))
 if [Sheet1$.VoteCount5] > 0:
 results.append('{} Vote Count = {}'.format([Sheet1$.Candiate5], [Sheet1$.VoteCount5]))
 if [Sheet1$.VoteCount6] > 0:
 results.append('{} Vote Count = {}'.format([Sheet1$.Candiate6], [Sheet1$.VoteCount6]))
 return '\n'.join(results)

There are neater ways to do it, but hopefully this will do the job!

answered Aug 1, 2017 at 8:55

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.