Last active
August 13, 2018 22:55
-
-
Save andrewxhill/9136810 to your computer and use it in GitHub Desktop.
Torque plus 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>Torque plus Radar Chart</title> | |
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" /> | |
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/> | |
<link rel="shortcut icon" href="http://cartodb.com/assets/favicon.ico" /> | |
<script src="http://www.chartjs.org/assets/Chart.js"></script> | |
<script src="http://libs.cartocdn.com/cartodb.js/v3/cartodb.js"></script> | |
<style> | |
html, body, #map { | |
height: 100%; | |
padding: 0; | |
margin: 0; | |
} | |
#chartjs{ | |
position: absolute; | |
bottom: 0; | |
right: 0; | |
z-index: 111111; | |
width: 350px; | |
height: 350px; | |
} | |
</style> | |
<link rel="stylesheet" href="http://libs.cartocdn.com/cartodb.js/v3/themes/css/cartodb.css" /> | |
<!--[if lte IE 8]> | |
<link rel="stylesheet" href="http://libs.cartocdn.com/cartodb.js/v3/themes/css/cartodb.ie.css" /> | |
<![endif]--> | |
</head> | |
<body> | |
<div id="map"></div> | |
<canvas id="chartjs" height="350" width="350"></canvas> | |
<script> | |
function main() { | |
var map = new L.Map('map', { | |
zoomControl: false, | |
center: [37, -91], | |
zoom: 5 | |
}); | |
L.tileLayer('http://tile.stamen.com/toner/{z}/{x}/{y}.png', { | |
attribution: 'Stamen' | |
}).addTo(map); | |
cartodb.createLayer(map, { | |
type: "torque", | |
order: 1, | |
options: { | |
query: null, | |
table_name: "us_fires_2012", | |
user_name: "andrew", | |
tile_style: '/** torque visualization */ Map { -torque-frame-count:128; -torque-animation-duration:10; -torque-time-attribute:"date"; -torque-aggregation-function:"count(cartodb_id)"; -torque-resolution:2; -torque-data-aggregation:linear; } #us_fires_2012{ comp-op: lighter; marker-opacity: 0.9; marker-line-color: #FFF; marker-line-width: 0; marker-line-opacity: 1; marker-type: ellipse; marker-width: 6; marker-fill: #FF9900; } #us_fires_2012[frame-offset=1] { marker-width:8; marker-opacity:0.45; } #us_fires_2012[frame-offset=2] { marker-width:10; marker-opacity:0.225; } #us_fires_2012[frame-offset=3] { marker-width:12; marker-opacity:0.15; } #us_fires_2012[frame-offset=4] { marker-width:14; marker-opacity:0.1125; }' | |
} | |
}).done(function(layer) { | |
map.addLayer(layer); | |
// start chart.js stuff | |
var sql = cartodb.SQL({ user: 'andrew' }); | |
sql.execute("SELECT date_part('Month', f.date) as month, count(*) total FROM us_fires_2012 f GROUP BY date_part('Month', f.date) ORDER BY date_part('Month', f.date) ASC").done(function(data) { | |
var fires = []; | |
for (i in data.rows){ | |
fires.push(data.rows[i].total) | |
} | |
var radarChartData = { | |
labels : ["January","February","March","April","May","June","July", "August", "September", "October", "November", "December"], | |
datasets : [ | |
{ | |
fillColor : "rgba(111,255,123,0.7)", | |
strokeColor : "rgba(0,0,0,0.2)", | |
pointColor : "rgba(111,111,111,0.2)", | |
pointStrokeColor : "#444", | |
data : fires | |
} | |
] | |
} | |
var myRadar = new Chart(document.getElementById("chartjs").getContext("2d")).Radar(radarChartData,{scaleShowLabels : false, pointLabelFontSize : 10, pointLabelFontColor : "#fff", pointLabelBackdropColor : "rgba(0,0,0,0.75)", scaleLineColor : "rgba(255,255,255,.4)",angleLineColor : "rgba(255,255,255,0.3)",}); | |
}); | |
// end chart.js stuff | |
}); | |
} | |
// you could use $(window).load(main); | |
window.onload = main; | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment