我无法在for循环中显示所有图表,仅显示最后一个图表
var l = 0;
for (j in quizs[i].quests) {
if (val == quizs[i].quests[j]["quizId"]) {
l = l + 1;
$(function() {
console.log(quizs[i].quests[j]["question"]);
var a = '#' + l;
var pieChartCanvas = $(a).get(0).getContext('2d');
var pieChart = new Chart(pieChartCanvas);
var PieData = [];
for (var b in quizs[i].quests[j].reps) {
if (quizs[i].quests[j]['questId'] == quizs[i].quests[j].reps[b]["quest"]) {
PieData.push({
value: quizs[i].quests[j].reps[b]["stat"],
startAngle: 240,
color: hex(),
label: quizs[i].quests[j].reps[b]["rep"]
});
}
}
var pieOptions = {
segmentShowStroke: true,
segmentStrokeColor: '#fff',
segmentStrokeWidth: 1,
percentageInnerCutout: 0,
animationSteps: 100,
animationEasing: 'easeInSine',
animateRotate: true,
animateScale: false,
responsive: true,
maintainAspectRatio: true
};
pieChart.Doughnut(PieData, pieOptions);
});
}}
我知道问题出在函数和for循环上,但我不知道到底是什么,任何帮助都将得到感谢