Help with a Line chart to visualize the growth of my portfolio

14 views
Skip to first unread message

Luca Pizzolato

unread,
May 25, 2020, 12:18:05 PM5/25/20
to Google Visualization API
Hello, I am not a developer so unfortunately I can't code scripts.

I have an issue with this line of code that I have found on youtube, potentially it could solve my problem but it doesn't work.

I have 1 tab that shows the earning of my portfolio everytime I update it, so I would like to visualize how is doing with a simple line chart that update everytime I update the page.

What I have found is this line of code:
/*
EVENT FUNCTION

Each time the spreadsheet is opened or refreshed
append a new entry
on the Trend sheet
for the sum of the TotalGain/Loss column
from the Portfolio sheet.
*/

function onOpen() {
  var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
  var portfolioSheet = spreadsheet.getSheetByName('portfolio');
  var rng = portfolioSheet.getRange(7,15,portfolioSheet.getLastRow());
  var values = rng.getValues()
  var total = 0
  for (var i = 0; i < values.length; i++) {
    if (parseFloat(values[i]) > 0) {
      total = total + parseFloat(values[i]);
    }
  }
  
  var localDateTime = new Date()
  var trendSheet = spreadsheet.getSheetByName('Trend');
    trendSheet.appendRow([localDateTime, total]);
}
The numbers 7 to 15 are the return for every stocks I have. The most common error I receive when I update is that it doesn't calculate the fact that I have losses so it does the sum. sometimes I receive a value equal to 0 which is impossible.

I have another cell that return the sum of those values, I would only like to take that number but it doesn't work if I change it here var rng = portfolioSheet.getRange(7,15,portfolioSheet.getLastRow());

Maybe someone can help me. Thanks a lot
Reply all
Reply to author
Forward
0 new messages