score:1
Accepted answer
Here's a code snippet with the requirement fulfilled.
var dataset = {
hddrives: [90,10],
};
var width = 460,
height = 300,
radius = Math.min(width, height) / 2;
var color = d3.scale.ordinal()
.range(["#2DA7E2", "red"]);
var pie = d3.layout.pie()
.sort(null);
var arc = d3.svg.arc()
.innerRadius(radius - 100)
.outerRadius(radius - 70);
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height)
.append("g")
.attr("transform", "translate(" + width / 2 + "," + height / 2 + ")");
//Draw the Circle
svg.append("circle")
.attr("cx", 0)
.attr("cy", 0)
.attr("r", 65)
.attr("fill", "#F1F1F1");
var path = svg.selectAll("path")
.data(pie(dataset.hddrives))
.enter().append("path")
.attr("class", "arc")
.attr("fill", function(d, i) { return color(i); })
.attr("d", arc);
svg.append("text")
.attr("dy", "0em")
.style("text-anchor", "middle")
.attr("class", "inside")
.text(function(d) { return '56%'; });
svg.append("text")
.attr("dy", "1.5em")
.style("text-anchor", "middle")
.attr("class", "data")
.text(function(d) { return '53GB / 123GB'; });
.inside {
font-family: 'Roboto Condensed', sans-serif;
font-size:30px;
}
.data {
font-size:12px;
color:grey;
}
.arc {
stroke: #fff;
}
.
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.3.7/d3.min.js"></script>
Code changes:
Changed the color scale's range to
.range(["#2DA7E2", "red"]);
With this,
.attr("fill", function(d, i) { return color(i); })
will find appropriate color based oni
. (as it was just one color before, the color was being repeated).Got rid the opacity of the arcs i.e. removed the following line (as this was causing the "left-over" part to have an opacity of 0)
.style("opacity", function(d, i) { return i == dataset.hddrives.length - 1 ? 0 : 1; })
Hope this helps. :)
Source: stackoverflow.com
Related Query
- D3 dougnut chart customizing circle color
- Fill same line color in to circle on Multi Line chart when mouse over and remove color from circle when mouse out
- how to change the color of circle to back with original color on clicking of another circle in D3 Js chart
- How to set text color for my d3 chart title?
- How to customize color in pie chart of NVD3
- D3 Sankey chart using circle node instead of rectangle node
- Change label text color in row chart
- nvd3.js - unable to change color of line in line chart
- Same color is showing in different arc of d3 pie chart
- NVD3 Scatter Chart Circle Radius
- How to make a C3 donut chart to a semi circle or a half donut chart in typescript?
- How to set color of D3 Zoom Packed Circle children
- 2 arrays one of values one of colors make D3 bar chart have color at same index of value
- How to remove the outer circle in D3 bubble chart
- d3 change bar chart color according to height
- d3v4 checkout chart - making sure the color scheme is correct for the legend and circles
- Color Specific Links on D3 Sankey Chart
- add circle in a spiral chart with d3js with line connecting to center
- How to change color of donut chart created using d3.js?
- How to overlay color in d3 area chart
- How to change color of line in line chart using dimple.js?
- dimple.js Show X Axis label, but if "value" is null don't place a circle on chart
- How do I color labels for my pie chart in D3?
- Migrating d3.v3 to d3.v4 in circle force layout chart
- How can you color each circle in the D3 circle pack layout
- Adding background color in d3 js bar chart using data values
- Assign specific color to specific segment in D3 Pie Chart
- Changing color range in a d3 reusable donut chart depending on the number of data points
- D3+Leaflet Circle SVG element not displaying any color
- is it possible to tweak the d3 bubble chart to obtain the bubbles at scattered positions instead of a circle pack?
More Query from same tag
- How to pass a variable as a string to locate a file to be read by d3
- Testing d3 inside of an angular service
- How do I get the width of a bar including padding in d3?
- D3 Path with random colored lines
- Dispatch custom event with namespace
- Alternative for JSON_ENCODE to be called in d3js graph
- how to change x axis in D3?
- What does D3.js "Data" function expect as its first argument?
- d3js v4 Create filter function from node values that include arrays
- Ideas for distinct layering of stacked graph in D3.js
- d3: Adding the min/max/mean lines to an existing linechart
- Creating scatter points on a multi line chart
- How do I create a dynamic domain?
- Updating a layout.pack in d3.js
- D3 Integration with Angular: "Error: Invalid value for <rect> attribute x"
- load d3 with amd using dojo
- d3 dynamic url based on array values
- d3.js tree - How to set Y depth of a specific level?
- How to implement D3 lasso plugin with Angular 2 and Typescript
- Extend D3 Chart to add tooltip from HTML page
- How to vary the start and end angles for my d3.js diagram?
- What makes grid lines visible?
- d3.js CoffeeScript class execution context
- removing magic number in drawing rows of svg rect
- How to apply (and change) classes to an SVG elements that already exist
- Appending axis to a D3 chart
- Parsing header row with dates when importing csv data
- Seven ate nine: Why is my index 8 being skipped in this d3 selection?
- d3.js traverse hierarchical data
- Position relative is not working in Safari 11 Dagre-d3 svg