未显示饼图!当我尝试将警报功能放在addRow之前时,它会发出警报;但是当它发出警报时,它不会发出警报!似乎addRow函数存在问题。
function drawVisualization(dataValues) {
// dataValues is the response from database
var data = new google.visualization.DataTable();
data.addColumn('string', 'Column Name');
data.addColumn('number', 'Column Value');
for (var i = 0; i < dataValues.length; i++) {
alert(dataValues.length); // alerted
data.addRow([dataValues[i].des, dataValues[i].cnt]);
alert(dataValues.length); // not alerted
}
var chart = new google.visualization.PieChart(document.getElementById('visualization'));
chart.draw(data, { title: "Google Chart demo" });
}
我都尝试:
data.addRow([dataValues[i].des, dataValues[i].cnt]);
data.addRow([$dataValues[i].des, $dataValues[i].cnt]);