Using the following script:
function chartCreation() {
var ss = SpreadsheetApp.getActive();
var sheet = ss.getSheetByName("Sheet1");
var chart = sheet.newChart().asColumnChart()
.setTitle('Test Chart')
.addRange(sheet.getRange(1, 1, sheet.getLastRow(), 4))
.setPosition(1,1,0,0)
sheet.insertChart(chart.build());
}
Produces a chart like this one, in which the legend is empty (i.e. the data series are unlabeled).
I've read that it could be due to the format of my header row, which should be text (which mine is, but it doesn't seem to be used). If I try to build it within Google Sheets, though the chart builder dialog, it works just fine and includes the data series labels.
How do I set the "use row 1 as headers" option with Google Apps Script?
This question is similar, but has no answer pertaining to non-text format.