我在 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>
顶部矩形没有出现,它似乎出现在菜单后面,我不知道为什么。任何人都可以帮忙吗?