我在d3
中创建了一个条形图 $(document).ready(function(){
var data = [0,20,10,60,100,75,40,20,25,2];
var width = 300;
var height = 300;
var padding = 1;
var userPerformanceChart = d3.select("#userPerformanceChart").append("svg").attr("width",width).attr("height",height);
userPerformanceChart.selectAll("rect")
.data(data)
.enter()
.append("rect")
.attr("x",40)
.attr("y",function(d,i){
console.log("function being called");
return i*(width/data.length);
})
.attr("width",function(d){
return d;
})
.attr("height",width/data.length - padding)
.attr("fill",function(d){
return "rgb(0," + (d*2) + ",0)";
});
这是我的HTML -
<div class="clear"></div>
<div class="horizontalMenu clear" id="quizSummaryMenu">
<a href="#" class="quizSummaryLink" id="quizLink">Quiz</a>
<a href="#" class="quizSummaryLink" id="historyLink">Statistis</a>
<a href="#" class="quizSummaryLink" id="topScorersLink">Top Scorers</a>
<a href="#" class="quizSummaryLink" id="practiceModeLink">Practice Mode</a>
<a href="#" class="quizSummaryLink" id="editQuizLink">Edit Quiz</a>
</div>
<div class="subContainer" id="quizDisplayContainer">
<div id="userPerformanceChart"></div>
</div>
顶部矩形没有出现,它似乎出现在菜单后面,我不知道为什么。有人可以帮忙吗?
答案 0 :(得分:2)
实际上顶栏存在......由于数据数组的第一个索引为0,第一个柱的宽度计算为零...