'TypeError: Cannot read property "getDataRange" from null. (line 3, file "Code")
I have decided to use Google Scripts when I can when using spreadsheets, just to start increasing knowledge. BUT I am untrained and got stuck quite quickly.
I saw some code on youtube for a different script but I thought I extracted what I needed and could get this to work...
function doGet() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var range = data.getRange();
var countFilter = Charts.newNumberRangeFilter().setFilterColumnIndex(2).build();
var categoryFilter = Charts.newCategoryFilter().setFilterColumnIndex(0).build();
var categorysearchFilter = Charts.newStringFilter().setFilterColumnIndex(0).build();
var monthFilter = Charts.newCategoryFilter().setFilterColumnIndex(1).build();
var tableChart = Charts.newTableChart().setDataViewDefinition(
Charts.newDataViewDefinition().setColumns([0, 1, 2]))
.build();
var pieChart = Charts.newPieChart() .setDataViewDefinition(
Charts.newDataViewDefinition().setColumns([0, 1, 2]))
.build();
var dashboard = Charts.newDashboardPanel()
.setDataTable(data)
.bind([countFilter, categoryFilter, categorysearchFilter, monthFilter],
[tableChart, pieChart])
.build();
var app = UiApp.createApplication();
var filterPanel = app.createVerticalPanel();
var chartPanel = app.createHorizontalPanel();
filterPanel.add(countFilter).add(categoryFilter).add(categorysearchFilter)
.add(monthFilter).setSpacing(10);
chartPanel.add(tableChart).add(pieChart).setSpacing(10);
dashboard.add(app.createVerticalPanel().add(filterPanel).add(chartPanel));
app.add(dashboard);
return app;
}
Error I received => TypeError: Cannot read property "getDataRange" from null. (line 3, file "Code")
Can you help me?
Solution 1:[1]
The problem is that you are telling the script to get a range of data without telling it where to look.
Try replacing the first line with this:
var data = SpreadsheetApp.getActive().getSheetByName("Name of sheet goes here");
Obviously change the last part.
There are a lot more problems with your code, try looking through here for some guidance.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | egg |
