Magento Forum

   
Chart style poll
 
kullysupply
Member
 
Avatar
Total Posts:  48
Joined:  2008-08-05
 

I wanted my poll to have chart style bars like you see so often on various websites. It’s actually pretty easy to implement.

In the file template/poll/result.phtml:

<?php if(isset($poll)) : ?>
<div class="block block-poll">
    <
div class="block-title">
        <
h2><?php echo $this->__('Community Poll'?></h2>
    </
div>
    <
div class="block-content">
        <
h3><?php echo $poll->getPollTitle(); ?></h3>
        
<?php if( $poll_answers ): ?>
        
<ol>
            
<?php $_votecount 0 ?>
            <?php 
foreach( $poll_answers as $answer ): ?>
                
<li>
                    <
span class="answer"><?php echo $answer->getAnswerTitle() ?> (<?php echo round($answer->getPercent()) ?>%)</span>
                    <
hr align="left" color="red" width="<?php echo round((200/100)*$answer->getPercent()) ?>" size="4" />
                </
li>
                
<?php $_votecount += $answer->getVotesCount() ?>
            <?php 
endforeach; ?>
        
</ol>
        <
b><?php echo $_votecount ?></btotal votes
        <?php 
endif; ?>
    
</div>
</
div>
<?php endif; ?>

Now each answer has a bar below it representing the percentage of votes for that answer. I also added the total number of votes cast below the answers list.

Note that the number ‘200’ is the max width of the bar. So, if one answer has 100% of the votes, it will be 200 pixels wide. This number can be adjusted to fit your layout.

Also, some people have noticed that their poll suddenly disappears after voting. Here’s what I found:
http://www.magentocommerce.com/boards/viewthread/14407/

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
    Back to top