This API provides you to build a pie chart more easily. All you need is your data which has one column for category and one column for corresponding numerical values. This software will create a pie chart with colored categories and their sizes will follow the values in numerical column.
When using, just follow the following format where d[0] equals categories and d[1] equals numerical values. Also please name your data as "data.csv"
var chart = pieChart()
.x(function(d) { return +d[0]; })
.y(function(d) { return +d[1]; });
d3.csv("data.csv", function(data) {
d3.select("#vis")
.datum(data)
.call(chart);
});
By doing this you will be able to create a simple pie chart. If you would like to change some features, you can use the following methods:
- Changing x values(categorical): chart.x(categories)
- Changing y values(numerical): chart.y(numbers)
- Changing the width: chart.width(w)
- Changing the height: chart.height(h)
- Changing the margins: chart.margin(m)
- Changing colors: chart.colors(c)
To give you an example of those methods, please see below.
var chart = pieChart().height(650); // changes height to 650.
Width and height accept a single integer, x and y accept sets of categories or numbers, margin accepts an object with margins, and colors accept a list of colors.
If you have any other questions, please let me know. Thank you.