Created
February 7, 2014 14:34
-
-
Save lamenath/8863660 to your computer and use it in GitHub Desktop.
visualizing second hand bikes average prices on leboncoin realtime
This file contains hidden or 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> | |
<head> | |
<meta name="description" content="Tataviiz"> | |
<meta name="keywords" content="dataviiz"> | |
<meta name="author" content="Nathanael Lamelliere"> | |
<meta charset="UTF-8"> | |
<link rel="stylesheet" type="text/css" href="dist/css/bootstrap.css"> | |
<script type="text/javascript" src="http://code.jquery.com/jquery-1.10.2.min.js"></script> | |
<script src="http://code.highcharts.com/highcharts.js"></script> | |
<script src="http://code.highcharts.com/modules/exporting.js"></script> | |
</head> | |
<body> | |
<script type="text/javascript"> | |
function kimonoCallback(data) { | |
// je transforme la collection d'objets en un tableau d'entier (prix) | |
var prices = data.results.collection1.map(function(item) { return parseInt(item.prix) || 0 }) | |
// je fais la somme des entiers du tableau ce qui me donne un entier | |
var sum = prices.reduce(function(prev, curr) { return prev + curr; }, 0) | |
// je mets l'attribut dans l'élément du DOM identifié par "nla" | |
$("#nla").attr("to", (sum / prices.length / 300)) | |
} | |
$.ajax({ | |
"url":"http://www.kimonolabs.com/api/2upbszfo?apikey=b91bac0f9820d9a83c6b829e3ea7086c&callback=kimonoCallback", | |
"crossDomain":true, | |
"dataType":"jsonp" | |
}) | |
</script> | |
</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment