Created
November 27, 2012 02:55
-
-
Save arfon/4152089 to your computer and use it in GitHub Desktop.
Rickshaw example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8" /> | |
<title>Spotty plots</title> | |
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script> | |
<script src="https://raw.github.com/shutterstock/rickshaw/master/vendor/d3.min.js"></script> | |
<script src="https://raw.github.com/shutterstock/rickshaw/master/rickshaw.min.js"></script> | |
<link type="text/css" rel="stylesheet" href="https://raw.github.com/shutterstock/rickshaw/master/rickshaw.min.css"> | |
</script> | |
</head> | |
<body> | |
<div id="chart_container"> | |
<div id="chart"></div> | |
</div> | |
<script> | |
var returnedData = {}; | |
new Rickshaw.Graph.JSONP({ | |
element: document.querySelector('#chart'), | |
dataURL: 'http://spot.arfon.org/instances/m1.small/us-east-1b', | |
renderer: 'line', | |
width: 580, | |
height: 250, | |
onData: function(data) { | |
$.each(data, function(i, item){ | |
// Initialise key if not present | |
if (!returnedData.hasOwnProperty(item.availability_zone)){ | |
returnedData[item.availability_zone] = []; | |
} | |
if(item.product_description == "Linux/UNIX"){ | |
$.each(item.pricing_history, function(date, price){ | |
returnedData[item.availability_zone].push({x: Date.parse(date), y: parseFloat(price)}); | |
}); | |
}; | |
}); | |
var returned = [{name: 'us-east-1b', data: returnedData['us-east-1b']}]; | |
console.log(returned); | |
return returned; | |
}, | |
onComplete: function(transport) { | |
// do something | |
} | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment