Skip to content

Instantly share code, notes, and snippets.

@franzenzenhofer
Created May 31, 2023 12:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save franzenzenhofer/f73d79df63a708bb1e6db300a6d87365 to your computer and use it in GitHub Desktop.
Save franzenzenhofer/f73d79df63a708bb1e6db300a6d87365 to your computer and use it in GitHub Desktop.
GSC Devices Bar Chart
function generateCharts() {
// Access the sheet
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Devices');
// Sort Column A
sheet.getRange('A2:E4').sort(1);
// Get the range for your data
var dataRange = sheet.getRange('A1:E4');
// Create a pie chart for Clicks
var pieChartBuilder = sheet.newChart();
pieChartBuilder.addRange(dataRange)
.setChartType(Charts.ChartType.PIE)
.setOption('title', 'Clicks per Device')
.setPosition(5, 6, 0, 0)
.setOption('sliceVisibilityThreshold', 0) // Ensures that all slices are shown
.asPieChart();
sheet.insertChart(pieChartBuilder.build());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment