I'm attempting to use Google Scripts to create a Pie Chart based on two columns of a Google Sheet but I'm unsure how to prevent my "Labels" dataset from showing redundant labels. I'm sure it's something simple but any help would be appreciated.
Pie Chart with redundant labels.
Sheets columns that I'm pulling data from.
Here is the code I'm using:
function onOpen() {
var menuEntries = [{
name: "Create chart from Calendar data",
functionName: "makemyChart"
}];
var ss = SpreadsheetApp.getActiveSpreadsheet();
ss.addMenu("Austin's test", menuEntries);
}
function makemyChart() {
var sheet = SpreadsheetApp.getActiveSheet(); //retrieves active open sheet
Logger.log(sheet) // check logs and it should tell you name of the sheet tab
// start building a data table that will feed into the chart
var chartDataRange = sheet.getRange(("F:G"));
var hAxisOptions = {
slantedText: true,
slantedTextAngle: 60,
gridlines: {
count: 12
}
};
//build a new pie chart from data
var pieChartBuilder = sheet.newChart().asPieChart()
var chart = pieChartBuilder
.addRange(chartDataRange)
.setTitle('Event Break Down')
.setNumHeaders(1)
.setPosition(5, 5, 0, 0)
.setLegendPosition(Charts.Position.RIGHT)
.setOption('hAxis', hAxisOptions) //Orginally 'hAxis', hAxisOptions
.build();
// insert chart IDEALLY on a new sheet(tab) of this same spreadsheet)
// Adds tab
var ss = SpreadsheetApp.getActiveSpreadsheet();
ss.duplicateActiveSheet(); //Copies current sheet
ss.renameActiveSheet("Time Breakdown"); //Renames sheet
ss.moveActiveSheet(1); //Moves sheet to the first position
// Prepares tab (clears old content)
var sheet = ss.getSheetByName("Time Breakdown");
var rangeToClear = ("A:K")
sheet.getRange(rangeToClear).clearContent()
sheet.insertChart(chart);
}