Where I put the clever stuff...
24 August 2008
Google let you dynamically generate charts and graphs using their Charts API. Last.fm (or more correctly Audioscrobbler) allow you to track your listening habits and then give access to the data via their web services.
This PHP class combines the two services and allows you to make charts showing your listening habits.
// include class
include 'lastfmChart.php';
// initiate a chart
$chart = new lastfmChart();
// choose a data source - there's a list at http://www.audioscrobbler.net/data/webservices/#User Profile Data
$chart->setDataFile('http://ws.audioscrobbler.com/1.0/user/mister-brown/weeklyartistchart.xml');
// set type of chart - 'pie' or 'bar' - defaults to pie
$chart->setType('pie');
// set the number of segments or bars - default is 15
$chart->setDataPoints('10');
// set the size of the output image
// defaults to 400x400 for bar, 550x200 for pie; max total number of pixels is 300,000
$chart->setSize('600x150');
// set a title for the chart
$chart->setTitle('Weekly Artist Shares');
// set a colour for the chart - defaults to yellow
$chart->setColors('0000FF');
// output the chart
$chart->doChart();
See some further examples of what is possible with this class.
Download the source for this class.
You are free to take this code, use it and modify it. I’m making no guarantees about the code though, and I wont be held responsible for any consequences of the use or misuse of it. You should read, understand and evaluate what the code does before you implement it yourself. You should also stick to the Google Chart API usage policy, the Audioscrobbler licence and any other applicable terms. If you do use this code, a link back to this page would be appreciated. Have fun!
Commenting is closed for this article.