2017-02-20 68 views
0

如何繪製谷歌折線圖顯示銷售報告明智的,我在谷歌搜索,我發現一個線圖解決方案,但它採取了兩項,但我需要折線圖只有每小時銷售..我嘗試刪除第二個數量,但我得到錯誤。我試圖與下面碼谷歌折線圖顯示銷售報告小時明智

<html> 
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script> 
<div id="chart_div"></div>  
</html> 
<script> 
google.charts.load('current', {packages: ['linechart', 'line']}); 
google.charts.setOnLoadCallback(drawCurveTypes); 

function drawCurveTypes() { 
    var data = new google.visualization.DataTable(); 
    data.addColumn('number', 'X'); 
    data.addColumn('number', 'Dogs'); 

    data.addRows([ 
    [0, 0], [1, 10], [2, 23], [3, 17 ], [4, 18], [5, 9], 
    [6, 11], [7, 27], [8, 33], [9, 40], [10, 32], [11, 35, 
    [12, 30], [13, 40], [14, 42], [15, 47], [16, 44], [17, 48], 
    [18, 52], [19, 54], [20, 42] 
    ]); 

    var options = { 
    hAxis: { 
     title: 'Time' 
    }, 
    vAxis: { 
     title: 'Popularity' 
    }, 
    series: { 
     1: {curveType: 'function'} 
    } 
    }; 

    var chart = new google.visualization.LineChart(document.getElementById('chart_div')); 
    chart.draw(data, options); 
} 
</script> 

當我與上面的代碼我得到下面errod 未捕獲的SyntaxError嘗試:在data.addRows的末端意外令牌)。請有人幫助我。提前致謝。

回答

0

的問題是在數據...

存在對數組值中的一個的丟失托架...

data.addRows([ 
    [0, 0], [1, 10], [2, 23], [3, 17 ], [4, 18], [5, 9], 
    [6, 11], [7, 27], [8, 33], [9, 40], [10, 32], [11, 35, // <-- missing bracket 
    [12, 30], [13, 40], [14, 42], [15, 47], [16, 44], [17, 48], 
    [18, 52], [19, 54], [20, 42] 
]); 

校正...

data.addRows([ 
    [0, 0], [1, 10], [2, 23], [3, 17 ], [4, 18], [5, 9], 
    [6, 11], [7, 27], [8, 33], [9, 40], [10, 32], [11, 35], // <-- correct 
    [12, 30], [13, 40], [14, 42], [15, 47], [16, 44], [17, 48], 
    [18, 52], [19, 54], [20, 42] 
]); 

看到下面的工作片段...

google.charts.load('current', {packages: ['corechart']}); 
 
google.charts.setOnLoadCallback(drawCurveTypes); 
 

 
function drawCurveTypes() { 
 
    var data = new google.visualization.DataTable(); 
 
    data.addColumn('number', 'X'); 
 
    data.addColumn('number', 'Dogs'); 
 

 
    data.addRows([ 
 
    [0, 0], [1, 10], [2, 23], [3, 17 ], [4, 18], [5, 9], 
 
    [6, 11], [7, 27], [8, 33], [9, 40], [10, 32], [11, 35], 
 
    [12, 30], [13, 40], [14, 42], [15, 47], [16, 44], [17, 48], 
 
    [18, 52], [19, 54], [20, 42] 
 
    ]); 
 

 
    var options = { 
 
    hAxis: { 
 
     title: 'Time' 
 
    }, 
 
    vAxis: { 
 
     title: 'Popularity' 
 
    }, 
 
    series: { 
 
     1: {curveType: 'function'} 
 
    } 
 
    }; 
 

 
    var chart = new google.visualization.LineChart(document.getElementById('chart_div')); 
 
    chart.draw(data, options); 
 
}
<script src="https://www.gstatic.com/charts/loader.js"></script> 
 
<div id="chart_div"></div>


注:只需要'corechart'包...

google.charts.load('current', {packages: ['corechart']});