jeudi 1 janvier 2015

Error in d3.js while drawing pie chart using json data


Vote count:

0




Error: mutating the [[Prototype]] of an object will cause your code to run very slowly; instead create the object with the correct initial [[Prototype]] value using Object.create d3.v3.min.js:3 Unexpected value translate(NaN,NaN) parsing transform attribute. d3.v3.min.js:1 TypeError: e is null


source code:



<!DOCTYPE html>
<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
<meta content="utf-8" http-equiv="encoding">
<html>
<head>
<title>D3 tutorial</title>
<script src="http://ift.tt/JmLP3T"></script>
</head>
<body>
<script>

var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height)
.append("g")
.attr("transform", "translate(" + width / 2 + "," + height / 2 + ")");

var width = 800,
height = 250,
radius = Math.min(width, height) / 2;

var color = d3.scale.ordinal()
.range(["#98abc5", "#8a89a6", "#7b6888", "#6b486b", "#a05d56", "#d0743c", "#ff8c00"]);

d3.json("mydata1.json",function (data) {


var arc = d3.svg.arc()
.outerRadius(radius - 10)
.innerRadius(radius - 70);

var pie = d3.layout.pie()
.sort(null)
.value(function (d) {
return d.totalCrimes;
});

var g = svg.selectAll(".arc")
.data(data)
.enter().append("g")
.attr("class", "arc");

g.append("path")
.attr("d", arc)
.style("fill", function (d) {
return color(d.crimeType);
});

g.append("text")
.attr("transform", function (d) {
return "translate(" + arc.centroid(d) + ")";
})
.attr("dy", ".35em")
.style("text-anchor", "middle")
.text(function (d) {
return d.crimeType;
});
});
</script>
</body>
</html>


json data:



[
{"crimeType":"mip","totalCrimes":24},
{"crimeType":"theft","totalCrimes":558},
{"crimeType":"drugs","totalCrimes":81},{"crimeType":"arson","totalCrimes":3}
,{"crimeType":"assault","totalCrimes":80},
{"crimeType":"burglary","totalCrimes":49},
{"crimeType":"disorderlyConduct","totalCrimes":63},
{"crimeType":"mischief","totalCrimes":189},
{"crimeType":"dui","totalCrimes":107},
{"crimeType":"resistingArrest","totalCrimes":11},
{"crimeType":"sexCrimes","totalCrimes":24},
{"crimeType":"other","totalCrimes":58}
];


asked 33 secs ago







Error in d3.js while drawing pie chart using json data

Aucun commentaire:

Enregistrer un commentaire