10

I'm trying to set a fixed minimum value in a chart created programmatically in my Google Spreadsheet. The goal is that I want to create several graphs with the same limits even though their data is wildly different.

For the purposes of this example, I have the following data in my spreadsheet:

Date Number 05.02.2017 125 06.02.2017 150 16.02.2017 21 05.02.2018 -5.333333333 06.02.2018 -57.33333333 16.02.2018 -109.3333333 05.02.2019 -161.3333333 

and the following script:

function update() { var title = 'Last updated ' + new Date().toString(); var ss = SpreadsheetApp.getActiveSpreadsheet(); var sheet = ss.getSheets()[0]; var chart = sheet.newChart() .setChartType(Charts.ChartType.AREA) .addRange(sheet.getRange("A1:B8")) .setPosition(5, 5, 0, 0) .setOption('title', title) .setOption('vAxis.minValue', -5000) .setOption('vAxis.viewWindow.min', -5000) .build(); sheet.insertChart(chart); } 

... so, in other words, I'm trying to set the minimum value, to -5000. Setting vAxis.minValue and/or vAxis.viewWindow.min accomplishes exactly nothing. (Yes, I know that my code will create a new one every time update() is called, but that's not the point here.)

There is a minimum/maximum value option when the chart is edited. The values there are blank: enter image description here

What do I do to change these values programmatically?

Full link to sheet here: https://docs.google.com/spreadsheets/d/1dKBG8Nx5mypD2YAfOTCzo2cvIX6C7R18SCIsNB5FsT0/edit?usp=sharing

1 Answer 1

7
+25

To set the minimum value of vAxis to -5000, configure the option as setOption("vAxes", {0: { viewWindow: { min: -5000} }})

 function update() { var title = 'Last updated ' + new Date().toString(); var ss = SpreadsheetApp.getActiveSpreadsheet(); var sheet = ss.getSheets()[0]; var chart = sheet.newChart() .setChartType(Charts.ChartType.AREA) .addRange(sheet.getRange("A1:B8")) .setPosition(5, 5, 0, 0) .setOption('title', title) .setOption("vAxes", {0: { viewWindow: { min: -5000} }}) .build(); sheet.insertChart(chart); } 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.