I have a slideshow on Google Slides running as our cafeteria slideshow. Recently, I got a Weather API to work and regularly update, using a linked chart. The chart and slide now updates automatically.
A student suggested that we add a real-time clock. Easy! I set it up in Charts using the =NOW() function and a scorecard chart, which displays just how I would like it. I linked it to the slide and set the trigger to run every minute, instead of every hour as I had done. The Sheet is set up to update every minute, and visibly does so. The Slides trigger fires, and the script runs successfully.
But Google Slides only notices that the Sheets chart has changed sporadically. Even if I unlink, create a new sheet, and re-link, it will still show the old time for an undetermined period of time. Here is my refreshCharts() function:
function refreshCharts(){
var gotSlides = SlidesApp.getActivePresentation().getSlides();
for (var i = 0; i < gotSlides.length; i++) {
var slide = gotSlides[i];
var sheetsCharts = slide.getSheetsCharts();
for (var k = 0; k < sheetsCharts.length; k++) {
var shChart = sheetsCharts[k];
shChart.refresh();
}
}
}
Is there something I should add to tell Google that yes, I am changing this data as often as I claim I am? This has been working so cleanly for the Weather side that I was shocked when the linked chart refused to update here. Any clues as to what I might be missing?
Attached screenshot shows the current time discrepancy. Linked Chart Discrepancy
The =NOW() function relies on recalculation (edited in File > Settings > Recalculation) to update the cell. This recalculation does not register as a change to the spreadsheet, so it does not trigger an update in the linked chart, even though the value changes.
I solved this by adding a counter that runs on a trigger; anything that changes a cell will do. Sample function:
function countMinutes() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var minutes = ss.getRange("E1");
var plusMinute = minutes.getValue();
minutes.setValue(plusMinute+1);
}