Created
September 5, 2016 09:30
-
-
Save mdhorine/6337ae6c9179aeb7d0dec42a5441e764 to your computer and use it in GitHub Desktop.
Example of a stacked bar chart to replicate a funnel chart.
This file contains hidden or 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
<html> | |
<head> | |
<!--Load the AJAX API--> | |
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script> | |
<script type="text/javascript"> | |
// Load the Visualization API and the material barchart package. | |
google.charts.load('current', {'packages':['corechart', 'bar']}); | |
// Set a callback to run when the Google Visualization API is loaded. | |
google.charts.setOnLoadCallback(drawChart); | |
// Callback that creates and populates a data table, | |
// instantiates the pie chart, passes in the data and | |
// draws it. | |
function drawChart() { | |
// Query the Google Spreadsheet | |
var baseUrl = 'https://docs.google.com/spreadsheets/d/1L1fitqxCim1jiIZQ39PbBjQc7tSSGW3Q1F33e3PDzcg/gviz/tq?gid=0&headers=1&'; | |
var query = new google.visualization.Query(baseUrl + 'range=I2:K8'); | |
query.send(handleQueryResponse); | |
} | |
function handleQueryResponse(response) { | |
if (response.isError()) { | |
alert('Error in query: ' + response.getMessage() + ' ' + response.getDetailedMessage()); | |
return; | |
} | |
var data = response.getDataTable(); | |
var view = new google.visualization.DataView(data); | |
view.setColumns([0, 1, 2, | |
{ calc: "stringify", | |
sourceColumn: 2, | |
type: "string", | |
role: "annotation" }, | |
]); | |
var options = { | |
title: 'Bar Chart as Funnel Demo', | |
titleTextStyle: { | |
italic: false, | |
bold: false, | |
color: '#000', | |
fontSize: 18 | |
}, | |
bars: 'horizontal', | |
bar: { | |
groupWidth: '90%' | |
}, | |
legend: { | |
position: 'none' | |
}, | |
hAxis: { | |
gridlines: { | |
count: 5, | |
color: '#fff' | |
}, | |
baselineColor: 'white', | |
title: 'Number', | |
titleTextStyle: { | |
italic: false, | |
bold: false, | |
color: '#bbb', | |
fontSize: 12 | |
} | |
}, | |
vAxis: { | |
title: 'Recruitment Stage', | |
titleTextStyle: { | |
italic: false, | |
bold: false, | |
color: '#bbb', | |
fontSize: 12 | |
} | |
}, | |
tooltip: { | |
trigger: 'none' | |
}, | |
colors: ['white', '#3367d6'], | |
series: { | |
0: {enableInteractivity: false} | |
}, | |
isStacked: true | |
}; | |
// Instantiate and draw our chart, passing in some options. | |
var chart = new google.visualization.BarChart(document.getElementById('chart_div')); | |
chart.draw(view, google.charts.Bar.convertOptions(options)); | |
} | |
</script> | |
</head> | |
<body> | |
<!--Div that will hold the stacked bar chart--> | |
<div id="chart_div" style="width: 900px; height: 500px; margin: auto"></div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment