I have a data group taken from a table of sales for the year. The group has two columns: Sale Type (e.g. Cash, Lease, etc.), and Count which is just an aggregation on the date field.
I can get a pie chart easy enough. Now I want to add a category picker that will allow the user to change the pie chart by picking a year. How can I do that?
Here is my code so far:
var dashboard = new google.visualization.Dashboard(
document.getElementById( 'dashboard_div' ) );
var categoryPicker = new google.visualization.ControlWrapper( {
'controlType': 'CategoryFilter',
'containerId': 'categoryPicker_div',
'options': {
'filterColumnIndex': 1,
'ui': {
'labelStacking': 'vertical',
'label': 'Year:',
'allowTyping': false,
'allowMultiple': false
}
}
} );
var groupedData = google.visualization.data.group(
gDataTableSales,
[ { column: 3, type: 'string', label: 'Type' } ],
[ { column: 2, aggregation: google.visualization.data.count, type: 'number', label: 'Count' } ] );
var chart = new google.visualization.ChartWrapper({
chartType: 'PieChart',
containerId: 'chart_div' });
dashboard.bind( [ categoryPicker ], [ chart ] );
dashboard.draw( groupedData );
The chart and category picker get rendered and I can select the count and the chart is updated suggesting that the mechanics are working as expected.