0
votes

Is it possible to create a chart in a spreadsheet with data that is not actually present in the sheet (calculated data)?

So instead of

chartBuilder.addRange(sheet.getRange("A2:A5"))

I want something like (pseudo code)

chartBuilder.addRange({0,1,2,8,15,35})

I guess I need to create a Range with custom data, but I couldn't find a solution in the documentation.

1

1 Answers

1
votes

I think the only way you could do this is if you used Charts and UI and showed it through the spreadsheet like so...

var data = Charts.newDataTable()
   .addColumn(Charts.ColumnType.STRING, "Month")
   .addColumn(Charts.ColumnType.NUMBER, "In Store")
   .addColumn(Charts.ColumnType.NUMBER, "Online")
   .addRow(["January", 10, 1])
   .addRow(["February", 12, 1])
   .addRow(["March", 20, 2])
   .addRow(["April", 25, 3])
   .addRow(["May", 30, 4])
   .build();

var chart = Charts.newAreaChart()
   .setDataTable(data)
   .setStacked()
   .setRange(0, 40)
   .setTitle("Sales per Month")
   .build();

var uiApp = UiApp.createApplication().setTitle("My Chart");
uiApp.add(chart);
SpreadsheetApp.getActiveSpreadsheet().show(uiApp);