I'm looking for a way to embed a Charts.Chart
to a Google Sheet (but not only, I also want to be able to insert it to other supports such as userform, Google Doc, etc.)
function generateChart(data) {
var chartBuilder = Charts.newBarChart();
// Miscellaneous such as titles, dimensions and data
// ..
;
var chart = chartBuilder.build();
return chart;
}
Also, I don't want to directly use the chart values from the spreadsheet range (there will be some data manipulation..), but used if from data
where is a struct of array.
data = {
field1: [..],
field2: ..
}
So, basically I want to avoid something like as it creates a dependency to the Sheet.
var sheet = SpreadsheetApp.getActiveSheet();
var chartBuilder = sheet.newChart()
// ..
;
If I write sheet.insertChart(generateChart(data))
, I get the following error. Which makes sense because I'm not dealing with same kind of Chart
, but is there a workaroud?
Exception: The parameters (Charts.Chart) don't match the method signature for SpreadsheetApp.Sheet.insertChart.
I'm wondering if I shouldn't convert it as blob
in order to make it compatible with Google Sheet Chart format, but I'm sure there are more straightforward ways to achieve it.
Thanks for any insights!