有人可以告诉我为什么不画图吗?
当我有3片时,它绘制得很好。但是当我添加第四个切片时,它不再绘制了。
代码:
function pieChart() {
var data = new google.visualization.DataTable();
data.addColumn('string', 'Placement');
data.addColumn('number', 'Amount');
data.addColumn({type: 'string', role: 'tooltip'});
data.addRows([
<?php
echo "['1st Place', $first_total, '1st place Received: $first_total times'],";
echo "['2nd Place', $second_total, '2nd place Received: $second_total times'],";
echo "['3rd Place', $third_total, '3rd place Received: $third_total times']";
//WHEN I ADD THIS BOTTOM LINE THE CHART NO LONGER DRAWS
echo "['4th Place', $fourth_total, '4th place Received: $fourth_total times']";
?>
]);
var options = {
tooltip: {isHtml: true},
// 'title':'Number of times Dancer Placed in top 3 ranks',
focusTarget: 'category',
'legend': { position: 'bottom' },
//'slices': {0: {color: '#D4AF37'}, 1:{color: '#C0C0C0'}, 2:{color: '#CD7F32'}}
};
var chart = new google.visualization.PieChart(document.getElementById('pie_chart'));
chart.draw(data, options);
}
编辑
我确实尝试了此代码,而不使用php和hardcoding值。结果是相同的,它将与前三个切片一起绘制,但是当我添加第四个切片时,它将不再绘制。
答案 0 :(得分:3)
第三行中的数组后需要一个逗号...
echo "['3rd Place', $third_total, '3rd place Received: $third_total times'],"; // <-- add comma after array