Note that I added fudged data to your dataTable to make the filters work better.
I'm struggling to work out whether it is possible to update a chart's title when a selection is made from a drop down in the Google chart-wrapper.
I have a large data set where I am looking at commuting patterns between one area and another, so a user will select an area they are interested in and the chart will change to reflect data for their area. The problem run to a dead end on (and it may not be possible) is working out how to change the title of the chart to include the selected areas name.
Any suggestions anyone has would be much appreciated. I've had a good search but can't work out whether it's doable?
Code below:
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<style>
.google-visualization-controls-categoryfilter { color: red }
.goog-menu-vertical { max-height: 300px; overflow-y: auto;}
</style>
<title>
Commute-APS
</title>
<script type="text/javascript">
google.load('visualization', '1.1', {packages: ['controls']});
</script>
<script type="text/javascript">
function drawVisualization() {
// Prepare the data
var data = new google.visualization.DataTable();
data.addColumn('string', 'Direction');
data.addColumn('string', 'Residence');
data.addColumn('string', 'Workplace');
data.addColumn('number', 'Proportion');
data.addColumn({type:'number', role:'interval'});
data.addColumn({type:'number', role:'interval'});
data.addRows([
['Inward', 'City of London', 'Tower Hamlets', 7.35, 6.2, 8.55],
['Inward', 'City of London', 'Newham', 5.63, 4.6, 6.63],
['Inward', 'City of London', 'Wandsworth', 4.6, 3.4, 5.84],
['Inward', 'City of London', 'Redbridge', 4.48, 3.5, 5.41],
['Inward', 'City of London', 'Waltham Forest', 4.15, 3.3, 5.02],
['Inward', 'City of London', 'Southwark', 3.65, 2.6, 4.73],
['Inward', 'City of London', 'Westminster', 3.55, 2.4, 4.71],
['Outward', 'Wyre Forest', 'Shropshire', 10.34, 0, 12.67],
['Outward', 'Wyre Forest', 'Wolverhampton', 3.84, 0, 4.49],
['Outward', 'Wyre Forest', 'Tamworth', 1.83, 0, 4.44],
['Outward', 'Wyre Forest', 'Herefordshire, County of', 1.48, 0, 3.3],
['Outward', 'Wyre Forest', 'Warwick', 0.78, 0, 1.3],
['Outward', 'Wyre Forest', 'East Staffordshire', 0.7, 0, 1.4red8]
]);
// Define a category picker control for the Gender column
var categoryPicker = new google.visualization.ControlWrapper({
'controlType': 'CategoryFilter',
'containerId': 'control2',
'options': {
'filterColumnLabel': 'Residence',
'ui': {
'labelStacking': 'vertical',
'allowTyping': false,
'allowMultiple': false,
height: 100
}
},
'state': {'selectedValues': ['City of London']}
});
var categoryPicker2 = new google.visualization.ControlWrapper({
'controlType': 'CategoryFilter',
'containerId': 'control3',
'options': {
'filterColumnLabel': 'Direction',
'ui': {
'labelStacking': 'vertical',
'allowTyping': false,
'allowMultiple': false,
height: 100
}
},
'state': {'selectedValues': ['Outward']}
});
// Define a Bar chart
var chart = new google.visualization.ChartWrapper({
'chartType': 'BarChart',
'containerId': 'chart1',
'options': {
'width': 700,
'height': 700,
'vAxis': {textStyle: {fontSize:12, fontName:'Arial'}, viewWindow:{max:10}},
'hAxis': {maxValue: 80, minValue:0},
animation:{
duration: 1000,
easing: 'out'
},
'legend': 'none',
'title': 'Outward commuting'
},
// Instruct the barchart to use columns 2, 3, 4 and 5
// from the 'data' DataTable.
'view': {'columns': [2, 3, 4, 5]}
});
// Create a dashboard
new google.visualization.Dashboard(document.getElementById('dashboard')).
// Establish bindings, declaring the both category pickers
// picker will drive the chart.
bind(categoryPicker, categoryPicker2).
bind(categoryPicker2, chart).
// Draw the entire dashboard.
draw(data);
}
google.setOnLoadCallback(drawVisualization);
</script>
</head>
<body style="font-family: Arial;border: 0 none;">
<div id="dashboard">
<table>
<tr style='vertical-align: top'>
<td style='width: 250px; height: 75px; font-size: 0.9em;'>
<div id="control2"></div>
<div id="control3"></div>
<div style="float: top;" id="chart1"></div>
</td>
</tr>
</table>
</div>
</body>
</html>