score:1
I was able to render the second chart by flattening the existing JSON. See the below source code.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>D3 Donut Chart</title>
</head>
<meta charset="utf-8">
<style>
body {
font: 10px sans-serif;
}
.arc path {
stroke: #fff;
}
</style>
<body>
<script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script>
<script>
var sampleSet = {
"title": "DummyData",
"data": [
{
"origin": "Disk_Pool_1",
"volumeName": "Vol1",
"usage": 15,
"type": "thick"
},
{
"origin": "Disk_Pool_1",
"volumeName": "Vol2",
"usage": 25,
"type": "thick"
},
{
"origin": "Disk_Pool_1",
"volumeName": "Repo_06",
"usage": 50,
"type": "thick"
},
{
"origin": "Repo_06",
"volumeName": "thinVol1",
"usage": 10,
"max": 20,
"type": "thin"
},
{
"origin": "Repo_06",
"volumeName": "thinVol2",
"usage": 10,
"max": 30,
"type": "thin"
},
{
"origin": "Repo_06",
"volumeName": "freespace",
"usage": 20,
"max": 40,
"type": "freespace"
}
]
};
var m = 10, r = 100, z = d3.scale.category20c();
var pie = d3.layout.pie()
.value(function (d) {
return +d.usage;
})
.sort(function (a, b) {
return b.usage - a.usage;
});
var arc = d3.svg.arc()
.innerRadius(r / 2)
.outerRadius(r);
var disks = d3.nest()
.key(function (d) {
return d.origin;
})
.entries(sampleSet.data);
var svg = d3.select("body").selectAll("div")
.data(disks)
.enter().append("div")
.style("display", "inline-block")
.style("width", (r + m) * 2 + "px")
.style("height", (r + m) * 2 + "px")
.append("svg:svg")
.attr("width", (r + m) * 2)
.attr("height", (r + m) * 2)
.append("svg:g")
.attr("transform", "translate(" + (r + m) + "," + (r + m) + ")");
svg.append("svg:text")
.attr("dy", ".35em")
.attr("text-anchor", "middle")
.text(function (d) {
return d.key;
});
var g = svg.selectAll("g")
.data(function (d) {
return pie(d.values);
})
.enter().append("svg:g");
g.append("svg:path")
.attr("d", arc)
.style("fill", function (d) {
return z(d.data.volumeName);
})
.append("svg:title")
.text(function (d) {
return d.data.volumeName + ": " + d.data.usage;
});
g.filter(function (d) {
return d.endAngle - d.startAngle > .2;
}).append("svg:text")
.attr("dy", ".35em")
.attr("text-anchor", "middle")
.attr("transform", function (d) {
return "translate(" + arc.centroid(d) + ")rotate(" + angle(d) + ")";
})
.text(function (d) {
return d.data.volumeName + ": " + d.data.usage;
});
function angle(d) {
var a = (d.startAngle + d.endAngle) * 90 / Math.PI - 90;
return a > 90 ? a - 180 : a;
}
</script>
</body>
</html>
Source: stackoverflow.com
Related Query
- D3 drawing a second donut chart from nested JSON
- D3.JS Grouped Donut Chart from JSON
- D3.js - Create multi-ring donut chart dataset from JSON
- modifying d3.js donut chart to read from json array
- Create donut chart using nested data from d3.nest()
- Drawing a Multi Line Chart from nested data
- D3 multi-series line chart from pivoted JSON
- Creating nested Json structure with multiple key values in Python from Json
- Convert a d3 chart to load data from json inside a variable
- D3: Create a grouped bar chart from json objects
- D3.js update bar chart from json
- prevent d3 donut chart from sorting automatically
- d3js pie graph from jquery ajax - correlating json keys and values on the chart
- d3 multiline chart from JSON
- D3.js : How to read data from JSON in Grouped Bar Chart
- D3 Grouped Bar Chart with JSON nested data
- D3 nodes and links from JSON with nested arrays of children
- grouped bar chart from JSON data instead of CSV
- Using dc.js on nested JSON to create bar chart
- D3 nested select and sibling from json property of object
- D3.js moving from tsv to json with nested array
- How do you call data from nested JSON array using d3?
- Javascript d3 pie chart doesn't pull data from JSON file with list of dictionaries
- Prepare nested JSON data for D3 stacked bar chart
- How to load data to D3 chart from JSON when there are only tuples
- c3js Stacked Bar chart from json array
- D3 dashboard chart data bind from json or csv
- How to tell d3js that this half donut chart should fill values from left to right corner
- C3, D3 Chart with nested JSON Data
- How to add a second tooltip, with data, from a data driven d3 chart
More Query from same tag
- Keep SVG centred while using media queries
- Anomalous mouseover handling with D3.js in Internet Explorer 11
- How to transition D3 axis without tick text attribute reset?
- how can I set a height and width for this map in d3.js
- Issues with adding a link via mouse click to two nodes in force directed graph
- Count number of items in an array of objects with a specific property value (JavaScript)
- How to fix undefined issue on d3 tooltip?
- Ghost image on drag disappears when using d3.behavior.drag()
- How to draw many functions with a loop in D3?
- Color grouped bar chart based on comparison of numbers d3
- D3 Stacked bar chart with different stack level
- Adding D3 usmap v3 to React
- d3.js draw multiple parallel paths from one path
- Circles disappear on mobile, when map is zoomed
- Which format to choose for storing and displaying data in D3.js dynamically?
- Converting shapefiles and geoJson to TopoJson and/or using geo2topo
- Transitions and text attributes in a div in D3.js
- Nested jQuery Accordions using d3
- Limit drag area each node d3.js
- Unable to append a rect to a SVG using d3
- D3 Multiline Chart with Tooltip Transition Issue
- d3 line graph using csv
- D3 Donut chart projected to sphere/globe
- How to load multiple csv files and use them mixed with each other
- change y axis labels in nvd3 scatter-chart
- Unable to set the right d3.extent accessor
- Get id of checkboxes when checked using D3
- Fix the x-axis of D3 JS and add dotted lines to the y-axis and x-axis
- simple d3.js relationship graph from mysql table
- Manipulate SVG with javascript?