extrovertive Posted December 18, 2008 Share Posted December 18, 2008 http://hccu.blogspot.com/2008/07/hccu-prepares-to-launch-its-first-debit.html How would I create a simple horizontal bar chart like the one above? Assuming I have an array like $results = array("Q01"=>12, "Q02"=>23....) What's the best way to create something like that? Any external tutorial? Quote Link to comment https://forums.phpfreaks.com/topic/137616-turning-an-array-into-a-bar-chart/ Share on other sites More sharing options...
ILMV Posted December 19, 2008 Share Posted December 19, 2008 Google Charts! The chart gets it data from the the variables you send in the url... Example chart url: http://chart.apis.google.com/chart?cht=bhs&chs=200x125&chd=s:ello&chco=4d89f9 Google Charts: http://code.google.com/apis/chart/ Quote Link to comment https://forums.phpfreaks.com/topic/137616-turning-an-array-into-a-bar-chart/#findComment-719318 Share on other sites More sharing options...
RussellReal Posted December 19, 2008 Share Posted December 19, 2008 lets say the numbers are all <? $array = array("giants" => 25,"packers" => 32,"cowboys" => 77,"vikings" => 82,"jets" => 92); $sum = array_sum($array); $i = 0; foreach ($array as $k => $v) { $i++; $a[$i][] = (($v / $sum) * 100); $a[$i][] = $k; } ?> biw after the for each loop, your $a array should hold [ 0 ] => percent [ 1 ] => name percent would be between 0 and 100 and then.. you just make 1 bar per $a index and give it the width of $a[index][0]px viola Quote Link to comment https://forums.phpfreaks.com/topic/137616-turning-an-array-into-a-bar-chart/#findComment-719321 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.