views:

46

answers:

2

Hi folks,

I'm trying to make a horizontal bar chart with data from an array

$values = implode(',', array_values($type));
$labels = implode('|', array_keys($type));
$img = "http://chart.apis.google.com/chart?cht=bhg&chs=600x300&chd=t:{$values}&chxt=x,y&chtt=Ticket+Types&chxl=1:{$labels}&chts=676767,21.5";
echo "<img src='{$img}' alt='Chart'>";

This isn't giving me what I want to achieve but I'm having a hard to fixing it. The code above gives me a horizontal bar chart with the y labels as the number of row (i.e. the first label is 1, the second label is 2) and incorrect x numbers.

I want the labels up the y axis and the values along the x.

Can someone give me a hand?

Jonesy

+4  A: 

Hi,

I was trying to do pretty much same thing, last week. This was driving me crazy. Check out this OpenSource project, this is PHP interface for google charts

http://code.google.com/p/gchartphp/

Check out these examples page, you will be able to recreate your chart under a minute... http://code.google.com/p/gchartphp/wiki/Examples

This will make it much easier to develop and maintain.

Alex
Awesome wrapper.. thanks.. +1 Only wish I saw this months ago
Mikey1980
this looks amazing Mikey! thanks a lot!
iamjonesy
have you tried using the map feature? I saw some mention of JSON/chof but can't find any examples
iamjonesy
map feature worked for me... try the code below.`<?php $map = new gMapChart(); $map->setZoomArea('usa'); $map->setStateCodes(array('FL', 'CA', 'TX', 'NY', 'UT', NV')); $map->addDataSet(array(500, 23, 32, 12, 54, 23)); ?><img src="<?php print $map->getUrl(); ?>" />`The chart is generated from php, you dont need JSON, just pass 1 dimentional array. Statecodes and datasets must have same # of elements, otherwise it does not work at all.
Alex
@Alex sorry I meant the interactive image map feature so that the user can click elemets of the chart
iamjonesy
unfortunately gchartphp is a wrapper for Image Charts. You need to look at Interactive Charts. Interactive charts are JS heavy and are much slower that Image Charts (3-5 seconds is normal, sometimes slower). You will have to invent your own wheel on this one... This will help you, http://code.google.com/apis/visualization/documentation/gallery/geomap.html. Look at events - "regionClick" and Configuration Options - "region"
Alex
A: 

I use GoogChart http://code.google.com/p/googchart/ and have modded it heavily to do what I need.

Mikey1980