This is a recursive function I made to draw purely CSS bar graphs. You pass it an array of data and the total amount, example:
$someData = array('Oranges'=>4, 'Apples'=>10); $total = 14; echo drawCSSGraph($someData, $total);
Also, you can pass it options in the form of an array or as space separated couples, exa:
//perfectly fine echo drawCSSGraph($data, $total, 'height=20 width=300 color=#c0c0c0'); //works just as well $options = array('height'=>20, 'width'=>300, 'color'=>'#c0c0c0'); echo drawCSSGraph($data, $total, $options);
Also, you can put [var] in the label which will be parsed out when the graph is drawn
$data = array('Data1: [var]'=>20, 'Data2: [var]'=>19); echo drawCSSGraph($data, 39); ==> Data1: 20 [graph here] Data2: 19 [graph here]
It will detect whether you're making a vertical or horizontal bar graph and adjust accordingly. If you want it vertical just make the height greater than the width.