Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Example of setting a query with Google Fusion Tables and the Google Visualization API
You are free to copy and use this sample in accordance with the terms of the
Apache license (
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "">
<html xmlns="">
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
Google Visualization API Sample
<script type="text/javascript" src="//"></script>
<script type="text/javascript">
google.load('visualization', '1', {packages: ['linechart']});
<script type="text/javascript">
var visualization;
function drawVisualization() {
// To see the data that this visualization uses, browse to
// With Fusion Tables the base query url is always the same
// To identify which table of data we are querying we use the FROM query with the docid in the query
// We also specify columns by their name not A, B, C, etc. Note back-quotes ` don't appear to work when
// referencing column ids that contain spaces
var query = new google.visualization.Query(
// Apply query language.
query.setQuery('SELECT country_name, population_density FROM 1hoqEqL-eU7AnO2yG4xsaYbeWBRWWNs_yoGHXN2pk WHERE population_density > 100 ORDER BY population_density' );
// Send the query with a callback function.
function handleQueryResponse(response) {
if (response.isError()) {
alert('Error in query: ' + response.getMessage() + ' ' + response.getDetailedMessage());
var data = response.getDataTable();
visualization = new google.visualization.LineChart(document.getElementById('visualization'));
visualization.draw(data, {legend: 'bottom'});
<body style="font-family: Arial;border: 0 none;">
<div id="visualization" style="height: 400px; width: 400px;"></div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment