Auto update chart .. error ???

Skip to first unread message

Ševc Dominik

Aug 12, 2021, 4:23:16 AMAug 12
to Google Visualization API
Hi all .
I have easy project, make own electronics with sensors (temperature, water sensor, energy ). All this data are stored to spreadsheet . 
I have two spreadsheet 
1. record all data in all time 
2. spreadsheet for last 48 hour .
Here is part of script :
var newRow_48 = sheet_48.getLastRow();
if (newRow_48 > 48) sheet_48.deleteRow(2);              
newRow_48 = sheet_48.getLastRow() + 1; 
var newRange_48 = sheet_48.getRange(newRow_48, 1, 1, rowData.length); 
On first find last row , then if more then 48 , delete row 2 , then append data to last row .
All working perfect , for 100%
Here is link to my spreadsheet : last 48 hour       
I create chart on new sheet , 
1.Graf Energie
2.Graf Voda

I set all what I want , and show me all data what I want .

Problem : 
1. I set range from 1:49 
for example A1:A49 
but after some time range change from 1:49 to 1:49 , then 1:47 etc .. 
not only in A1:A49 , also all other range D1:D49 , S1:S49
what is problem??

I know I reload all data in my last 48 hour spreadsheet . 
delete  row 2 and then write new data to last row ..

what is problem .. 

regards ..

Ševc Dominik

Aug 25, 2021, 2:45:26 AMAug 25
to Google Visualization API
Hi all .
I have problem with chart.
I search solution and find it .. .
In chart builder make complete chart (design) what I want with all data sources .
Then start script editor and make new file. Make script :

function UpdateEnergia48() {
  var spreadsheet = SpreadsheetApp.openById('your ID');
  spreadsheet.setActiveSheet(spreadsheet.getSheetByName('Graf  Energie'), true); // here write name your sheet where chart is 
  var sheet = spreadsheet.getActiveSheet();
  var charts = sheet.getCharts();
  var chart = charts[charts.length - 1].modify()
  .addRange(spreadsheet.getRange('\'Hárok1\'!A1:A49')) // here define source  for all range what I need  Hárok1 is in Slovak Language , in english is sheets , for example ('\'Sheet1\'!A1:A49')) , or name of your Sheets
after this work perfect, lots of help me macro record.. then I see code and can edit it .
If all finish then make time event every 15 minutes start my script UpdateEnergia48() and data are updated ..
With this code you can make google web page with chart and public it .. work good ..
Dátum: štvrtok 12. augusta 2021, čas: 10:23:16 UTC+2, odosielateľ: Ševc Dominik
Reply all
Reply to author
0 new messages