// Load the Visualization API and the piechart package. google.load('visualization', '1.0', {'packages':['corechart']});
// Set a callback to run when the Google Visualization API is loaded. google.setOnLoadCallback(drawChart);
function drawChart() { // Create and populate the data table. var data = new google.visualization.DataTable(); data.addColumn('number', 'g'); data.addColumn('number', 'Royal Mail (UK)'); data.addColumn('number', 'USPS (USA)');
data.addRows([ [0,0.76,null], [10,0.76,null], [10,1.1,null], [20,1.1,null], [20,1.65,null], [40,1.65,null], [40,2.07,null], [60,2.07,null], [60,2.51,null], [80,2.51,null], [80,3.19,null], [100,3.19,null], [0,null,0.66], [28.3495,null,0.66], [28.3495,null,1.21], [56.699,null,1.21], [56.699,null,1.75], [85.0485,null,1.75], [85.0485,null,2.30], [99.22325,null,2.30] ]);
// Create and draw the visualization. var chart = new google.visualization.ScatterChart( document.getElementById('visualization')); chart.draw(data, {title: 'The cost to send a letter across the Atlantic', width: 600, height: 400, lineWidth: 3, pointSize: 0, colors: ['red','blue'], vAxis: {title: "Cost (GBP)", titleTextStyle: {color: "black"}}, hAxis: {title: "Mass of Letter (g)", titleTextStyle: {color: "black"}}} ); }
Did you know that it costs eleven pence more to send a postcard from the UK to the US than it does to send from the US to the UK, despite it travelling the exact same distance?
As interesting (or not) as that may be to you (and please feel free to discuss below), the purpose of this post is primarily to test the Google Chart API.
NB: USD prices were converted to GBP using an exchange rate of 0.6279 as retrieved from Google on 2nd March 2012. USPS pricing for letters is by ounces not grams and these were converted to equivalent grams for the purposes of the above comparison. All prices were retrieved from the official websites for each organisation.
Hmm Quite Interesting