Search code examples
google-apps-scriptgoogle-visualizationgoogle-appsgoogle-apps-script-editor

How do I set "aggregate data series" to average instead of sum in Google Apps Script?


I'm trying to automate graph generation through google apps script, but the one setting I cannot find anywhere in the documentation is how to change the way the data is aggregated from sum to average in google apps script.

I looked through the documentation and attempted to follow the instructions from Google Apps Script: How to set "Use column A as labels" in chart embedded in spreadsheet?, but there didn't seem to be any change in the JSON object.


Solution

  • I finally solved it. It turns out I was looking at the wrong JSON object, and the setting is called "aggregateFunction", which I set to average. However, you can't set it directly using setOption. Instead, you must set it for each series in the chart, for example:

    .setOption("series", {"0":{"aggregateFunction":"average"}})