Created
September 17, 2012 12:29
-
-
Save mhawksey/3737023 to your computer and use it in GitHub Desktop.
Google Apps Script to generate ChartFusion datasource xml from a Google Spreadsheet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//http://www.google.sc/support/forum/p/apps-script/thread?tid=345591f349a25cb4&hl=en | |
function setUp() { | |
ScriptProperties.setProperty('active', SpreadsheetApp.getActiveSpreadsheet().getId()); | |
var svc = ScriptApp.getService(); | |
if (!svc.isEnabled()) { | |
// it's not enabled, and should be | |
svc.enable(svc.Restriction.ALL); | |
} | |
} | |
function doGet(e){ | |
// uses 2d array library https://sites.google.com/site/scriptsexamples/custom-methods/2d-arrays-library | |
var t = HtmlService.createTemplateFromFile("oomfo template"); | |
t.id = e.parameter.id; | |
//var id ="q1"; | |
var doc = SpreadsheetApp.openById(ScriptProperties.getProperty('active')); | |
var sheet = doc.getSheetByName("ALL"); | |
var data = sheet.getRange(2, 3, sheet.getLastRow(), 2).getValues(); | |
var filtered = ArrayLib.filterByText(data, 0, t.id); | |
counts = {}; | |
for (i in filtered){ | |
if (counts[filtered[i][1]] == undefined){ // see if tweet is in our object store | |
counts[filtered[i][1]] = 0; // if not add it using the tweet text as key | |
} | |
counts[filtered[i][1]]++; | |
} | |
t.counts = counts; | |
//return t.evaluate(); | |
return ContentService.createTextOutput(t.evaluate().getContent()) | |
.setMimeType(ContentService.MimeType.XML); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<chart caption="Voting Response for <?= id ?>" yaxisname="Votes" xaxisname="Option" showvalues="0" animation="1" stack100percent="0" themename="Default"> | |
<set label="A" value="<?= counts.A || 0 ?>"/> | |
<set label="B" value="<?= counts.B || 0 ?>"/> | |
<set label="C" value="<?= counts.C || 0 ?>"/> | |
<set label="D" value="<?= counts.D || 0 ?>"/> | |
<set label="E" value="<?= counts.E || 0 ?>"/> | |
<PP_Internal> | |
<chart themename="Default"/> | |
</PP_Internal> | |
</chart> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment