Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Daniel Čupak
6,602 PointsD3.JS code not working
So I have found this page about D3.JS but I cannot make the code shown there work...
code:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Step 1 - A Basic Pie Chart</title> <link rel="stylesheet" href="normalize.css"> </head> <body> <div id="chart"></div> <script src="d3.v3.min.js"></script> <script> (function(d3) { 'use strict';
var dataset = [
{ label: 'Abulia', count: 10 },
{ label: 'Betelgeuse', count: 20 },
{ label: 'Cantaloupe', count: 30 },
{ label: 'Dijkstra', count: 40 }
];
var width = 360;
var height = 360;
var radius = Math.min(width, height) / 2;
var color = d3.scale.category20b();
var svg = d3.select('#chart')
.append('svg')
.attr('width', width)
.attr('height', height)
.append('g')
.attr('transform', 'translate(' + (width / 2) +
',' + (height / 2) + ')');
var arc = d3.svg.arc()
.outerRadius(radius);
var pie = d3.layout.pie()
.value(function(d) { return d.count; })
.sort(null);
var path = svg.selectAll('path')
.data(pie(dataset))
.enter()
.append('path')
.attr('d', arc)
.attr('fill', function(d, i) {
return color(d.data.label);
});
})(window.d3);
</script>
</body> </html>
page: http://zeroviscosity.com/d3-js-step-by-step/step-1-a-basic-pie-chart
Thanks!
1 Answer
Daniel Čupak
6,602 PointsI did not know I had to fire up XAMPP...that solved it...embarassing