I am working on a pie chart today in D3 (fun!).
Alright, the issue I am having is the colours aren't being assigned properly.
Here's the jsfiddle:
https://jsfiddle.net/zh34ud25/5/
Most(?) relevant code:
var color = d3.scale.ordinal()
.range(["#71b2b9", "#dcdcdc"]);
color.domain(d3.keys(dataUnbilledRevenue[0].values[0]).filter(function(key) {
if (key === 'Unbilled_Revenue'
|| key === 'Billed_Revenue') {
return key
}
}));
// This returns the data into two separate objects which can be graphed.
// In this case, Amount and Quantity.
var datasets = color.domain().map(function(name) {
return {
name: name,
values: dataUnbilledRevenue.map(function(d) {
return {
Value: +d.values[0][name]
};
})
};
});
This is simple, doing this will give the colors to pie:
pieValues.append("path")
.attr("d", arc)
.attr('class', 'pie-point')
.style("fill", function(d) {
return color(d.data.name)
})
working code here
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments