to extract data.
Now, I need to filter by the Date; however even while using the DateRangeFilter, I get the same error.
The Date column in my spreadsheet is of the "Date" Format. Because of this format, I am unsure why I am getting a ScriptError, however, it seems like there's something wrong here.
This is the JavaScript code I used for the sample spreadsheet. The code that is related to the DateRangeFilter is marked in orange.
<script>
// Load the Visualization API and desired package(s).
google.load('visualization', '1.0', {'packages':['controls']});
/**
* Run initializations on dialog load.
*/
$(function() {
// Set a callback to run when the Google Visualization API is loaded.
// Note: could also be accomplished via google.load options.
google.setOnLoadCallback(sendQuery);
// Assign handler functions to dialog elements here, if needed.
// Call the server here to retrieve any information needed to build
// the dialog, if necessary.
});
/**
* Issue asynchronous request for spreadsheet data.
*/
function sendQuery() {
google.script.run
.withSuccessHandler(drawDashboard)
.withFailureHandler(function(msg) {
// Respond to failure conditions here.
$('#main-heading').text(msg);
$('#main-heading').addClass("error");
$('#error-message').show();
})
.getSpreadsheetData();
}
/**
* Callback function to generate visualization using data in response parameter.
*
* @param {Object[][]} Two-Dim array of visualization data
*/
function drawDashboard(response) {
$('#main-heading').addClass("hidden");
if (response == null) {
alert('Error: Invalid source data.')
return;
}
else {
// Transmogrify spreadsheet contents (array) to a DataTable object
var data = google.visualization.arrayToDataTable(response,false);
//new dashboard
var dashboard = new google.visualization.Dashboard(document.getElementById('dashboard-div'));
//table chart to display data
var table = new google.visualization.ChartWrapper({
'chartType': 'Table',
'containerId': 'table-div'
});
//Range Filter
//fails if binding is carried out on
var donutSlider = new google.visualization.ControlWrapper({
'controlType': 'DateRangeFilter',
'containerId': 'slider-date-div',
'options': {
'filterColumnLabel': 'Date'
}
});
//Category filter for the school
var school = new google.visualization.ControlWrapper({
'controlType': 'CategoryFilter',
'containerId': 'selector-school-div',
'options': {
'filterColumnLabel': 'School'}});
//Category filter for the staff
var staff = new google.visualization.ControlWrapper({
'controlType': 'CategoryFilter',
'containerId': 'selector-staff-div',
'options': {
'filterColumnLabel': 'Staff Name'
}
});
// Set up dependencies between controls and charts
dashboard.bind([school, staff,donutSlider], table);//<-Fails
// Draw all visualization components of the dashboard
dashboard.draw(data);
}
}
</script>