Skip to content

Instantly share code, notes, and snippets.

@revox
Last active November 1, 2018 10:06
Show Gist options
  • Save revox/3b3512d1c9361f7c1584 to your computer and use it in GitHub Desktop.
Save revox/3b3512d1c9361f7c1584 to your computer and use it in GitHub Desktop.
Google Visualisation API Example - Tweet time series with data from Google sheet
<!DOCTYPE html>
<html>
<head>
<title>Twitter volume</title>
<!--Load the AJAX API-->
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
// Load the Visualization API and the core charts package.
google.load('visualization', '1.0', {
'packages': ['corechart']
});
// Set a callback to run when the Google Visualization API is fully loaded.
google.setOnLoadCallback(getData);
function getData() {
// this is the key for the spreadhseet with your data in it, you can copy this from the URL for the sheet
var key = "1gIytFC4RV-FnRabk3h52vYiTd5tppKY1ac75uisuTqc";
// this is the range in the sheet to find the data
var range = "A1:B50";
// get the date from the range specified
var query = new google.visualization.Query('https://docs.google.com/spreadsheet/ccc?key=' + key + '&usp=sharing&range=' + range);
// Send the query with a callback function, to be executed when the data is reeady
query.send(drawChart);
}
// Callback that creates and populates a data table,
// instantiates the line chart, passes in the data and
// draws it.
function drawChart(response) {
// dig out the data from the response to the query
var data = response.getDataTable();
// there are squillions of cool options for your charts, shove them into this JSON object
// read more https://developers.google.com/chart/interactive/docs/gallery/linechart
var options = {
'title': 'Tweet Volume By Minute (15:00 - 15:49, Decemeber 1st)',
'width': 1000,
'height': 400,
'legend': { position: 'in'}
};
// Instantiate and draw our line chart, passing in the options JSON object.
var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
chart.draw(data, options);
}
</script>
</head>
<body>
<!--Div that will hold the pie chart-->
<div id="chart_div"></div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment