How do I create a Line Graph on App Script?

34 Views Asked by At

I have this app script code that first deletes any existing graphs then I want it to put the x-axis as xRange and the series as yValues (To find my ranges, I used some other functions but they work correctly and get my wanted ranges) (I want the graph on the Graph spreadsheet)

function createLineGraph(){
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var attendance = ss.getSheetByName("Attendance");
  var graph = ss.getSheetByName("Graph");

  // Delete any existing line charts in the sheet
  var chts=graph.getCharts();
  for(var i=0;i<chts.length;i++){
    graph.removeChart(chts[i]);
  }


  var xRange = attendance.getRange("B1:"+getColumnLetter(findTotalAttendanceColumn(attendance)-1)+"1");
  var yValues = attendance.getRange("B"+findTotalAttendanceRow(attendance)+":"+getColumnLetter(findTotalAttendanceColumn(attendance)-1)+findTotalAttendanceRow(attendance));

}

For example: If the xRange was "hello","bye","idk" and the yValues were 2,8,5, then the line graph would look like this: enter image description here

Could someone please tell me how to do it? Thanks

0

There are 0 best solutions below