d3甜甜圈图不渲染 [英] d3 Donut chart does not render
本文介绍了d3甜甜圈图不渲染的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试执行从 http://bl.ocks.org/mbostock引用的甜甜圈图/3887193 .当我执行它时,图表不会呈现,并且显示空白页.请帮助.两天后我的头了.感谢帮助.
I'm trying to execute the Donut chart referred from http://bl.ocks.org/mbostock/3887193 . When i execute it , the chart does not render and it shows me blank page .Please help . Banging my head from two days . Appreciate the help.
<apex:includeScript value="{!URLFOR($Resource.jquery1)}"/>
<apex:includeScript value="{!URLFOR($Resource.D3)}"/>
<apex:includeScript value="{!URLFOR($Resource.nvD3)}"/>
<apex:includeScript value="{!URLFOR($Resource.data)}"/>
<!--<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.3.3/d3.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/nvd3/1.0.0-beta/nv.d3.min.js"></script> -->
<script>
var width = 960,
height = 500,
radius = Math.min(width, height) / 2;
var color = d3.scale.ordinal()
.range(["#98abc5", "#8a89a6", "#7b6888", "#6b486b", "#a05d56", "#d0743c", "#ff8c00"]);
var arc = d3.svg.arc()
.outerRadius(radius - 10)
.innerRadius(0);
var pie = d3.layout.pie().sort(null)
.x(function(d){return d.age;});
.y(function(d){return d.population;});
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height)
.append("g")
.attr("transform", "translate(" + width / 2 + "," + height / 2 + ")");
d3.csv("data.csv", function(error, data) {
console.log(data);
data.forEach(function(d) {
if (isNaN(+d.age)) console.log(d.population);
d.age = +d.age;
d.population = +d.population;
});
var g = svg.selectAll(".arc")
.data(pie(data))
.enter().append("g")
.attr("class", "arc");
g.append("path")
.attr("d", arc)
.style("fill", function(d) { return color(d.data.age); });
g.append("text")
.attr("transform", function(d) { return "translate(" + arc.centroid(d) + ")"; })
.attr("dy", ".35em")
.style("text-anchor", "middle")
.text(function(d) { return d.data.age; });
});
</script>
</apex:page>
推荐答案
首先,您应该检查对d3-library的引用,我在那儿遇到了错误.尝试使用
first, you should check the reference to the d3-library, i'm getting an error there. try using
<script src="http://d3js.org/d3.v3.min.js" type="text/javascript"></script>
第二步,必须将body-div放置在脚本之前,因此代码的开始应类似于
second, you must position your body-div before the script, so the start of your code should look like
<div id="body" height="50%" width="500px" ></div>
<script>
var width = 960,
height = 500,
radius = Math.min(width, height) / 2;
//...and so on
这篇关于d3甜甜圈图不渲染的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文