Technical Issue: Pie Chart Slice "Distance from Center" and "Color" not updating via Apps Script

21 hours ago 3
ARTICLE AD BOX

I am seeking help regarding a consistent technical issue with Pie Charts in Google Sheets when using Apps Script.

The Problem: When I try to programmatically update a Pie Chart, some visual elements update correctly (like the Chart Title and Donut Hole size), but other elements remain unchanged in the UI.

Specifically, the following options do not render visually:

Distance from center (offset): The slice does not move/explode from the center.

Slice Color: The specific color applied to a slice is ignored, and it keeps the default theme color.

Observations:

This is not a script error, as other properties (like the title) change successfully during the same execution.

Manual adjustments through the Chart Editor work perfectly, which suggests the issue is related to how the API handles the "slices" configuration object.

I have tried refreshing the page and clearing the cache, but the visual state of the slices remains stuck.

Has anyone encountered this behavior where only specific chart properties fail to sync with the UI? Is there a known workaround for forcing the chart to redraw these specific slice attributes?

Thank you for your time and assistance.

Here is my code for creating the chart:

/** * Minimal Reproducible Example: * Creates test data and attempts to build a Pie Chart with a slice offset. */ function createPieWithOffsetMCVE() { const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getSheetByName("Test") || ss.insertSheet("Test"); // 1. Prepare Test Data sheet.clear(); const testData = [ ["Group A", 10], ["Group B", 20], ["Group C", 30] ]; sheet.getRange(1, 1, 3, 2).setValues(testData); // 2. Ensure enough space (Avoid "Out of Bounds" error) if (sheet.getMaxRows() < 20) sheet.insertRowsAfter(sheet.getMaxRows(), 10); if (sheet.getMaxColumns() < 10) sheet.insertColumnsAfter(sheet.getMaxColumns(), 5); // 3. Clean up existing charts const charts = sheet.getCharts(); charts.forEach(c => sheet.removeChart(c)); // 4. Define Slice Options (The core issue: offset is ignored) const sliceOptions = { 0: { offset: 0.25, color: '#FF0000' }, // Expected: 25% distance from center 1: { offset: 0, color: '#3366CC' }, 2: { offset: 0, color: '#DC3912' } }; // 5. Build Chart const chartBuilder = sheet.newChart() .setChartType(Charts.ChartType.PIE) .addRange(sheet.getRange("A1:B3")) .setPosition(5, 1, 0, 0) .setOption('title', 'Offset Bug Test') .setOption('is3D', true) .setOption('pieHole', 0.4) .setOption('slices', sliceOptions) .setOption('useFirstRowAsHeaders', false) .build(); sheet.insertChart(chartBuilder); Logger.log("Chart created. Slice 0 should have 0.25 offset, but it stays at center."); }
Read Entire Article