Revision [16663]

This is an old revision of BarGraph made by AqmSwn on 2007-05-31 10:32:26.

 

See also:

A Simple HTML-Based Bar Graph


This has only been tested on Win 2000 using IE 6 and Firefox 1.0.2.

The previous version of this action assumed the largest specified value was the 100% marker. This behavior has been removed in favor of explicitly setting a "total" value. This way 60% will actually look like 60%!

The Code


The following bar_graph class should be saved as 3rdparty/plugins/bar_graph.php --

%%(php)
<?php

if (!class_exists('bar_graph'))
{
class bar_graph
{
var $title;
var $total;
var $width;
var $class;
var $values = array();
function bar_graph($title = , $total = 0, $width = 250, $class = 'bar_graph')
{
$this->title = $title;
$this->total = $total;
$this->width = $width;
$this->class = $class;
}
function add($label, $n, $color = )
{
$this->values[] = array('label' => $label, 'n' => $n, 'color' => $color);
}
function show($show_numbers = true)
{
if (sizeof($this->values) > 0)
{
$colspan = 2 $show_numbers;
echo '<table class="' . $this->class . '" cellpadding="6" cellspacing="0" border="0">';
if (!empty($this->title)) echo "\n<tr><th class=\"title\" colspan=\"$colspan\">$this->title</th></tr>";
foreach ($this->values as $value)
{
$total = $this->total;
if (strpos($value['n'], '/')) list($n, $total) = split('/', $value['n']); else $n = $value['n'];
if ($total)
{
$normal = $n / $total;
$percent = round($normal * 100, 2);
$width = ceil($normal * $this->width);
$div_bar = ($percent > 20) ? "$percent%</div>" : "</div>
There are 8 comments on this page. [Show comments]
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki