Jump to content

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/137616-turning-an-array-into-a-bar-chart/
Share on other sites

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/

 

 

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.