Hi All,

All the Line chart examples that i see online rely on building the data 
table manually in the app script and then constructing the line graph. Is 
there a means to Link the google sheet data to create line graph. 

I have my sample code, but not sure where i am going wrong in developing a 
webscript to draw line chart using google sheet data. Below is my code.  

// Code.gs
function doGet(e) {
  
  return HtmlService
  .createTemplateFromFile("index")
  .evaluate()
  .setTitle("Google Spreadsheet Chart")
  .setSandboxMode(HtmlService.SandboxMode.IFRAME);
  
}

function getSpreadsheetData() {
  
  var ssID   = "PUT_YOUR_SPREADSHEET_ID",
      sheet  = SpreadsheetApp.openById(ssID).getSheets()[0],
      data   = sheet.getDataRange().getValues();
  
  return data;
    
}

Below is the html file inside the script editor saved as index.html

<!DOCTYPE html>
<html>

<head>
  <script src="https://www.google.com/jsapi";></script>
</head>

<body>

  <div id="main"></div>

  <script>
    google.load('visualization', '1', {
      packages: ['corechart', 'line']
    });

    google.setOnLoadCallback(getSpreadsheetData);

    function getSpreadsheetData() {
      google.script.run.withSuccessHandler(drawChart).getSpreadsheetData();
    }

    function drawChart(rows) {

      var options = {
        title: 'Line Chart',
        legend: { position: 'bottom' },
        chartArea: {
          width: '60%'
        },
        vAxis: {
          textStyle: {
            fontFamily: 'Arial',
            fontSize: 12
          }
        }
      };

      var data = google.visualization.arrayToDataTable(rows, false),
        chart = new 
google.visualization.LineChart(document.getElementById("curve_chart"));

      chart.draw(data, options);

    }
  </script>
</body>

</html>


your support and help is much appreciated. 

Thanks
Regards

-- 
You received this message because you are subscribed to the Google Groups 
"Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/google-visualization-api.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-visualization-api/2c2835c4-be97-4360-b167-29b96e870c6a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to