Last active
January 30, 2016 20:52
-
-
Save bstancil/57434bec14b5e5966da8 to your computer and use it in GitHub Desktop.
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
<!--Load the AJAX API--> | |
<script type="text/javascript" src="https://www.google.com/jsapi"></script> | |
<script type="text/javascript"> | |
// Get the HTML body before calling google.load | |
var HTML = document.body.innerHTML; | |
// Load the Visualization API and the controls package. | |
google.load('visualization', '1.0', {'packages':['controls']}); | |
// Set a callback to run when the Google Visualization API is loaded. | |
setTimeout(function() { drawDashboard() }, 1000) | |
// Callback that creates and populates a data table, | |
// instantiates a dashboard, a range slider and a pie chart, | |
// passes in the data and draws it. | |
function drawDashboard() { | |
// Recreate body and write HTML back in | |
var body = document.createElement("body"); | |
document.documentElement.appendChild(body); | |
$(document.body).append(HTML) | |
// Create our data table. | |
var data = google.visualization.arrayToDataTable([ | |
['Name', 'Donuts eaten'], | |
['Michael' , 5], | |
['Elisa', 7], | |
['Robert', 3], | |
['John', 2], | |
['Jessica', 6], | |
['Aaron', 1], | |
['Margareth', 8] | |
]); | |
// Create a dashboard. | |
var dashboard = new google.visualization.Dashboard( | |
document.getElementById('dashboard_div')); | |
// Create a range slider, passing some options | |
var donutRangeSlider = new google.visualization.ControlWrapper({ | |
'controlType': 'NumberRangeFilter', | |
'containerId': 'filter_div', | |
'options': { | |
'filterColumnLabel': 'Donuts eaten' | |
} | |
}); | |
// Create a pie chart, passing some options | |
var pieChart = new google.visualization.ChartWrapper({ | |
'chartType': 'PieChart', | |
'containerId': 'chart_div', | |
'options': { | |
'width': 300, | |
'height': 300, | |
'pieSliceText': 'value', | |
'legend': 'right' | |
} | |
}); | |
// Establish dependencies, declaring that 'filter' drives 'pieChart', | |
// so that the pie chart will only display entries that are let through | |
// given the chosen slider range. | |
dashboard.bind(donutRangeSlider, pieChart); | |
// Draw the dashboard. | |
dashboard.draw(data); | |
} | |
</script> | |
<!--Div that will hold the dashboard--> | |
<div id="dashboard_div"> | |
<!--Divs that will hold each control and chart--> | |
<div id="filter_div"></div> | |
<div id="chart_div"></div> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment