1
我已經在谷歌電子表格的以下數據:如何在面積圖中的X軸上繪製日期?
ColumnA ColumnB
Departament Quantity
01/01/2016 23
02/01/2016 43
04/01/2016 5
06/01/2016 65
10/01/2016 12
11/01/2016 32
13/01/2016 22
15/02/2016 2
而想要使用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', 'bar']});
google.setOnLoadCallback(getSpreadsheetData);
function getSpreadsheetData() {
google.script.run.withSuccessHandler(drawChart).getSpreadsheetData();
}
function drawChart(rows) {
var options = {'title':'Example','width':400,'height':300};
var data = google.visualization.arrayToDataTable(rows, false);
var chart = newgoogle.visualization.LineChart(document.getElementById("main"));
chart.draw(data, options)
}
</script>
</body>
</html>
我的腳本來讀取表:
function getSpreadsheetData() {
var ssID = "12GvIStMKqmRFNBM-C67NCDeb89-c55K7KQtcuEYmJWQ",
sheet = SpreadsheetApp.openById(ssID).getSheets()[0],
data = sheet.getDataRange().getValues();
return data;
}
但是我不能畫的情節,這個問題dissapear當我的數據更改爲數字(即42370),但那不是我想要的!
的問題是:我有什麼,以便更改爲x軸向右格式添加?
希望這可以幫助... – WhiteHat
感謝您的回答不幸,圖表保持不變,似乎代碼只是忽略了haxis.for mat語句(顯然註釋部分被刪除了) –
你知道它是以字符串還是實際日期加載嗎?你可以檢查['data.getColumnType(0)'](https://developers.google.com/chart/interactive/docs/reference#DataTable_getColumnType) – WhiteHat