score:2
Accepted answer
Here my solution:
var data = [
{
institution: [53245, 28479, 19697, 24037, 40245]
},
{
institution: [45, 9, 127, 37, 11]
},
{
institution: [3245, 88479, 45697, 1037, 77245]
}
];
var width = 200;
var height = 200;
var radius = Math.min(width, height) / 4;
var r = radius;
var textOffset=5;
var colours = ['#ffc400','#e53517','#7ab51d','#009fda','#c2c2c2'];
for (index = 0; index < data.length; ++index) {
var pie = d3.layout.pie().sort(null);
var arc = d3.svg.arc().innerRadius(radius - 30).outerRadius(radius - 5);
var svg = d3.select("body").append("svg:svg")
.attr("width", width)
.attr("height", height)
.append("g")
.attr("transform", "translate(" + width / 2 + "," + height / 2 + ")");
var piedata=pie(data[index].institution);
var ticks = svg.selectAll("line").data(piedata).enter().append("line");
ticks.attr("x1", 0)
.attr("x2", 0)
.attr("y1", -radius+4)
.attr("y2", -radius-2)
.attr("stroke", "gray")
.attr("transform", function(d) {
return "rotate(" + (d.startAngle+d.endAngle)/2 * (180/Math.PI) + ")";
});
var labels = svg.selectAll("text").data(piedata).enter().append("text");
labels.attr("class", "value")
.attr("transform", function(d) {
var dist=radius+15;
var winkel=(d.startAngle+d.endAngle)/2;
var x=dist*Math.sin(winkel);
var y=-dist*Math.cos(winkel);
return "translate(" + x + "," + y + ")";
})
.attr("dy", "0.35em")
.attr("text-anchor", "middle")
.text(function(d){
return d.value;
});
var path = svg.selectAll("path")
.data(piedata)
.enter().append("path")
.attr("fill", function(d, i) { return colours[i]; })
.attr("d", arc);
}
Source: stackoverflow.com
Related Query
- Donut chart with tick mark lines (d3)
- MultiBar chart with nvd3 / d3 only shows labels for every other tick on the x-axis. How can I get them all to show up?
- Special donut chart with different rings/arcs for positive and negative values
- Donut chart with partial ring around
- Create an interactive chart (zoom/pan) with lines using D3
- Align lines and dots with x-axis values in line chart
- D3 - Placing labels and lines on a half pie/half donut chart
- Only end tick mark is showing on dc.js bubble chart
- d3 donut chart with labels
- Is it possible to insert an icon in the arc of a donut chart with D3?
- Incomplete line chart with missing points and missing lines
- How do I split labels for my donut chart to multiple lines using d3.js?
- D3.js v4 major & minor tick lines with y-Axis zero as the centered baseline
- C3.js horizontal bar chart - Highlight a specific x-axis tick together with bar
- Tooltips for multiple lines chart with legend click d3.js
- D3.js how to make the lines not go inside the arc of a donut chart
- D3 Donut Chart with Connectors
- Why does my bar chart using scaleBand not line up with my tick marks?
- dc.js - Chart not rendering (single row bar chart - horizontal row), with the exception of legend, axes and tick marks/values (which do render)
- tick mark line styling with d3.js
- D3 donut chart based on seasons with fixed labels
- D3.js Giving a legend to a donut chart with inner rings
- d3.js multi lines chart using dataset with nested object
- d3 donut chart with curved labels
- how to animate the labels to flow with the donut chart with a start angle and end angle in d3.
- fill points on the multi-line chart with the same color as lines
- D3 Donut Chart Enter with Transition
- D3js chart with 2 lines - display only lines
- d3.js bar chart with target lines
- trying to create a donut chart with labels inside the curve using d3.js
More Query from same tag
- Put text in the middle of a circle using. d3.js
- Hide and show svg element with transition
- DC js with large dataset and many dimensions
- d3.js Multi level pie chart with per-slice offset start angles
- Radar chart library similar to nv-d3.js
- Google maps with d3.js (v5) overlay
- Using D3.js to create a simple treemap
- How to control Brush transaction effect in dc.js?
- Replace legend on the c3.js graph
- Custom scale in d3
- D3.js Rendering topoJSON in multiple charts
- d3 drag node behaviour doesn't work
- d3 - Rotate text elements in an array
- D3 Error: NotFoundError: Node was not found
- Correct Way to Import D3.js into an Angular 2 Application
- Formatting Highcharts labels with a callback function (Formatter)
- d3 resize issue browsers
- JSON call error with d3js
- How to make a summary list of one column in a large CSV file?
- How to load a CSV and a JSON file and combine both datsets to one dataset using d3.json, d3.csv and d3.zip
- Unable to align ticks with d3.js
- D3 Inversion of mouse position to closest tick value on the X-axis
- Linear + threshold unified scale
- Update zoom state in d3 v4 after manually setting translation and scale
- Using D3 and blobs to render svg to image
- how to set collision between nodes and other svg element in D3.js
- D3Plus Header Modification
- nvd3 add nvd3 chart dom element from code
- How to allow Duplicate Tick Labels in Plotly?
- D3.js bar charts not refreshing