Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save white5168/4a4d344f3d862c1ff550b46e926c728e to your computer and use it in GitHub Desktop.
Save white5168/4a4d344f3d862c1ff550b46e926c728e to your computer and use it in GitHub Desktop.
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("visualization", "1", {packages:["corechart"]});
google.setOnLoadCallback(getSpreadsheetData);
function getSpreadsheetData() {
google.script.run.withSuccessHandler(getPicData).getData();
}
function getPicData(data) {
//create data table object
var dataTable = new google.visualization.DataTable();
//define columns
dataTable.addColumn('string', data[0][0]); //日期
dataTable.addColumn('number', data[0][4]); //收盤價
dataTable.addColumn({type: 'string', role: 'annotation'});
dataTable.addColumn('number', data[0][25]); //摩台換倉成本
dataTable.addColumn({type: 'string', role: 'annotation'});
//dataTable.addColumn({type: 'string', role: 'annotationText'});
for (var i = 0; i < data.length; i++)
{
if(i != data.length-1)
dataTable.addRow([data[i][0], parseFloat(data[i][4]), null, parseFloat(data[i][25]), null]);
else if(i == data.length-1)
dataTable.addRow([data[i][0], parseFloat(data[i][4]), String(parseFloat(data[i][4])), parseFloat(data[i][25]), String(parseFloat(data[i][25]))]);
}
var options = {width: 1400,
height: 800,
is3D: true,
title: '摩台未平倉量與成本'};
var chart = new google.visualization.LineChart(document.getElementById('chart'));
chart.draw(dataTable, options);
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment