[英]Google charts trendline not showing
我有一個谷歌圖表折線圖,我想顯示趨勢線,但它沒有顯示。
數據從數據庫中獲取,javascript由PHP生成,但生成的javascript如下所示:
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
// Load the Visualization API and the piechart package.
google.load('visualization', '1.0', {'packages':['corechart']});
// Set a callback to run when the Google Visualization API is loaded.
google.setOnLoadCallback(drawChart);
// Callback that creates and populates a data table,
// instantiates the pie chart, passes in the data and
// draws it.
function drawChart() {
var dataS = new google.visualization.DataTable();
dataS.addColumn('string', 'Dag');
dataS.addColumn('number', 'Poäng');
dataS.addRows([
['1', 32],
['2', 37],
['3', 37],
['4', 40],
['5', 31],
['6', 38],
['7', 28],
['8', 34],
['9', 41],
['10', 41],
]);
var optionsS = {
title: '',
legend: 'none',
hAxis: {title: 'Serie'},
vAxis: {title: 'Poäng'},
pointSize: 4,
trendlines: { 0: {} }
};
// Instantiate and draw our chart, passing in some options.
var chart = new google.visualization.LineChart(document.getElementById('chart_div_series'));
chart.draw(dataS, optionsS);
}
</script>
該腳本主要是來自Google圖表示例的copypaste。 圖表工作正常,但趨勢線未顯示。 有什么想法嗎?
您必須有一個連續的域軸(類型“數字”,“日期”,“日期時間”或“timeofday”)才能使用趨勢線。 通過將第一列設置為“字符串”類型(並用字符串填充),您將禁用趨勢線。 切換到“數字”類型列,趨勢線將起作用:
var dataS = new google.visualization.DataTable();
dataS.addColumn('number', 'Dag');
dataS.addColumn('number', 'Poäng');
dataS.addRows([
[1, 32],
[2, 37],
[3, 37],
[4, 40],
[5, 31],
[6, 38],
[7, 28],
[8, 34],
[9, 41],
[10, 41]
]);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.