Last active
August 29, 2015 14:04
-
-
Save juanje/501b5118be28425faf1b to your computer and use it in GitHub Desktop.
Testing cartodb.js with Chart.js
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> | |
<head> | |
<title>Testing cartodb.js with Chart.js with some random data</title> | |
<script src="http://www.chartjs.org/assets/Chart.js"></script> | |
<meta name = "viewport" content = "initial-scale = 1, user-scalable = no"> | |
<script src="http://libs.cartocdn.com/cartodb.js/v3/cartodb.js"></script> | |
<style> | |
canvas{ | |
} | |
</style> | |
</head> | |
<body> | |
<canvas id="canvas" height="450" width="600"></canvas> | |
<script> | |
var sql = cartodb.SQL({ user: 'juanje' }); | |
sql.execute("SELECT date_part('Minute', c.begin) as min, count(*) total FROM cooper_test_30_april_2013 c group BY date_part('Minute', c.begin) ORDER BY date_part('Minute', c.begin) ASC").done(function(data) { | |
console.log(data) | |
var total = []; | |
var min = []; | |
for (i in data.rows){ | |
total.push(data.rows[i].total) | |
min.push(data.rows[i].min) | |
} | |
console.log(data) | |
var lineChartData = { | |
labels : ["January","February","March","April","May","June","July", "August", "September", "October", "November", "December"], | |
datasets : [ | |
{ | |
fillColor : "rgba(220,220,120,0.5)", | |
strokeColor : "rgba(220,220,120,1)", | |
pointColor : "rgba(220,220,120,1)", | |
pointStrokeColor : "#fff", | |
data : min | |
}, | |
{ | |
fillColor : "rgba(151,187,205,0.5)", | |
strokeColor : "rgba(151,187,205,1)", | |
pointColor : "rgba(151,187,205,1)", | |
pointStrokeColor : "#fff", | |
data : total | |
} | |
] | |
} | |
var myLine = new Chart(document.getElementById("canvas").getContext("2d")).Line(lineChartData); | |
}) | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment