Marc
Marc

Reputation: 303

How can I change the minimum value of the vertical axis with apps script in a embeddedchart (google sheets)?

I have 'manually' created a chart in google sheets by selecting a range and inserting a stacked column chart:

manual chart

I changed the vertical axis minimum value to 79.000.000.

However, I would like to automate this process. So, therefore I wrote a little script:

 /**
 * @OnlyCurrentDoc
 */

function buildChart() {
  // Get the sheet
  var sheet = SpreadsheetApp.getActiveSheet()

  //Create new chart
  var chart = sheet.newChart()
    .setChartType(Charts.ChartType.COLUMN)
    .addRange(sheet.getRange("D1:H8"))

    .setPosition(10, 10, 0, 0)
    //.setOption('title', 'Cost Price Development - Stage 3')
    .setOption('isStacked', 'TRUE')
    .setOption('colors', ['tranparant', '#93CCEA', 'green', 'black'])
    .setOption('vAxis.title', 'test test')
    //.setOption('vAxis', {'title': 'Something Here'})
    //.setOption('vAxis.viewWindowMode', 'explicit')  
    .setOption('vAxis.viewWindow.min', 79000000)
    //.setOption('vAxis.textStyle.fontSize',8)
    .build();

  // Insert chart in sheet
  sheet.insertChart(chart);
}

With the line

.setOption('vAxis.viewWindow.min', 79000000)

I want to change the minimum value of the vertical axis. However, the vertical axis does still start at 0 instead op 79.000.000.

I have also tried:

 .setOption('vAxis.minValue', 79000000)

which does not help either: the code above results in the following chart:

chart with apps script

Upvotes: 2

Views: 1930

Answers (1)

Marc
Marc

Reputation: 303

I solved it with this code line:

setOption('vAxes', {0: {title: '€', textStyle: {fontSize: 10}, titleTextStyle: {fontSize : 8}, viewWindow: {min: 79000000}}})

So, I used vAxes instead of vAxis.

Upvotes: 4

Related Questions