I wanted to add some chart functionality and played with both the Charts and Google Chart API modules. The first module is a basic API for a few different charting systems, and the second one is a more in-depth API for Google only. "Charts" lacked things I wanted like being able to set the width of bars on bar graphs, so I went with the Google-only module.
The Google Chart API module also incorporates "map charts" that allows you to plot countries. This would be fun with some MARC or subject-heading data, but since we are a virtual reference service I decided to chart the number of times our librarians share a page from the CIA World Factbook, a resource we turn to when students are doing a "country report".

On this map it is a little hard to tell, but we've shared the page for Guyana more often than any other country.
In Drupal:
$chart = array( '#chart_id' => 'cia_world_factbook_map', '#type' => CHART_TYPE_MAP, '#countries' => array('AT','AU','AW','AZ','BE'), // really there were more '#georange' => world, '#data' => array(44,11,22,22,11), // again, lots more points '#data_colors' => array('eeeeee', 'eeee00', 'ff0000'), '#size' => chart_size(440,220), ); echo chart_render($chart)'
Breaking this into parts:
'#chart_id' => 'cia_world_factbook_map' - a unique id for you
'#type' => CHART_TYPE_MAP - a constant to define the map type
'#countries' => array('AT','AU','AW','AZ','BE') - an array of ISO country codes - I had to create a conversion table from the two-letter codes used in CIA World Factbook URLs.
'#georange' => world - the focus of the map
'#data' => array(44,11,22,22,11) - values, from 0 to 100 representing the value you want to represent; I had 9 different values and used multiples of 11.
'#data_colors' => array('eeeeee', 'eeee00', 'ff0000') - the first color is the default map color, and the second and third are the beginning and end of a color gradient. I used yellow to red. a data value of 1 would be yellow, and a data value of 100 would be red.
'#size' => chart_size(440,220) - The maximum size of a map chart to 440 x 220 pixels.
The module renders the image tag for the chart:
>img src="http://chart.apis.google.com/chart?chd=t%3A44%2C11%2C22%2C22%2C11%2C11%2C22%2C11%2C11%2C22%2C22%2C44%2C11%2C66%2C22%2C11%2C11%2C22%2C11%2C44%2C100%2C11%2C11%2C22%2C11%2C22%2C22%2C11%2C11%2C22%2C11%2C11%2C11%2C44%2C22%2C11%2C11%2C11%2C11%2C22%2C22%2C11%2C22%2C11%2C11%2C22%2C22%2C11%2C33%2C11%2C22&cht=t&chs=440x220&chco=eeeeee%2Ceeee00%2Cff0000&chf=&chld=ATAUAWAZBEBOBRCACCCGCLCNCOCUDEDODZEHESGBGFHTIDILINIRITJMJPKRLCMGMXNINLNZPEPKPRPTPYSDSTSVTGTHTWUAUSVNZM&chtm=world" id="chart-cia_world_factbook_map" class=" chart" />
So there isn't much magic here, but I found using the Google Chart API through Drupal was less daunting than without it.
| Attachment | Size |
|---|---|
| chart.png | 15.53 KB |
Comments
Post new comment