Reputation: 73
I'm using Google Apps Script to build an EmbeddedChart in a Google sheet. By default the vertical axis labels are right-aligned, but I need them to be left-aligned. (Below is a little screen-shot/sketch that shows what I'm trying to do). I see a number of options for formatting the vAxis text using the setOption() method of the EmbeddedChartBuilder object, as in the code sample below. But I can't find any simple solution for aligning the labels.
The documentation I've consulted is the list titled Configuration options located at https://developers.google.com/chart/interactive/docs/gallery/barchart
This seems to be an exhaustive list, so maybe what I want to do isn't possible.
The only solution that cames to mind was to pad the end of each label string with whitespace to create the appearance of being left-aligned. But this doesn't work since it turns out that whitespace is automatically truncated when the chart is built.
Can anyone suggest a solution?
function myFunction() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var range = sheet.getDataRange();
var chart = sheet.newChart()
.asBarChart()
.addRange(range)
.setPosition(1, 1, 1, 1)
.setTitle('Sales')
.setXAxisTitle('Month')
.setOption('vAxis.textStyle.fontSize','12')
.build();
sheet.insertChart(chart);
};
Upvotes: 3
Views: 1207
Reputation: 6791
You may want to check vAxis.textPosition
, this will help you position your vAxis text.
Position of the vertical axis text, relative to the chart area. Supported values:
'out', 'in', 'none'
.
Sample Code:
.setOption('vAxis.textPosition','out')
Also you might want to check this related SO question.
Hope this helps!
Upvotes: 0