views:

47

answers:

1

Hi folks,

I'm using the gchart php wrapper from http://code.google.com/p/gchartphp/. This is a question for anyone out there using it.

Can you visibly display the values that make up slices of a pie chart?

<?php
$piChart = new gPieChart();
$piChart->setDimensions(650,300);
$piChart->addDataSet(array_values($type));
$piChart->setLabels(array_keys($type));
$piChart->setColors(array("F26134", "F1F1F1","FFC7A8","E6E6E6","171717"));
$piChart->setTitle("All Tickets by Issue Type");
?>

<img src="<?php print $piChart->getUrl();  ?>" /> 

Is it possible that for each slice it shows this sort of format - "label (15)"

Thanks!

Jonesy

+1  A: 

You can always modify your labels so that they fit in the format you want. For example, this will format your label into the format "Name (Value)" :

<?php
function formatLabel(&$item, $key, $arr) {
    $item = $item . ' (' . $arr[$item] . ')';
}

$keys = array_keys($type);
array_walk($keys, 'formatLabel', $type);

$piChart = new gPieChart();
$piChart->setDimensions(650,300);
$piChart->addDataSet(array_values($type));
$piChart->setLabels($keys);
$piChart->setColors(array("F26134", "F1F1F1","FFC7A8","E6E6E6","171717"));
$piChart->setTitle("All Tickets by Issue Type");
?>
HoLyVieR
fantastic! I just didn't think about doing it that way! it gives me much more flexibility too! thanks!
iamjonesy
It seems like you just didn't think to award the answer either. Just trying to help here (honestly), you might find people less willing to help in future. It costs you nothing to accept his answer and would up your acceptance rate from its current 79%. Just sayin'
Mawg