我想將多個圖表整合到我的頁面中,但只有第一個工作。谷歌圖表錯誤 - 不會顯示第二個圖表
JS代碼如下:
google.charts.load('current', {'packages':['corechart']});
google.charts.setOnLoadCallback(drawChart_total);
google.charts.setOnLoadCallback(drawChart_fixed);
function drawChart_total() {
var fixed_costs = document.getElementById('total_fixed_costs').value;
var variable_costs = document.getElementById('total_variable_costs').value;
var salary = document.getElementById('total_salary').value;
var data = new google.visualization.DataTable();
data.addColumn('string','Cost Type');
data.addColumn('number','Spendings');
data.addRows
([
['Fixed Costs', parseFloat(fixed_costs)],
['Variable Costs', parseFloat(variable_costs)],
['Salary', parseFloat(salary)]
]);
var options = {title: 'Total costs distribution chart', width: 600, height: 333};
var chart = new google.visualization.PieChart(document.getElementById('piechart_total'));
chart.draw(data, options);
}
function drawChart_fixed() {
var truck_payment = document.getElementById('truck_payment').value;
var collision_comp_insurance = document.getElementById('collision_comp_insurance').value;
var office_lease = document.getElementById('office_lease').value;
var health_insurance = document.getElementById('health_insurance').value;
var permits = document.getElementById('permits').value;
var data = new google.visualization.DataTable();
data.addColumn('string', 'Cost Type');
data.addColumn('number', 'Spendings');
data.addRows
([
['Truck Payment', parseFloat(truck_payment)],
['Collision/Comp Insurance', parseFloat(collision_comp_insurance)],
['Office Lease', parseFloat(office_lease)]
['Health Insurance', parseFloat(health_insurance)],
['Permits', parseFloat(permits)]
]);
var options = {title: 'Fixed costs distribution chart', width: 600, height: 333};
var chart = new google.visualization.PieChart(document.getElementById('piechart_fixed'));
chart.draw(data, options);
}
的數據是從一個形式服用。 用於第一曲線圖中的表單字段中的HTML標籤是這樣的:
<input name="total_fixed_costs" id="total_fixed_costs" placeholder="Total" value=0 readonly>
和那些用於第二圖形是這樣的:
<input type="number" min=0 id="permits" name="permits" placeholder="Write Here">
至於第二圖形雲,如果我離開它,因爲我知道以下錯誤:
jsapi_compiled_default_module.js:36未捕獲的錯誤:給出的每一行都必須爲null或數組。
在另一方面,如果我不上填充數據表的第二列中的變量使用parseFloat,我得到以下錯誤:
jsapi_compiled_default_module.js:14未捕獲的錯誤:類型不匹配。值與列索引中的類型編號不匹配1
我一直在尋找最近兩天的解決方案,但沒有成功。我想提一提,我是編程領域的新手,目前正在學習JS。我還沒有與JQuery聯繫。
謝謝。
只是一個錯字,希望這可以幫助... – WhiteHat