I have created the script below, which runs from an onedit function for when cell J1 is edited. The graph exists in the sheet titled 'Daily Data'. The data it will be using is from a sheet titled 'Long Term Data'.
I used the following link as guidance: https://developers.google.com/apps-script/reference/spreadsheet/embedded-chart.
Thank you for any help.
function onEdit(e) {
//This IF statement ensures it will only run when cell J1 is edited:
if (
e.source.getSheetName() == "Daily Data" &&
e.range.columnStart == 10 &&
e.range.columnEnd == 10 &&
e.range.rowStart >= 1 &&
e.range.rowEnd <= 1
) {
var spreadsheet = SpreadsheetApp.getActive();
var daily_data = spreadsheet.getSheetByName("Daily Data");
var LTD_data = spreadsheet.getSheetByName("Long Term Data");
//ABOVE HAS BEEN TESTED AND RUNS SUCCESFULLY. THE BELOW DOES NOT...
var chart = daily_data.getCharts()[0];
var range = LTD_data.getRange("B2:J3")
chart = chart.modify()
.addRange(range)
.build();
spreadsheet.updateChart(chart);
}
}
;