How to update chart embedded in Google Site using Google Script - google-apps-script

My goal is to retrieve the 13 last data logged to a Google Spreadsheet through a Google Form and to display them in a Chart on a Google Site.
To do so, I created a Google Script associated with the Google Spreadsheet which reads the last 13 rows of the Spreadsheet and create a new chart based on them. Then I have embedded the chart on my Google Site with Live Mode.
When I enter a new value through the form, the chart created by the script on the Spreadsheet is correctly updated and show 13 values. But the version embedded on the Google Site adds the new value to the range without hiding the 14th thus showing 14 ones (and as more values as I enter afterwards).
To fix the issue, I retrieve the Google Site in the script and every time delete the previous chart and embed the new chart generated by the Google Spreadsheet. However the SitesApps does not seem to enable to retrieve and manage the Chart object easily.
My questions are:
- Do you see an easier way to do what I currently what to do ?
- Do you know a way to retrieve and manage the Chart Object embedded in a Google Site through Google Script ?
What I want to do looks like that :
var site = SitesApp.getSiteByUrl('siteUrl');
var page = Site.getChildByName('home');
var chart = page.getHtmlContent(). ??? Function to get the Chart object ???
Thanks in advance for your help.

Not really. You'll have to search for the text you want to replace in the HTML content. What you could do instead, though, is make a UiApp gadget that generates the charts whenever it's loaded.

Related

Script to "click" on a drawn button on a Google Sheet for Analytics v4 Report?

I have a Google Sheets Apps Script question related to an extension I use. We use Google Analytics v4 for data on our app's activity, and I pull daily numbers on that into a Google Sheet to create reports. Google made a free extension to do that for GA v3, but not for v4, and so I have to use an extension called Google Analytics Connector by SyncWith in order to get the data. It gives you 35 free report refreshes per month before it locks down and makes you pay to get any more, so I have to be very specific about only refreshing once a day (my company is not going to pay for a monthly plan from them). SyncWith has an automatic daily refresh setting, but the problem is it doesn't let you pick the specific time that it refreshes.
SyncWith makes spreadsheets for its reports, and originally had a TRUE/FALSE checkbox at the top. When you checked it, it would execute their code to pull in the new day's numbers from GA v4. I made this simple Apps Script that would simply check the box and uncheck it to get the report to run, and had a trigger set to run the Apps Script between 6 and 7 a.m.
function AppDataRefresh() {
var sheet = SpreadsheetApp.getActive().getSheetByName('App Daily data');
sheet.getRange('A1').setValue("TRUE");
sheet.getRange('A1').setValue("FALSE");
}
However, now SyncWith has replaced its checkboxes with a new panel at the top that uses drawn buttons. This is what it looks like: https://freeimage.host/i/H7FfrEF
So, unfortunately, there's no longer any checkbox, meaning I can't get this report generated automatically at a specific time with my original Apps Script fix. So, my question is, based on the above picture, is there any kind of an Apps Script that can simulate clicking on a drawn button in a Google Sheet, based on cell location? For example, is there an Apps Script that could click "Refresh" by just clicking on cell D1?

Google Sheets Update Filter data range when new rows aded

I have a Google Sheets spreadsheet with several tabs. Data is written to the 'tracker' tab constantly by a script which is writing information from incoming files. So new rows are constantly being added.
The tracker tab has a number of 'filter views' built using the UI. The data range that these filter views point to does not update when new rows are added.
I have seen some scripts which seem to be able to update the range if usng the Google Sheets API. However, I need something that runs within Google Apps Script itself..
Can anyone help?
The answer was to add the Google Sheets API via the add Services menu.

How to create a URL that modifies a particular cell in Google Sheets?

I have a google sheet where I have information about places. I used that sheet to populate a map on Google My Maps. I want to insert (create) a URL for every point of the map so when I clic on it the information in the sheet gets updated (for example chaging one cell value).
¿Is it possible to create a URL that modifies a particula cell on a google shett when it´s visited? ¿How?
Thanks in advance.
The easiest way I've found to pass information from a hyperlink to a Google Sheet is by using Google Forms as an intermediary - here's a blog post I found that outlines how to set up a URL that prefills Google Form with certain answers and automatically submits it when clicked (by adding &submit=Submit to the URL). The Google Form answers are then available in a Google Sheet.
This isn't exactly a google-apps-script solution, but from here you could pass that information back to your original Google Sheet with an Apps Script function or with ImportRange depending on the complexity of your needs.

How to create a dynamic chart in google site with data from google spreadsheet?

I come from Vietnam so my English not quite! Please people sympathize if I have written anything confusing!
I want to create a line chart in google site with data taken from google spreadsheet. If the data in the spreadsheet update then chart in the site automatically changes (like chart that when we insert in the spreadsheet).
The spreadsheet is response from the form : http://goo.gl/forms/jRjl0DCAf3
Thank you very much!
Taken verbatim from here in Google Sites help. I have italicized the most important information for automatically updating the chart.
To insert a chart into a site, follow these steps:
Open the site page you'd like to insert a chart into.
Click the edit page button.
Go to the Insert menu, and select Chart.
Select a spreadsheet from the list that contains the chart data you'd like to display.
- If the spreadsheet already contains a chart, you can select the chart. This will be a snapshot of the spreadsheet chart, and the chart won't update if spreadsheet data is modified. To insert a chart that dynamically updates, open the charts editor and select the Live option.
- If the spreadsheet doesn't already have a chart in it, enter a range of data. If you mark Live, the chart will update as spreadsheet data is modified. If you mark Snapshot, the chart won't update unless you manually do so. Learn more about creating a chart.
Once you've selected or created a chart, click OK.
On the next page, you can adjust the dimensions of the chart and change the title. When you've done so, click Save, and the chart will be inserted into the page.
Keep in mind:
Anyone viewing your site can view a Snapshot chart. If you've selected Live updating for your chart, only people who have access to the spreadsheet will be able to view an updated version of the original chart.

Google Spreadsheet Script to publish chart

Is there a way to publish a chart with a Google spreadsheet script? I dynamically create charts, but need a way to also dynamically publish these charts.
I am referring to the process of publishing a chart from the hidden menu at the top right of a chart. See below.
Unfortunately this functionality doesn't exist in Apps Script, but you can file a feature request on our issue tracker.
If the dynamic reports are replacing your charts like it did for me I just created a named range on the sheet that held the dynamic data. Then used =importRange to populate the sheet with the chart, then you publish the one time, my data pulls every hour, so my chart updates every hour. Hope it helps.