D3 Line Chart not populating; what's missing? - d3.js

I am trying to sum up values in a csv and populate it using a line chart (Current team strength across months). Now, I am not getting any errors, & neither am getting the chart populated. Can't seem to figure out what is missing.
Here is my code:
<!DOCTYPE html>
<meta charset="utf-8">
<style> /* set the CSS */
body { font: 12px Arial;}
.line {
stroke: blue;
fill:none;
stroke-width: 4;
}
.axis path,
.axis line {
fill: none;
stroke: black;
shape-rendering: crispEdges;
}
.axis text {
font-size: 10px;
font-family: sans-serif;
}
.text-label {
font-size: 10px;
font-family: sans-serif;
}
</style>
<body>
<!-- load the d3.js library -->
<script src="http://d3js.org/d3.v3.min.js"></script>
<script>
// Set the dimensions of the canvas / graph
var margin = {top: 30, right: 20, bottom: 30, left: 50},
width = 600 - margin.left - margin.right,
height = 270 - margin.top - margin.bottom;
// Parse the date / time
var parseDate = d3.time.format("%m/%d/%Y").parse;
// Set the ranges
var x = d3.time.scale().range([0, width]);
var y = d3.scale.linear().range([height, 0]);
// Define the axes
var xAxis = d3.svg.axis().scale(x)
.orient("bottom").ticks(5);
var yAxis = d3.svg.axis().scale(y)
.orient("left").ticks(5);
d3.csv("Test.csv", function(error, data) {
if (error) throw error;
// Not yet using filtering
var filter = data.filter(function(d){
return (d.Head == 'People' && d.Measure == 'Current Team')
});
var nested = d3.nest()
.key(function(d) {return d.Time_Period;})
.rollup(function(d) {
return {
line1: d3.sum(d, function(e) { return e.Value; })
};
//console.log(line1);
})
.entries(data);
console.log(nested);
x.domain(d3.extent(nested, function(d) { return d.key; }));
y.domain(d3.extent(nested, function(d) { return d.values.line1; }));
// Adds the svg canvas
var svg = d3.select("body").append("svg");
svg.append("g")
.attr("class", "x axis")
.attr("transform", "translate(0," + height + ")")
.call(xAxis);
svg.append("g")
.attr("class", "y axis")
.call(yAxis)
.append("text")
.attr("transform", "rotate(-90)")
.attr("y", 6)
.attr("dy", ".71em")
.style("text-anchor", "end")
.text("Price ($)");
var line_1 = d3.svg.line()
.x(function(d) { console.log(parseDate(d.key));return parseDate(d.key); })
.y(function(d) { console.log(d.values.line1);return d.values.line1; });
console.log(line_1.x.value);
svg.append("path")
.datum(nested)
.attr("class", "line")
.attr("d", line_1)
.style("stroke", "steelblue")
.attr("fill", "none")
.attr("stroke-width", 4.8)
.attr("stroke-opacity", 0.0001)
.transition().duration(2000)
.attr("stroke-opacity", 1)
.attr("stroke-width", 2.8);
});
</script>
<Test.csv>
[
{
"RU": "IN",
"Head": "People",
"Industry": "-",
"Practice": "Reporting & Vizualization",
"Value": "6",
"Measure": "Current Team",
"Time_Period": "4/1/2016",
"Unit": "Count"
},
{
"RU": "IN",
"Head": "People",
"Industry": "-",
"Practice": "Data Integration",
"Value": "5",
"Measure": "Current Team",
"Time_Period": "4/1/2016",
"Unit": "Count"
},
{
"RU": "US",
"Head": "People",
"Industry": "-",
"Practice": "Reporting & Vizualization",
"Value": "0",
"Measure": "Current Team",
"Time_Period": "4/1/2016",
"Unit": "Count"
},
{
"RU": "US",
"Head": "People",
"Industry": "-",
"Practice": "Data Integration",
"Value": "0",
"Measure": "Current Team",
"Time_Period": "4/1/2016",
"Unit": "Count"
},
{
"RU": "IN",
"Head": "People",
"Industry": "-",
"Practice": "Reporting & Vizualization",
"Value": "6",
"Measure": "New Joinees",
"Time_Period": "4/1/2016",
"Unit": "Count"
},
{
"RU": "IN",
"Head": "People",
"Industry": "-",
"Practice": "Data Integration",
"Value": "5",
"Measure": "New Joinees",
"Time_Period": "4/1/2016",
"Unit": "Count"
},
{
"RU": "US",
"Head": "People",
"Industry": "-",
"Practice": "Reporting & Vizualization",
"Value": "0",
"Measure": "New Joinees",
"Time_Period": "4/1/2016",
"Unit": "Count"
},
{
"RU": "US",
"Head": "People",
"Industry": "-",
"Practice": "Data Integration",
"Value": "0",
"Measure": "New Joinees",
"Time_Period": "4/1/2016",
"Unit": "Count"
},
{
"RU": "IN",
"Head": "People",
"Industry": "-",
"Practice": "Reporting & Vizualization",
"Value": "0",
"Measure": "Planned Team",
"Time_Period": "4/1/2016",
"Unit": "Count"
},
{
"RU": "IN",
"Head": "People",
"Industry": "-",
"Practice": "Data Integration",
"Value": "0",
"Measure": "Planned Team",
"Time_Period": "4/1/2016",
"Unit": "Count"
},
{
"RU": "US",
"Head": "People",
"Industry": "-",
"Practice": "Reporting & Vizualization",
"Value": "0",
"Measure": "Planned Team",
"Time_Period": "4/1/2016",
"Unit": "Count"
},
{
"RU": "US",
"Head": "People",
"Industry": "-",
"Practice": "Data Integration",
"Value": "0",
"Measure": "Planned Team",
"Time_Period": "4/1/2016",
"Unit": "Count"
},
{
"RU": "IN",
"Head": "People",
"Industry": "-",
"Practice": "Reporting & Vizualization",
"Value": "6",
"Measure": "Current Team",
"Time_Period": "5/1/2016",
"Unit": "Count"
},
{
"RU": "IN",
"Head": "People",
"Industry": "-",
"Practice": "Data Integration",
"Value": "5",
"Measure": "Current Team",
"Time_Period": "5/1/2016",
"Unit": "Count"
},
{
"RU": "US",
"Head": "People",
"Industry": "-",
"Practice": "Reporting & Vizualization",
"Value": "0",
"Measure": "Current Team",
"Time_Period": "5/1/2016",
"Unit": "Count"
},
{
"RU": "US",
"Head": "People",
"Industry": "-",
"Practice": "Data Integration",
"Value": "0",
"Measure": "Current Team",
"Time_Period": "5/1/2016",
"Unit": "Count"
},
{
"RU": "IN",
"Head": "People",
"Industry": "-",
"Practice": "Reporting & Vizualization",
"Value": "6",
"Measure": "New Joinees",
"Time_Period": "5/1/2016",
"Unit": "Count"
},
{
"RU": "IN",
"Head": "People",
"Industry": "-",
"Practice": "Data Integration",
"Value": "5",
"Measure": "New Joinees",
"Time_Period": "5/1/2016",
"Unit": "Count"
},
{
"RU": "US",
"Head": "People",
"Industry": "-",
"Practice": "Reporting & Vizualization",
"Value": "0",
"Measure": "New Joinees",
"Time_Period": "5/1/2016",
"Unit": "Count"
},
{
"RU": "US",
"Head": "People",
"Industry": "-",
"Practice": "Data Integration",
"Value": "0",
"Measure": "New Joinees",
"Time_Period": "5/1/2016",
"Unit": "Count"
},
{
"RU": "IN",
"Head": "People",
"Industry": "-",
"Practice": "Reporting & Vizualization",
"Value": "0",
"Measure": "Planned Team",
"Time_Period": "5/1/2016",
"Unit": "Count"
},
{
"RU": "IN",
"Head": "People",
"Industry": "-",
"Practice": "Data Integration",
"Value": "0",
"Measure": "Planned Team",
"Time_Period": "5/1/2016",
"Unit": "Count"
},
{
"RU": "US",
"Head": "People",
"Industry": "-",
"Practice": "Reporting & Vizualization",
"Value": "0",
"Measure": "Planned Team",
"Time_Period": "5/1/2016",
"Unit": "Count"
},
{
"RU": "US",
"Head": "People",
"Industry": "-",
"Practice": "Data Integration",
"Value": "0",
"Measure": "Planned Team",
"Time_Period": "5/1/2016",
"Unit": "Count"
},
{
"RU": "IN",
"Head": "People",
"Industry": "-",
"Practice": "Reporting & Vizualization",
"Value": "6",
"Measure": "Current Team",
"Time_Period": "6/1/2016",
"Unit": "Count"
},
{
"RU": "IN",
"Head": "People",
"Industry": "-",
"Practice": "Data Integration",
"Value": "5",
"Measure": "Current Team",
"Time_Period": "6/1/2016",
"Unit": "Count"
},
{
"RU": "US",
"Head": "People",
"Industry": "-",
"Practice": "Reporting & Vizualization",
"Value": "0",
"Measure": "Current Team",
"Time_Period": "6/1/2016",
"Unit": "Count"
},
{
"RU": "US",
"Head": "People",
"Industry": "-",
"Practice": "Data Integration",
"Value": "0",
"Measure": "Current Team",
"Time_Period": "6/1/2016",
"Unit": "Count"
},
{
"RU": "IN",
"Head": "People",
"Industry": "-",
"Practice": "Reporting & Vizualization",
"Value": "6",
"Measure": "New Joinees",
"Time_Period": "6/1/2016",
"Unit": "Count"
},
{
"RU": "IN",
"Head": "People",
"Industry": "-",
"Practice": "Data Integration",
"Value": "5",
"Measure": "New Joinees",
"Time_Period": "6/1/2016",
"Unit": "Count"
},
{
"RU": "US",
"Head": "People",
"Industry": "-",
"Practice": "Reporting & Vizualization",
"Value": "0",
"Measure": "New Joinees",
"Time_Period": "6/1/2016",
"Unit": "Count"
},
{
"RU": "US",
"Head": "People",
"Industry": "-",
"Practice": "Data Integration",
"Value": "0",
"Measure": "New Joinees",
"Time_Period": "6/1/2016",
"Unit": "Count"
},
{
"RU": "IN",
"Head": "People",
"Industry": "-",
"Practice": "Reporting & Vizualization",
"Value": "0",
"Measure": "Planned Team",
"Time_Period": "6/1/2016",
"Unit": "Count"
},
{
"RU": "IN",
"Head": "People",
"Industry": "-",
"Practice": "Data Integration",
"Value": "0",
"Measure": "Planned Team",
"Time_Period": "6/1/2016",
"Unit": "Count"
},
{
"RU": "US",
"Head": "People",
"Industry": "-",
"Practice": "Reporting & Vizualization",
"Value": "0",
"Measure": "Planned Team",
"Time_Period": "6/1/2016",
"Unit": "Count"
},
{
"RU": "US",
"Head": "People",
"Industry": "-",
"Practice": "Data Integration",
"Value": "0",
"Measure": "Planned Team",
"Time_Period": "6/1/2016",
"Unit": "Count"
},
{
"RU": "IN",
"Head": "People",
"Industry": "-",
"Practice": "Reporting & Vizualization",
"Value": "6",
"Measure": "Current Team",
"Time_Period": "7/1/2016",
"Unit": "Count"
},
{
"RU": "IN",
"Head": "People",
"Industry": "-",
"Practice": "Data Integration",
"Value": "5",
"Measure": "Current Team",
"Time_Period": "7/1/2016",
"Unit": "Count"
},
{
"RU": "US",
"Head": "People",
"Industry": "-",
"Practice": "Reporting & Vizualization",
"Value": "0",
"Measure": "Current Team",
"Time_Period": "7/1/2016",
"Unit": "Count"
},
{
"RU": "US",
"Head": "People",
"Industry": "-",
"Practice": "Data Integration",
"Value": "0",
"Measure": "Current Team",
"Time_Period": "7/1/2016",
"Unit": "Count"
},
{
"RU": "IN",
"Head": "People",
"Industry": "-",
"Practice": "Reporting & Vizualization",
"Value": "6",
"Measure": "New Joinees",
"Time_Period": "7/1/2016",
"Unit": "Count"
},
{
"RU": "IN",
"Head": "People",
"Industry": "-",
"Practice": "Data Integration",
"Value": "5",
"Measure": "New Joinees",
"Time_Period": "7/1/2016",
"Unit": "Count"
},
{
"RU": "US",
"Head": "People",
"Industry": "-",
"Practice": "Reporting & Vizualization",
"Value": "0",
"Measure": "New Joinees",
"Time_Period": "7/1/2016",
"Unit": "Count"
},
{
"RU": "US",
"Head": "People",
"Industry": "-",
"Practice": "Data Integration",
"Value": "0",
"Measure": "New Joinees",
"Time_Period": "7/1/2016",
"Unit": "Count"
},
{
"RU": "IN",
"Head": "People",
"Industry": "-",
"Practice": "Reporting & Vizualization",
"Value": "0",
"Measure": "Planned Team",
"Time_Period": "7/1/2016",
"Unit": "Count"
},
{
"RU": "IN",
"Head": "People",
"Industry": "-",
"Practice": "Data Integration",
"Value": "0",
"Measure": "Planned Team",
"Time_Period": "7/1/2016",
"Unit": "Count"
},
{
"RU": "US",
"Head": "People",
"Industry": "-",
"Practice": "Reporting & Vizualization",
"Value": "0",
"Measure": "Planned Team",
"Time_Period": "7/1/2016",
"Unit": "Count"
},
{
"RU": "US",
"Head": "People",
"Industry": "-",
"Practice": "Data Integration",
"Value": "0",
"Measure": "Planned Team",
"Time_Period": "7/1/2016",
"Unit": "Count"
}
]

I made following updates in your code and it seems to be working fine in the snippet.
Position and size of SVG container.
Parsing of x axis date values.
The values in your question was showing a straight line. I have used some random values for a different look.
var data = [{
"RU": "IN",
"Head": "People",
"Industry": "-",
"Practice": "Reporting & Vizualization",
"Value": "6",
"Measure": "Current Team",
"Time_Period": "4/1/2016",
"Unit": "Count"
}, {
"RU": "IN",
"Head": "People",
"Industry": "-",
"Practice": "Data Integration",
"Value": "5",
"Measure": "Current Team",
"Time_Period": "4/1/2016",
"Unit": "Count"
}, {
"RU": "US",
"Head": "People",
"Industry": "-",
"Practice": "Reporting & Vizualization",
"Value": "0",
"Measure": "Current Team",
"Time_Period": "4/1/2016",
"Unit": "Count"
}, {
"RU": "US",
"Head": "People",
"Industry": "-",
"Practice": "Data Integration",
"Value": "0",
"Measure": "Current Team",
"Time_Period": "4/1/2016",
"Unit": "Count"
}, {
"RU": "IN",
"Head": "People",
"Industry": "-",
"Practice": "Reporting & Vizualization",
"Value": "6",
"Measure": "New Joinees",
"Time_Period": "4/1/2016",
"Unit": "Count"
}, {
"RU": "IN",
"Head": "People",
"Industry": "-",
"Practice": "Data Integration",
"Value": "75",
"Measure": "New Joinees",
"Time_Period": "4/1/2016",
"Unit": "Count"
}, {
"RU": "US",
"Head": "People",
"Industry": "-",
"Practice": "Reporting & Vizualization",
"Value": "0",
"Measure": "New Joinees",
"Time_Period": "4/1/2016",
"Unit": "Count"
}, {
"RU": "US",
"Head": "People",
"Industry": "-",
"Practice": "Data Integration",
"Value": "0",
"Measure": "New Joinees",
"Time_Period": "4/1/2016",
"Unit": "Count"
}, {
"RU": "IN",
"Head": "People",
"Industry": "-",
"Practice": "Reporting & Vizualization",
"Value": "0",
"Measure": "Planned Team",
"Time_Period": "4/1/2016",
"Unit": "Count"
}, {
"RU": "IN",
"Head": "People",
"Industry": "-",
"Practice": "Data Integration",
"Value": "0",
"Measure": "Planned Team",
"Time_Period": "4/1/2016",
"Unit": "Count"
}, {
"RU": "US",
"Head": "People",
"Industry": "-",
"Practice": "Reporting & Vizualization",
"Value": "18",
"Measure": "Planned Team",
"Time_Period": "4/1/2016",
"Unit": "Cunt"
}, {
"RU": "US",
"Head": "People",
"Industry": "-",
"Practice": "Data Integration",
"Value": "15",
"Measure": "Planned Team",
"Time_Period": "4/1/2016",
"Unit": "Count"
}, {
"RU": "IN",
"Head": "People",
"Industry": "-",
"Practice": "Reporting & Vizualization",
"Value": "6",
"Measure": "Current Team",
"Time_Period": "5/1/2016",
"Unit": "Count"
}, {
"RU": "IN",
"Head": "People",
"Industry": "-",
"Practice": "Data Integration",
"Value": "5",
"Measure": "Current Team",
"Time_Period": "5/1/2016",
"Unit": "Count"
}, {
"RU": "US",
"Head": "People",
"Industry": "-",
"Practice": "Reporting & Vizualization",
"Value": "0",
"Measure": "Current Team",
"Time_Period": "5/1/2016",
"Unit": "Count"
}, {
"RU": "US",
"Head": "People",
"Industry": "-",
"Practice": "Data Integration",
"Value": "0",
"Measure": "Current Team",
"Time_Period": "5/1/2016",
"Unit": "Count"
}, {
"RU": "IN",
"Head": "People",
"Industry": "-",
"Practice": "Reporting & Vizualization",
"Value": "6",
"Measure": "New Joinees",
"Time_Period": "5/1/2016",
"Unit": "Count"
}, {
"RU": "IN",
"Head": "People",
"Industry": "-",
"Practice": "Data Integration",
"Value": "5",
"Measure": "New Joinees",
"Time_Period": "5/1/2016",
"Unit": "Count"
}, {
"RU": "US",
"Head": "People",
"Industry": "-",
"Practice": "Reporting & Vizualization",
"Value": "0",
"Measure": "New Joinees",
"Time_Period": "5/1/2016",
"Unit": "Count"
}, {
"RU": "US",
"Head": "People",
"Industry": "-",
"Practice": "Data Integration",
"Value": "0",
"Measure": "New Joinees",
"Time_Period": "5/1/2016",
"Unit": "Count"
}, {
"RU": "IN",
"Head": "People",
"Industry": "-",
"Practice": "Reporting & Vizualization",
"Value": "0",
"Measure": "Planned Team",
"Time_Period": "5/1/2016",
"Unit": "Count"
}, {
"RU": "IN",
"Head": "People",
"Industry": "-",
"Practice": "Data Integration",
"Value": "0",
"Measure": "Planned Team",
"Time_Period": "5/1/2016",
"Unit": "Count"
}, {
"RU": "US",
"Head": "People",
"Industry": "-",
"Practice": "Reporting & Vizualization",
"Value": "0",
"Measure": "Planned Team",
"Time_Period": "5/1/2016",
"Unit": "Count"
}, {
"RU": "US",
"Head": "People",
"Industry": "-",
"Practice": "Data Integration",
"Value": "0",
"Measure": "Planned Team",
"Time_Period": "5/1/2016",
"Unit": "Count"
}, {
"RU": "IN",
"Head": "People",
"Industry": "-",
"Practice": "Reporting & Vizualization",
"Value": "6",
"Measure": "Current Team",
"Time_Period": "6/1/2016",
"Unit": "Count"
}, {
"RU": "IN",
"Head": "People",
"Industry": "-",
"Practice": "Data Integration",
"Value": "5",
"Measure": "Current Team",
"Time_Period": "6/1/2016",
"Unit": "Count"
}, {
"RU": "US",
"Head": "People",
"Industry": "-",
"Practice": "Reporting & Vizualization",
"Value": "0",
"Measure": "Current Team",
"Time_Period": "6/1/2016",
"Unit": "Count"
}, {
"RU": "US",
"Head": "People",
"Industry": "-",
"Practice": "Data Integration",
"Value": "0",
"Measure": "Current Team",
"Time_Period": "6/1/2016",
"Unit": "Count"
}, {
"RU": "IN",
"Head": "People",
"Industry": "-",
"Practice": "Reporting & Vizualization",
"Value": "6",
"Measure": "New Joinees",
"Time_Period": "6/1/2016",
"Unit": "Count"
}, {
"RU": "IN",
"Head": "People",
"Industry": "-",
"Practice": "Data Integration",
"Value": "5",
"Measure": "New Joinees",
"Time_Period": "6/1/2016",
"Unit": "Count"
}, {
"RU": "US",
"Head": "People",
"Industry": "-",
"Practice": "Reporting & Vizualization",
"Value": "0",
"Measure": "New Joinees",
"Time_Period": "6/1/2016",
"Unit": "Count"
}, {
"RU": "US",
"Head": "People",
"Industry": "-",
"Practice": "Data Integration",
"Value": "0",
"Measure": "New Joinees",
"Time_Period": "6/1/2016",
"Unit": "Count"
}, {
"RU": "IN",
"Head": "People",
"Industry": "-",
"Practice": "Reporting & Vizualization",
"Value": "0",
"Measure": "Planned Team",
"Time_Period": "6/1/2016",
"Unit": "Count"
}, {
"RU": "IN",
"Head": "People",
"Industry": "-",
"Practice": "Data Integration",
"Value": "0",
"Measure": "Planned Team",
"Time_Period": "6/1/2016",
"Unit": "Count"
}, {
"RU": "US",
"Head": "People",
"Industry": "-",
"Practice": "Reporting & Vizualization",
"Value": "0",
"Measure": "Planned Team",
"Time_Period": "6/1/2016",
"Unit": "Count"
}, {
"RU": "US",
"Head": "People",
"Industry": "-",
"Practice": "Data Integration",
"Value": "0",
"Measure": "Planned Team",
"Time_Period": "6/1/2016",
"Unit": "Count"
}, {
"RU": "IN",
"Head": "People",
"Industry": "-",
"Practice": "Reporting & Vizualization",
"Value": "6",
"Measure": "Current Team",
"Time_Period": "7/1/2016",
"Unit": "Count"
}, {
"RU": "IN",
"Head": "People",
"Industry": "-",
"Practice": "Data Integration",
"Value": "5",
"Measure": "Current Team",
"Time_Period": "7/1/2016",
"Unit": "Count"
}, {
"RU": "US",
"Head": "People",
"Industry": "-",
"Practice": "Reporting & Vizualization",
"Value": "0",
"Measure": "Current Team",
"Time_Period": "7/1/2016",
"Unit": "Count"
}, {
"RU": "US",
"Head": "People",
"Industry": "-",
"Practice": "Data Integration",
"Value": "0",
"Measure": "Current Team",
"Time_Period": "7/1/2016",
"Unit": "Count"
}, {
"RU": "IN",
"Head": "People",
"Industry": "-",
"Practice": "Reporting & Vizualization",
"Value": "6",
"Measure": "New Joinees",
"Time_Period": "7/1/2016",
"Unit": "Count"
}, {
"RU": "IN",
"Head": "People",
"Industry": "-",
"Practice": "Data Integration",
"Value": "5",
"Measure": "New Joinees",
"Time_Period": "7/1/2016",
"Unit": "Count"
}, {
"RU": "US",
"Head": "People",
"Industry": "-",
"Practice": "Reporting & Vizualization",
"Value": "0",
"Measure": "New Joinees",
"Time_Period": "7/1/2016",
"Unit": "Count"
}, {
"RU": "US",
"Head": "People",
"Industry": "-",
"Practice": "Data Integration",
"Value": "0",
"Measure": "New Joinees",
"Time_Period": "7/1/2016",
"Unit": "Count"
}, {
"RU": "IN",
"Head": "People",
"Industry": "-",
"Practice": "Reporting & Vizualization",
"Value": "10",
"Measure": "Planned Team",
"Time_Period": "7/1/2016",
"Unit": "Count"
}, {
"RU": "IN",
"Head": "People",
"Industry": "-",
"Practice": "Data Integration",
"Value": "20",
"Measure": "Planned Team",
"Time_Period": "7/1/2016",
"Unit": "Count"
}, {
"RU": "US",
"Head": "People",
"Industry": "-",
"Practice": "Reporting & Vizualization",
"Value": "30",
"Measure": "Planned Team",
"Time_Period": "7/1/2016",
"Unit": "Count"
}, {
"RU": "US",
"Head": "People",
"Industry": "-",
"Practice": "Data Integration",
"Value": "0",
"Measure": "Planned Team",
"Time_Period": "7/1/2016",
"Unit": "Count"
}];
var margin = {
top: 30,
right: 20,
bottom: 30,
left: 50
},
width = 600 - margin.left - margin.right,
height = 270 - margin.top - margin.bottom;
// Parse the date / time
var parseDate = d3.time.format("%m/%d/%Y").parse;
// Set the ranges
var x = d3.time.scale().range([0, width]);
var y = d3.scale.linear().range([height, 0]);
// Define the axes
var xAxis = d3.svg.axis().scale(x)
.orient("bottom").ticks(5);
var yAxis = d3.svg.axis().scale(y)
.orient("left").ticks(5);
// Not yet using filtering
var filter = data.filter(function(d) {
return (d.Head == 'People' && d.Measure == 'Current Team')
});
var nested = d3.nest().key(function(d) {
return d.Time_Period;
})
.rollup(function(d) {
return d3.sum(d, function(e) {
return +e.Value;
})
//console.log(line1);
})
.entries(data);
x.domain(d3.extent(nested, function(d) {
return parseDate(d.key);
}));
y.domain(d3.extent(nested, function(d) {
return d.values;
}));
// Adds the svg canvas
var svg = d3.select("body").append("svg").attr("height", height + margin.top + margin.bottom)
.attr("width", width + margin.left + margin.right)
.append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");
svg.append("g")
.attr("class", "x axis")
.attr("transform", "translate(0," + height + ")")
.call(xAxis);
svg.append("g")
.attr("class", "y axis")
.call(yAxis)
.append("text")
.attr("transform", "rotate(-90)")
.attr("y", 6)
.attr("dy", ".71em")
.style("text-anchor", "end")
.text("Price ($)");
var line_1 = d3.svg.line()
.x(function(d) {
return x(parseDate(d.key));
})
.y(function(d) {
return d.values;
});
//console.log(line_1.x.value);
svg.append("path")
.datum(nested)
.attr("class", "line")
.attr("d", line_1)
.style("stroke", "steelblue")
.attr("fill", "none")
.attr("stroke-width", 4.8)
.attr("stroke-opacity", 0.0001)
.transition().duration(2000)
.attr("stroke-opacity", 1)
.attr("stroke-width", 2.8);
.line {
stroke: blue;
fill: none;
stroke-width: 4;
}
.axis path,
.axis line {
fill: none;
stroke: black;
shape-rendering: crispEdges;
}
.axis text {
font-size: 10px;
font-family: sans-serif;
}
.text-label {
font-size: 10px;
font-family: sans-serif;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.4.11/d3.min.js"></script>

Related

Updated json not updating the jstree

I am trying to use jstree in my ruby on rails application. I have the following data captured in rails
TransferRequestController.rb
def sources
#disease_code_id = params[:disease_code_id]
#phase_name = params[:phase_id]
#phase_id = RecruitmentPhase.select('recruitment_phases.phase_id').where('recruitment_phases.phase_name = ?', #phase_name)
#byebug
#sources = QuestionnaireItem.joins('join traits on traits.trait_id = questionnaire_items.trait_id join trait_groups on trait_groups.trait_id = traits.trait_id join sources on sources.source_id = traits.source_id join disease_phaseid_questionnaires on disease_phaseid_questionnaires.questionnaire_id = questionnaire_items.questionnaire_id join recruitment_phases on disease_phaseid_questionnaires.phase_id = recruitment_phases.phase_id').where('disease_phaseid_questionnaires.disease_code_id = ? and disease_phaseid_questionnaires.phase_id = ?', #disease_code_id, #phase_id.first.phase_id).where.not(:recruitment_phases => {phase_name:nil}).select('distinct sources.source_name', 'sources.source_id', 'recruitment_phases.phase_name', 'recruitment_phases.phase_id')
#sources.each { |x| $data.push(Node.new(x.source_name.strip, #phase_name.chomp, x.source_name.strip))}
respond_to do |format|
format.html
format.js
format.json { render json: $data.flatten}
end
end
In my application.js
function nextCall(phase_id, disease_code_id){
$.ajax({
url: "source/"+phase_id+"/"+disease_code_id,
dataType:'json',
type:'GET',
data: "{}",
success: function (data) {
$('#using_json_2').jstree(true).settings.core.data = data;
$('#using_json_2').jstree('refresh');
}
});
}
While debugging it, I am perfectly getting the node structure for the data as shown below
[
0,
{
"id": "Follow-up 4",
"parent": "#",
"text": "Follow-up 4"
},
{
"id": "Follow-up 3",
"parent": "#",
"text": "Follow-up 3"
},
{
"id": "Follow-up 2",
"parent": "#",
"text": "Follow-up 2"
},
{
"id": "Baseline",
"parent": "#",
"text": "Baseline"
},
{
"id": "Follow-up 3 extra",
"parent": "#",
"text": "Follow-up 3 extra"
},
{
"id": "Follow-up 1",
"parent": "#",
"text": "Follow-up 1"
},
{
"id": "question form popgen",
"parent": "Baseline",
"text": "question form popgen"
},
{
"id": "administrative/derived popgen",
"parent": "Baseline",
"text": "administrative/derived popgen"
},
{
"id": "practitioner record",
"parent": "Baseline",
"text": "practitioner record"
}
]
But my tree structure looks like the following
jstree
Can anyone help me where I am going wrong?
It's because of that first 0 you had in your json. Remove it and it will work as expected.
$('#tree').jstree({ 'core' : {
'data' : [
{
"id": "Follow-up 4",
"parent": "#",
"text": "Follow-up 4"
},
{
"id": "Follow-up 3",
"parent": "#",
"text": "Follow-up 3"
},
{
"id": "Follow-up 2",
"parent": "#",
"text": "Follow-up 2"
},
{
"id": "Baseline",
"parent": "#",
"text": "Baseline"
},
{
"id": "Follow-up 3 extra",
"parent": "#",
"text": "Follow-up 3 extra"
},
{
"id": "Follow-up 1",
"parent": "#",
"text": "Follow-up 1"
},
{
"id": "question form popgen",
"parent": "Baseline",
"text": "question form popgen"
},
{
"id": "administrative/derived popgen",
"parent": "Baseline",
"text": "administrative/derived popgen"
},
{
"id": "practitioner record",
"parent": "Baseline",
"text": "practitioner record"
}
]
} });
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jstree/3.3.12/jstree.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/jstree/3.3.12/themes/default/style.min.css" rel="stylesheet" type="text/css" />
<div id='tree'>

two node Elasticsearch cluster having data sync issue

I have a 2 node Elasticsearch cluster with both as master eligible nodes. They both are formed a cluster and named as **node1 and **node2. Couple of weeks back we have upgraded the version of ES from 7.9 to 7.17.4. Now there was an issue reported that there is some data sync issue between the nodes.
When hitting elasticsearch url we are seeing different data for an index. so we tried to hit two node urls individually as below and we observed different data on each node.
curl http://node1:9200/vehicle/_search?q=***
curl http://node2:9200/vehicle/_search?q=***
I know that data on a cluster will get synced automatically on elasticsearch but I think this is not happening in my case. Could you please let me know why this is happening ? is there anything that I can forcefully sync data between nodes.
What could be the reason to get different data on the nodes ? what should I check why there is a different data getting populated ?
Here are the curl queries and their results on two nodes. Node 2 has an additional object along with the first object with a small difference in the last line.
curl http://node1:9200/vehicle/_search?q=XYZ
{
"took": 5,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 1,
"relation": "eq"
},
"max_score": 7.8380795,
"hits": [
{
"_index": "vehicle_inventory",
"_type": "_doc",
"_id": "109802",
"_score": 7.8380795,
"_source": {
"abs": "Yes",
"addressLine1": "965 ALDRIN DR",
"addressLine2": " ",
"aeroCabExtenders": "Yes",
"aeroRoof": " ",
"aeroSideFairings": "Yes",
"airConditioning": "Yes",
"areaName": " ",
"areaNumber": "0617",
"bodyMake": "NULL",
"bodySerialNumber": "NULL",
"bodyFloorType": "",
"bodyRoofType": "",
"brakeType": "NULL",
"cabStyle": "Conventional",
"category": "TRACTOR",
"chassisBumper": "AERO",
"chassisMakeCode": "FTL",
"cdlRequired": "Yes",
"city": "Eagan",
"color": "White",
"modified_color": "WHITE",
"compared": false,
"saved": false,
"country": "US",
"countryExt": "United States",
"collisionWarning": "No",
"collisionWarningModel": "",
"customerNumber": "RENTAL",
"description": "AVAILABLE JANUARY 2022",
"displayDeliveryCal": "Y",
"districtName": " ",
"driverSeatType": "AIR",
"emailAddress": "E-MAIL.GENERAL.LOCATION#XXXXXX",
"engineBrake": "Yes",
"engineMake": "Detroit",
"engineModel4": "DD15AT",
"engineHours": 0,
"faxNumber": "06516860476",
"featuredListing": "Y",
"frontAxleCapacity": "13300",
"frontWheelType": "",
"fuelType": "DIESEL",
"grossVehicleWeight": 80000,
"height": "NULL",
"horsepower": 455,
"image": "/usedtrucks/image/109802/1",
"interiorLevel": "PREMIUM",
"individualPageUrl": "",
"liftGate": "NULL",
"liftGateCapacity": "0",
"liftGateModel": " ",
"loadLength": "NULL",
"make": "Freightliner",
"managersSpecial": "false",
"managerSpecialDiscountRetail": "0",
"managerSpecialDiscountWholeSale": "0",
"mileage": "701,830 miles",
"model": "Cascadia 12564ST",
"newListing": "false",
"numberOfBunks": "2",
"numberOfDriveAxles": "2",
"numberOfTanks": "Dual",
"numericHeight": "",
"numericLoadLength": -1,
"numericWidth": "",
"offLease": "N",
"originalWholeSalePrice": "64,500",
"originalRetailPrice": "64,500",
"phoneNumber": "1-866-309-1962",
"promotionVehicle": "true",
"rearAxleCapacity": "40000",
"rearAxleMake": "Detroit",
"rearDoor": "NULL",
"rearRatio": "2.53",
"rearWheelType": "",
"reeferStandby": "",
"refrigerationHours": "",
"refrigerationMake": "NULL",
"refrigerationModel": "NULL",
"retailPrice": "54,500",
"salePutUpDate": "2021-12-17 00:00:00",
"sideConstruction": "NULL",
"sideDoor": "NULL",
"sleeperSize": "72",
"sleeperType": "Raised Roof",
"slidingFifthWheel": "Yes",
"state": "MN",
"status": "ACTIVE",
"statusComments": " ",
"sale_reason_desc": "AVAILABLE JANUARY 2022",
"saleType": " ",
"size": "",
"suspension": "Air",
"tareWeight": "18795",
"thumbnail": "usedtrucks/image/109802t/1",
"tireSize": "11R22.5",
"tireType": "S/WAY",
"totalFuelCapacity": "220",
"transmissionMake": "Detroit",
"transmissionModel": "12DA1550",
"transmissionSpeed": "12",
"transmissionType": "Automatic",
"type": "Sleeper Tractor",
"unitNumber": "109802",
"use": "RENTAL",
"vin": "3AKJGLD53FSGJ8668",
"wheelBase": "228\"",
"wheelType": "Aluminum",
"wholesalePrice": "59,500",
"width": "NULL",
"year": 2015,
"zip": "55121",
"numeric_mileage": 701830,
"numeric_retail_price": 54500,
"numeric_wholesale_price": 59500,
"dLatitude": 44.944400787353516,
"dLongitude": -93.09329986572266,
"bodyModel": null,
"promotionAmount": "10,000",
"salePrice": 0,
"location": "016510",
"jpegImage": "/usedtrucks/JpgServlet/109802_1.jpg",
"translatedCategory": "Heavy Duty Tractors",
"originalCategory": "Heavy Duty Tractors",
"monFriHours": "M-F 8:00 am to 8:00 pm ET",
"satHours": "Sat 9:00 am to 3:00 pm ET",
"mobileSitePhone": "1-800-485-9671",
"salePutUpDatesort": "2021-12-17",
"stringyear": "2015",
"range_grossVehicleWeight": null,
"range_loadLength": null,
"range_horsepower": "401 and more",
"range_cabType": "Raised Roof",
"range_retailCenter": null,
"viewCount": "222ST15",
"advertTerm": "Level 1",
"numeric_Height": 0,
"numeric_totalFuelCapacity": 0,
"numeric_Width": 0,
"promotionList": [
{
"name": "Save on Select Sleeper Tractors",
"description": "Save on Select Sleeper Tractors",
"amount": 10000,
"amountDisplayRetail": "10,000",
"amountDisplayWholeSale": "10,000",
"type": "DISCOUNT",
"rule": "viewCount != null and viewCount.equalsIgnoreCase('222ST15') and (year <= 2014 or numeric_mileage >= 700)"
}
],
"imageMaxInstance": 10,
"defaultImageBeanList": null,
"translationsMap": {
"cdlRequired": "Yes",
"countryExt": "United States",
"advertTerm": "Level 1",
"color": "White",
"range_horsepower": "401 and more",
"range_cabType": "Raised Roof",
"model": "Cascadia 12564ST",
"category": "Heavy Duty Tractors",
"type": "Sleeper Tractor"
},
"vehicle_suggestions": {},
"vehicle_locations": {
"lon": "-93.0933",
"lat": "44.9444"
},
"combo_filter": [
{
"filter_name": "range_horsepower",
"filter_value": "401 and more"
},
{
"filter_name": "range_cabType",
"filter_value": "Raised Roof"
},
{
"filter_name": "range_retailCenter",
"filter_value": null
},
{
"filter_name": "advertTerm",
"filter_value": "Level 1"
},
{
"filter_name": "airConditioning",
"filter_value": "Yes"
},
{
"filter_name": "category",
"filter_value": "Heavy Duty Tractors"
},
{
"filter_name": "color",
"filter_value": "White"
},
{
"filter_name": "engineMake",
"filter_value": "Detroit"
},
{
"filter_name": "fuelType",
"filter_value": "DIESEL"
},
{
"filter_name": "make",
"filter_value": "Freightliner"
},
{
"filter_name": "model",
"filter_value": "Cascadia 12564ST"
},
{
"filter_name": "newListing",
"filter_value": "false"
},
{
"filter_name": "numberOfBunks",
"filter_value": "2"
},
{
"filter_name": "numberOfDriveAxles",
"filter_value": "2"
},
{
"filter_name": "state",
"filter_value": "MN"
},
{
"filter_name": "transmissionMake",
"filter_value": "Detroit"
},
{
"filter_name": "transmissionSpeed",
"filter_value": "12"
},
{
"filter_name": "transmissionType",
"filter_value": "Automatic"
},
{
"filter_name": "type",
"filter_value": "Sleeper Tractor"
},
{
"filter_name": "collisionWarning",
"filter_value": "No"
},
{
"filter_name": "canada",
"filter_value": null
},
{
"filter_name": "unitedStates",
"filter_value": "MN"
},
{
"filter_name": "countryExt",
"filter_value": "United States"
},
{
"filter_name": "promotionVehicle",
"filter_value": "true"
},
{
"filter_name": "promotions",
"filter_value": "Current Deals"
},
{
"filter_name": "promotions",
"filter_value": "Save on Select Sleeper Tractors"
}
],
"slider_filter_integer": [
{
"filter_name": "numeric_mileage",
"filter_value": 701830
},
{
"filter_name": "year",
"filter_value": 2015
}
],
"slider_filter_float": [
{
"filter_name": "numeric_retail_price",
"filter_value": 54500
},
{
"filter_name": "numeric_wholesale_price",
"filter_value": 59500
}
],
"basic_filter": {},
"rowNum": 2465,
"displayManagerspecial": null,
"displayPromotions": "true",
"canada": null,
"unitedStates": "MN",
"mgrSpecialRetail": "false",
"mgrSpecialWholesale": "false",
"promotions": []
}
}
]
}
}
curl http://node2:9200/vehicle/_search?q=XYZ
{
"took": 5,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 1,
"relation": "eq"
},
"max_score": 7.8380795,
"hits": [
{
"_index": "vehicle_inventory",
"_type": "_doc",
"_id": "109802",
"_score": 7.8380795,
"_source": {
"abs": "Yes",
"addressLine1": "965 ALDRIN DR",
"addressLine2": " ",
"aeroCabExtenders": "Yes",
"aeroRoof": " ",
"aeroSideFairings": "Yes",
"airConditioning": "Yes",
"areaName": " ",
"areaNumber": "0617",
"bodyMake": "NULL",
"bodySerialNumber": "NULL",
"bodyFloorType": "",
"bodyRoofType": "",
"brakeType": "NULL",
"cabStyle": "Conventional",
"category": "TRACTOR",
"chassisBumper": "AERO",
"chassisMakeCode": "FTL",
"cdlRequired": "Yes",
"city": "Eagan",
"color": "White",
"modified_color": "WHITE",
"compared": false,
"saved": false,
"country": "US",
"countryExt": "United States",
"collisionWarning": "No",
"collisionWarningModel": "",
"customerNumber": "RENTAL",
"description": "AVAILABLE JANUARY 2022",
"displayDeliveryCal": "Y",
"districtName": " ",
"driverSeatType": "AIR",
"emailAddress": "E-MAIL.GENERAL.LOCATION#XXXXXX",
"engineBrake": "Yes",
"engineMake": "Detroit",
"engineModel": "DD15AT",
"engineHours": 0,
"faxNumber": "06516860476",
"featuredListing": "Y",
"frontAxleCapacity": "13300",
"frontWheelType": "",
"fuelType": "DIESEL",
"grossVehicleWeight": 80000,
"height": "NULL",
"horsepower": 455,
"image": "/usedtrucks/image/109802/1",
"interiorLevel": "PREMIUM",
"individualPageUrl": "",
"liftGate": "NULL",
"liftGateCapacity": "0",
"liftGateModel": " ",
"loadLength": "NULL",
"make": "Freightliner",
"managersSpecial": "false",
"managerSpecialDiscountRetail": "0",
"managerSpecialDiscountWholeSale": "0",
"mileage": "701,830 miles",
"model": "Cascadia 12564ST",
"newListing": "false",
"numberOfBunks": "2",
"numberOfDriveAxles": "2",
"numberOfTanks": "Dual",
"numericHeight": "",
"numericLoadLength": -1,
"numericWidth": "",
"offLease": "N",
"originalWholeSalePrice": "64,500",
"originalRetailPrice": "64,500",
"phoneNumber": "1-866-309-1962",
"promotionVehicle": "true",
"rearAxleCapacity": "40000",
"rearAxleMake": "Detroit",
"rearDoor": "NULL",
"rearRatio": "2.53",
"rearWheelType": "",
"reeferStandby": "",
"refrigerationHours": "",
"refrigerationMake": "NULL",
"refrigerationModel": "NULL",
"retailPrice": "44,500",
"salePutUpDate": "2021-12-17 00:00:00",
"sideConstruction": "NULL",
"sideDoor": "NULL",
"sleeperSize": "72",
"sleeperType": "Raised Roof",
"slidingFifthWheel": "Yes",
"state": "MN",
"status": "ACTIVE",
"statusComments": " ",
"sale_reason_desc": "AVAILABLE JANUARY 2022",
"saleType": " ",
"size": "",
"suspension": "Air",
"tareWeight": "18795",
"thumbnail": "usedtrucks/image/109802t/1",
"tireSize": "11R22.5",
"tireType": "S/WAY",
"totalFuelCapacity": "220",
"transmissionMake": "Detroit",
"transmissionModel": "12DA1550",
"transmissionSpeed": "12",
"transmissionType": "Automatic",
"type": "Sleeper Tractor",
"unitNumber": "109802",
"use": "RENTAL",
"vin": "3AKJGLD53FSGJ8668",
"wheelBase": "228\"",
"wheelType": "Aluminum",
"wholesalePrice": "59,500",
"width": "NULL",
"year": 2015,
"zip": "55121",
"numeric_mileage": 701830,
"numeric_retail_price": 44500,
"numeric_wholesale_price": 59500,
"dLatitude": 44.944400787353516,
"dLongitude": -93.09329986572266,
"bodyModel": null,
"promotionAmount": "10,000",
"salePrice": 0,
"location": "016510",
"jpegImage": "/usedtrucks/JpgServlet/109802_1.jpg",
"translatedCategory": "Heavy Duty Tractors",
"originalCategory": "Heavy Duty Tractors",
"monFriHours": "M-F 8:00 am to 8:00 pm ET",
"satHours": "Sat 9:00 am to 3:00 pm ET",
"mobileSitePhone": "1-800-485-9671",
"salePutUpDatesort": "2021-12-17",
"stringyear": "2015",
"range_grossVehicleWeight": null,
"range_loadLength": null,
"range_horsepower": "401 and more",
"range_cabType": "Raised Roof",
"range_retailCenter": null,
"viewCount": "222ST15",
"advertTerm": "Level 1",
"numeric_Height": 0,
"numeric_totalFuelCapacity": 0,
"numeric_Width": 0,
"promotionList": [
{
"name": "Save on Select Sleeper Tractors",
"description": "Save on Select Sleeper Tractors",
"amount": 10000,
"amountDisplayRetail": "10,000",
"amountDisplayWholeSale": "10,000",
"type": "DISCOUNT",
"rule": "viewCount != null and viewCount.equalsIgnoreCase('222ST15') and (numeric_mileage < 700 or year > 2014)"
},
{
"name": "Save on Select Sleeper Tractors. Save an additional $5,000 when financing with Premier Financing",
"description": "Save on Select Sleeper Tractors. Save an additional $5,000 when financing with Premier Financing",
"amount": 10000,
"amountDisplayRetail": "10,000",
"amountDisplayWholeSale": "10,000",
"type": "DISCOUNT",
"rule": "viewCount != null and viewCount.equalsIgnoreCase('222ST15') and (numeric_mileage >= 700 or year <= 2014) "
}
],
"imageMaxInstance": 10,
"defaultImageBeanList": null,
"translationsMap": {
"cdlRequired": "Yes",
"countryExt": "United States",
"advertTerm": "Level 1",
"color": "White",
"range_horsepower": "401 and more",
"range_cabType": "Raised Roof",
"model": "Cascadia 12564ST",
"category": "Heavy Duty Tractors",
"type": "Sleeper Tractor"
},
"vehicle_suggestions": {},
"vehicle_locations": {
"lon": "-93.0933",
"lat": "44.9444"
},
"combo_filter": [
{
"filter_name": "range_horsepower",
"filter_value": "401 and more"
},
{
"filter_name": "range_cabType",
"filter_value": "Raised Roof"
},
{
"filter_name": "range_retailCenter",
"filter_value": null
},
{
"filter_name": "advertTerm",
"filter_value": "Level 1"
},
{
"filter_name": "airConditioning",
"filter_value": "Yes"
},
{
"filter_name": "category",
"filter_value": "Heavy Duty Tractors"
},
{
"filter_name": "color",
"filter_value": "White"
},
{
"filter_name": "engineMake",
"filter_value": "Detroit"
},
{
"filter_name": "fuelType",
"filter_value": "DIESEL"
},
{
"filter_name": "make",
"filter_value": "Freightliner"
},
{
"filter_name": "model",
"filter_value": "Cascadia 12564ST"
},
{
"filter_name": "newListing",
"filter_value": "false"
},
{
"filter_name": "numberOfBunks",
"filter_value": "2"
},
{
"filter_name": "numberOfDriveAxles",
"filter_value": "2"
},
{
"filter_name": "state",
"filter_value": "MN"
},
{
"filter_name": "transmissionMake",
"filter_value": "Detroit"
},
{
"filter_name": "transmissionSpeed",
"filter_value": "12"
},
{
"filter_name": "transmissionType",
"filter_value": "Automatic"
},
{
"filter_name": "type",
"filter_value": "Sleeper Tractor"
},
{
"filter_name": "collisionWarning",
"filter_value": "No"
},
{
"filter_name": "canada",
"filter_value": null
},
{
"filter_name": "unitedStates",
"filter_value": "MN"
},
{
"filter_name": "countryExt",
"filter_value": "United States"
},
{
"filter_name": "promotionVehicle",
"filter_value": "true"
},
{
"filter_name": "promotions",
"filter_value": "Current Deals"
},
{
"filter_name": "promotions",
"filter_value": "Save on Select Sleeper Tractors"
},
{
"filter_name": "promotions",
"filter_value": "Save on Select Sleeper Tractors. Save an additional $5,000 when financing with Premier Financing"
}
],
"slider_filter_integer": [
{
"filter_name": "numeric_mileage",
"filter_value": 701830
},
{
"filter_name": "year",
"filter_value": 2015
}
],
"slider_filter_float": [
{
"filter_name": "numeric_retail_price",
"filter_value": 44500
},
{
"filter_name": "numeric_wholesale_price",
"filter_value": 59500
}
],
"basic_filter": {},
"rowNum": 2465,
"displayManagerspecial": null,
"displayPromotions": "true",
"canada": null,
"unitedStates": "MN",
"mgrSpecialRetail": "false",
"mgrSpecialWholesale": "false",
"promotions": []
}
}
]
}
}
Output of GET _cat/shards/vehicle*?v from both the nodes
node1
index shard prirep state docs store ip node
vehicle_inventory 0 p STARTED 120528 9.9mb 3.178.159.250 qa-esearch-n1
vehicle_inventory 0 r UNASSIGNED
node2
index shard prirep state docs store ip node
vehicle_inventory 0 p STARTED 121065 10.1mb 3.178.159.252 qa-esearch-n2
vehicle_inventory 0 r UNASSIGNED
Please observe there is a difference in storage size (9.9mb and 10.1mb). why is the size difference.
Output of GET _cat/nodes?v from both nodes
node1
ip heap.percent ram.percent cpu load_1m load_5m load_15m node.role master name
3.178.159.250 54 96 7 2.10 1.53 1.58 cdfhilmrstw * qa-esearch-n1
node2
ip heap.percent ram.percent cpu load_1m load_5m load_15m node.role master name
3.178.159.252 30 98 6 0.35 0.21 0.17 cdfhilmrstw * qa-esearch-n2

jqgrid treeGrid Cannot read property 'rowIndex' of undefined

I try to use local data with treeGrid, when i click the unfold
button . I get the tips "Cannot read property 'rowIndex' of
undefined"
<!DOCTYPE html>
<html lang="en">
<head>
<!-- The jQuery library is a prerequisite for all jqSuite products -->
<script type="text/ecmascript" src="./js/jquery.min.js"></script>
<!-- This is the Javascript file of jqGrid -->
<script type="text/ecmascript" src="./js/jquery.jqGrid.min.js"></script>
<!-- This is the localization file of the grid controlling messages, labels, etc.
<!-- We support more than 40 localizations -->
<script type="text/ecmascript" src="./js/i18n/grid.locale-en.js"></script>
<!-- A link to a jQuery UI ThemeRoller theme, more than 22 built-in and many more custom -->
<link rel="stylesheet" type="text/css" media="screen" href="./css/jquery-ui-1.10.4.custom.min.css" />
<!-- The link to the CSS that the grid needs -->
<link rel="stylesheet" type="text/css" media="screen" href="./css/ui.jqgrid.css" />
<meta charset="utf-8" />
<title>jqTreeGrid - Load On Demand - Load all Rows at once collapsed</title>
</head>
<body>
<table id="tree"></table>
<div id="pager"></div>
<script type="text/javascript">
var rows = [
{
"category_id": "1",
"name": "ELECTRONICS",
"price": "0.00",
"qty_onhand": "0",
"color": "",
"lft": "1",
"rgt": "44",
"level": "0",
"uiicon": ""
},
{
"category_id": "2",
"name": "TELEVISIONS",
"price": "0.00",
"qty_onhand": "0",
"color": "",
"lft": "2",
"rgt": "19",
"level": "1",
"uiicon": ""
},
{
"category_id": "3",
"name": "TUBE",
"price": "0.00",
"qty_onhand": "0",
"color": "",
"lft": "3",
"rgt": "8",
"level": "2",
"uiicon": ""
},
{
"category_id": "11",
"name": "26 \" TV",
"price": "200.00",
"qty_onhand": "1",
"color": "black",
"lft": "4",
"rgt": "5",
"level": "3",
"uiicon": "ui-icon-image"
},
{
"category_id": "12",
"name": "30 \" TV",
"price": "350.00",
"qty_onhand": "2",
"color": "black",
"lft": "6",
"rgt": "7",
"level": "3",
"uiicon": "ui-icon-document"
},
{
"category_id": "4",
"name": "LCD",
"price": "0.00",
"qty_onhand": "0",
"color": "",
"lft": "9",
"rgt": "12",
"level": "2",
"uiicon": ""
},
{
"category_id": "13",
"name": "Super-LCD 42\" ",
"price": "400.00",
"qty_onhand": "10",
"color": "all",
"lft": "10",
"rgt": "11",
"level": "3",
"uiicon": "ui-icon-video"
},
{
"category_id": "5",
"name": "PLASMA",
"price": "0.00",
"qty_onhand": "0",
"color": "",
"lft": "13",
"rgt": "18",
"level": "2",
"uiicon": ""
},
{
"category_id": "14",
"name": "Ultra-Plasma 62\" ",
"price": "440.00",
"qty_onhand": "2",
"color": "silver",
"lft": "14",
"rgt": "15",
"level": "3",
"uiicon": "ui-icon-clipboard"
},
{
"category_id": "15",
"name": "Value Plasma 38\" ",
"price": "312.00",
"qty_onhand": "0",
"color": "silver",
"lft": "16",
"rgt": "17",
"level": "3",
"uiicon": "ui-icon-clipboard"
},
{
"category_id": "6",
"name": "PORTABLE ELECTRONICS",
"price": "0.00",
"qty_onhand": "0",
"color": "",
"lft": "20",
"rgt": "43",
"level": "1",
"uiicon": ""
},
{
"category_id": "7",
"name": "MP3 PLAYERS",
"price": "0.00",
"qty_onhand": "0",
"color": "",
"lft": "21",
"rgt": "32",
"level": "2",
"uiicon": ""
},
{
"category_id": "8",
"name": "FLASH",
"price": "0.00",
"qty_onhand": "0",
"color": "",
"lft": "22",
"rgt": "29",
"level": "3",
"uiicon": ""
},
{
"category_id": "17",
"name": "Super-Shuffle 1gb",
"price": "20.00",
"qty_onhand": "11",
"color": "all",
"lft": "23",
"rgt": "24",
"level": "4",
"uiicon": "ui-icon-note"
},
{
"category_id": "21",
"name": "5Gb Flash",
"price": "0.00",
"qty_onhand": "0",
"color": "",
"lft": "25",
"rgt": "26",
"level": "4",
"uiicon": "ui-icon-comment"
},
{
"category_id": "22",
"name": "10Gb flash ",
"price": "0.00",
"qty_onhand": "0",
"color": "",
"lft": "27",
"rgt": "28",
"level": "4",
"uiicon": "ui-icon-tag"
},
{
"category_id": "16",
"name": " Power-MP3 128mb",
"price": "123.00",
"qty_onhand": "2",
"color": "withe",
"lft": "30",
"rgt": "31",
"level": "3",
"uiicon": "ui-icon-signal-diag"
},
{
"category_id": "9",
"name": "CD PLAYERS",
"price": "0.00",
"qty_onhand": "0",
"color": "",
"lft": "33",
"rgt": "38",
"level": "2",
"uiicon": ""
},
{
"category_id": "18",
"name": " Porta CD ",
"price": "10.00",
"qty_onhand": "0",
"color": "",
"lft": "34",
"rgt": "35",
"level": "3",
"uiicon": "ui-icon-eject"
},
{
"category_id": "19",
"name": "CD To go!",
"price": "110.00",
"qty_onhand": "11",
"color": "",
"lft": "36",
"rgt": "37",
"level": "3",
"uiicon": "ui-icon-power"
},
{
"category_id": "10",
"name": "2 WAY RADIOS",
"price": "0.00",
"qty_onhand": "0",
"color": "",
"lft": "39",
"rgt": "42",
"level": "2",
"uiicon": ""
},
{
"category_id": "20",
"name": "Family Talk 360 ",
"price": "200.00",
"qty_onhand": "15",
"color": "",
"lft": "40",
"rgt": "41",
"level": "3",
"uiicon": "ui-icon-volume-on"
},
{
"category_id": "23",
"name": "COMPUTERS",
"price": "0.00",
"qty_onhand": "0",
"color": "",
"lft": "45",
"rgt": "50",
"level": "0",
"uiicon": ""
},
{
"category_id": "25",
"name": "DESKTOP ",
"price": "0.00",
"qty_onhand": "0",
"color": "",
"lft": "46",
"rgt": "47",
"level": "1",
"uiicon": ""
},
{
"category_id": "26",
"name": "LAPTOPS",
"price": "0.00",
"qty_onhand": "0",
"color": "",
"lft": "48",
"rgt": "49",
"level": "1",
"uiicon": ""
},
{
"category_id": "24",
"name": "APPLIANCES",
"price": "0.00",
"qty_onhand": "0",
"color": "",
"lft": "51",
"rgt": "52",
"level": "0",
"uiicon": ""
}
]
jQuery(document).ready(function ($) {
jQuery('#tree').jqGrid({
// "url":"data.json",
"colModel": [
{
"name": "category_id",
"index": "accounts.account_id",
"sorttype": "int",
"key": true,
"hidden": true,
"width": 50
}, {
"name": "name",
"index": "name",
"sorttype": "string",
"label": "Name",
"width": 170
}, {
"name": "price",
"index": "price",
"sorttype": "numeric",
"label": "Price",
"width": 90,
"align": "right"
}, {
"name": "qty_onhand",
"index": "qty_onhand",
"sorttype": "int",
"label": "Qty",
"width": 90,
"align": "right"
}, {
"name": "color",
"index": "color",
"sorttype": "string",
"label": "Color",
"width": 100
}, {
"name": "lft",
"hidden": true
}, {
"name": "rgt",
"hidden": true
}, {
"name": "level",
"hidden": true
}, {
"name": "uiicon",
"hidden": true
}
],
"width": "780",
"hoverrows": false,
"viewrecords": false,
"gridview": true,
"height": "auto",
"sortname": "lft",
"loadonce": true,
"rowNum": 100,
"scrollrows": true,
// enable tree grid
"treeGrid": true,
// which column is expandable
"ExpandColumn": "name",
// datatype
"treedatatype": "json",
// the model used
"treeGridModel": "nested",
// configuration of the data comming from server
"treeReader": {
"left_field": "lft",
"right_field": "rgt",
"level_field": "level",
"leaf_field": "isLeaf",
"expanded_field": "expanded",
"loaded": "loaded",
"icon_field": "icon"
},
// "sortorder": "asc",
"datatype": "local",
"data": rows,
"pager": "#pager"
});
});
</script>
</body>
</html>
For localdata type, you must configure the localReader parameter:
localReader: {
repeatitems: true,
// cell: "",
id: "category_id"
}

multi-ring pie chart using d3js

I am trying to understand how to create a multi ring pie chart using d3js . Here is what I have tried and got so far. I am pretty sure its not reading the data correctly here. Any example on how should I be creating such a chart. What I am trying to do is to get each ring based on each group like pop quarter and so on.
var dataset = [
{
"name": "Population Quater",
"code": "POP_QUATER",
"parent": "POP_BY_QUAT",
"children": [
{
"name": "POP_CYQ1",
"code": "POP_CYQ1",
"parent": "POP_QUATER",
"value": "6772",
"label": "CYQ1",
"children": []
},
{
"name": "POP_CYQ2",
"code": "POP_CYQ2",
"parent": "POP_QUATER",
"value": "6716",
"label": "CYQ2",
"children": []
},
{
"name": "POP_CYQ3",
"code": "POP_CYQ3",
"parent": "POP_QUATER",
"value": "6714",
"label": "CYQ3",
"children": []
},
{
"name": "POP_CYQ4",
"code": "POP_CYQ4",
"parent": "POP_QUATER",
"value": "6703",
"label": "CYQ4",
"children": []
},
{
"name": "POP_LYQ1",
"code": "POP_LYQ1",
"parent": "POP_QUATER",
"value": "6721",
"label": "LYQ1",
"children": []
},
{
"name": "POP_LYQ2",
"code": "POP_LYQ2",
"parent": "POP_QUATER",
"value": "6671",
"label": "LYQ2",
"children": []
},
{
"name": "POP_LYQ3",
"code": "POP_LYQ3",
"parent": "POP_QUATER",
"value": "6708",
"label": "LYQ3",
"children": []
},
{
"name": "POP_LYQ4",
"code": "POP_LYQ4",
"parent": "POP_QUATER",
"value": "6734",
"label": "LYQ4",
"children": []
}
]
},
{
"name": "Transient Pop",
"code": "TRANSIENT_POP",
"parent": "POP_BY_QUAT",
"label": "Transient Pop",
"children": [
{
"name": "TRANSIENT_LYQ1",
"code": "TRANSIENT_LYQ1",
"parent": "TRANSIENT_POP",
"value": "54",
"label": "LYQ1",
"children": []
},
{
"name": "TRANSIENT_LYQ2",
"code": "TRANSIENT_LYQ2",
"parent": "TRANSIENT_POP",
"value": "86",
"label": "LYQ2",
"children": []
},
{
"name": "TRANSIENT_LYQ3",
"code": "TRANSIENT_LYQ3",
"parent": "TRANSIENT_POP",
"value": "219",
"label": "LYQ3",
"children": []
},
{
"name": "TRANSIENT_LYQ4",
"code": "TRANSIENT_LYQ4",
"parent": "TRANSIENT_POP",
"value": "191",
"label": "LYQ4",
"children": []
},
{
"name": "TRANSIENT_CYQ1",
"code": "TRANSIENT_CYQ1",
"parent": "TRANSIENT_POP",
"value": "52",
"label": "CYQ1",
"children": []
},
{
"name": "TRANSIENT_CYQ2",
"code": "TRANSIENT_CYQ2",
"parent": "TRANSIENT_POP",
"value": "91",
"label": "CYQ2",
"children": []
},
{
"name": "TRANSIENT_CYQ3",
"code": "TRANSIENT_CYQ3",
"parent": "TRANSIENT_POP",
"value": "222",
"label": "CYQ3",
"children": []
},
{
"name": "TRANSIENT_CYQ4",
"code": "TRANSIENT_CYQ4",
"parent": "TRANSIENT_POP",
"value": "186",
"label": "CYQ4",
"children": []
}
]
},
{
"name": "Seasonal Pop",
"code": "SEASONAL_POP",
"parent": "POP_BY_QUAT",
"label": "Seasonal Pop",
"children": [
{
"name": "SEASONAL_LYQ1",
"code": "SEASONAL_LYQ1",
"parent": "SEASONAL_POP",
"value": "2",
"label": "LYQ1",
"children": []
},
{
"name": "SEASONAL_LYQ2",
"code": "SEASONAL_LYQ2",
"parent": "SEASONAL_POP",
"value": "24",
"label": "LYQ2",
"children": []
},
{
"name": "SEASONAL_LYQ3",
"code": "SEASONAL_LYQ3",
"parent": "SEASONAL_POP",
"value": "152",
"label": "LYQ3",
"children": []
},
{
"name": "SEASONAL_LYQ4",
"code": "SEASONAL_LYQ4",
"parent": "SEASONAL_POP",
"value": "55",
"label": "LYQ4",
"children": []
},
{
"name": "SEASONAL_CYQ1",
"code": "SEASONAL_CYQ1",
"parent": "SEASONAL_POP",
"value": "2",
"label": "CYQ1",
"children": []
},
{
"name": "SEASONAL_CYQ2",
"code": "SEASONAL_CYQ2",
"parent": "SEASONAL_POP",
"value": "22",
"label": "CYQ2",
"children": []
},
{
"name": "SEASONAL_CYQ3",
"code": "SEASONAL_CYQ3",
"parent": "SEASONAL_POP",
"value": "161",
"label": "CYQ3",
"children": []
},
{
"name": "SEASONAL_CYQ4",
"code": "SEASONAL_CYQ4",
"parent": "SEASONAL_POP",
"value": "55",
"label": "CYQ4",
"children": []
}
]
}
];
var width = 460,
height = 300,
cwidth = 25;
var color = d3.scale.category20();
var pie = d3.layout.pie()
.sort(null).value(function (d) {
return d.value;//since score is the parameter for the pie
});
var arc = d3.svg.arc();
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height)
.append("g")
.attr("transform", "translate(" + width / 2 + "," + height / 2 + ")");
var gs = svg.selectAll("g").data(d3.values(dataset)).enter().append("g");
var path = gs.selectAll("path")
.data(function(d) { return pie(d.value); })
.enter().append("path")
.attr("fill", function(d, i) { return color(i); })
.attr("d", function(d, i, j) { return arc.innerRadius(10+cwidth*j).outerRadius(cwidth*(j+1))(d); });
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.3.13/d3.min.js"></script>
You are not binding the data array (dataset) to your groups. It should be:
var gs = svg.selectAll("g")
.data(dataset)
.enter()
.append("g");
And then, for the inner selections, use children:
var path = gs.selectAll("path")
.data(function(d) {
return pie(d.children);
})
//etc...
Here is your code with those changes:
var dataset = [{
"name": "Population Quater",
"code": "POP_QUATER",
"parent": "POP_BY_QUAT",
"children": [{
"name": "POP_CYQ1",
"code": "POP_CYQ1",
"parent": "POP_QUATER",
"value": "6772",
"label": "CYQ1",
"children": []
}, {
"name": "POP_CYQ2",
"code": "POP_CYQ2",
"parent": "POP_QUATER",
"value": "6716",
"label": "CYQ2",
"children": []
}, {
"name": "POP_CYQ3",
"code": "POP_CYQ3",
"parent": "POP_QUATER",
"value": "6714",
"label": "CYQ3",
"children": []
}, {
"name": "POP_CYQ4",
"code": "POP_CYQ4",
"parent": "POP_QUATER",
"value": "6703",
"label": "CYQ4",
"children": []
}, {
"name": "POP_LYQ1",
"code": "POP_LYQ1",
"parent": "POP_QUATER",
"value": "6721",
"label": "LYQ1",
"children": []
}, {
"name": "POP_LYQ2",
"code": "POP_LYQ2",
"parent": "POP_QUATER",
"value": "6671",
"label": "LYQ2",
"children": []
}, {
"name": "POP_LYQ3",
"code": "POP_LYQ3",
"parent": "POP_QUATER",
"value": "6708",
"label": "LYQ3",
"children": []
}, {
"name": "POP_LYQ4",
"code": "POP_LYQ4",
"parent": "POP_QUATER",
"value": "6734",
"label": "LYQ4",
"children": []
}]
}, {
"name": "Transient Pop",
"code": "TRANSIENT_POP",
"parent": "POP_BY_QUAT",
"label": "Transient Pop",
"children": [{
"name": "TRANSIENT_LYQ1",
"code": "TRANSIENT_LYQ1",
"parent": "TRANSIENT_POP",
"value": "54",
"label": "LYQ1",
"children": []
}, {
"name": "TRANSIENT_LYQ2",
"code": "TRANSIENT_LYQ2",
"parent": "TRANSIENT_POP",
"value": "86",
"label": "LYQ2",
"children": []
}, {
"name": "TRANSIENT_LYQ3",
"code": "TRANSIENT_LYQ3",
"parent": "TRANSIENT_POP",
"value": "219",
"label": "LYQ3",
"children": []
}, {
"name": "TRANSIENT_LYQ4",
"code": "TRANSIENT_LYQ4",
"parent": "TRANSIENT_POP",
"value": "191",
"label": "LYQ4",
"children": []
}, {
"name": "TRANSIENT_CYQ1",
"code": "TRANSIENT_CYQ1",
"parent": "TRANSIENT_POP",
"value": "52",
"label": "CYQ1",
"children": []
}, {
"name": "TRANSIENT_CYQ2",
"code": "TRANSIENT_CYQ2",
"parent": "TRANSIENT_POP",
"value": "91",
"label": "CYQ2",
"children": []
}, {
"name": "TRANSIENT_CYQ3",
"code": "TRANSIENT_CYQ3",
"parent": "TRANSIENT_POP",
"value": "222",
"label": "CYQ3",
"children": []
}, {
"name": "TRANSIENT_CYQ4",
"code": "TRANSIENT_CYQ4",
"parent": "TRANSIENT_POP",
"value": "186",
"label": "CYQ4",
"children": []
}]
}, {
"name": "Seasonal Pop",
"code": "SEASONAL_POP",
"parent": "POP_BY_QUAT",
"label": "Seasonal Pop",
"children": [{
"name": "SEASONAL_LYQ1",
"code": "SEASONAL_LYQ1",
"parent": "SEASONAL_POP",
"value": "2",
"label": "LYQ1",
"children": []
}, {
"name": "SEASONAL_LYQ2",
"code": "SEASONAL_LYQ2",
"parent": "SEASONAL_POP",
"value": "24",
"label": "LYQ2",
"children": []
}, {
"name": "SEASONAL_LYQ3",
"code": "SEASONAL_LYQ3",
"parent": "SEASONAL_POP",
"value": "152",
"label": "LYQ3",
"children": []
}, {
"name": "SEASONAL_LYQ4",
"code": "SEASONAL_LYQ4",
"parent": "SEASONAL_POP",
"value": "55",
"label": "LYQ4",
"children": []
}, {
"name": "SEASONAL_CYQ1",
"code": "SEASONAL_CYQ1",
"parent": "SEASONAL_POP",
"value": "2",
"label": "CYQ1",
"children": []
}, {
"name": "SEASONAL_CYQ2",
"code": "SEASONAL_CYQ2",
"parent": "SEASONAL_POP",
"value": "22",
"label": "CYQ2",
"children": []
}, {
"name": "SEASONAL_CYQ3",
"code": "SEASONAL_CYQ3",
"parent": "SEASONAL_POP",
"value": "161",
"label": "CYQ3",
"children": []
}, {
"name": "SEASONAL_CYQ4",
"code": "SEASONAL_CYQ4",
"parent": "SEASONAL_POP",
"value": "55",
"label": "CYQ4",
"children": []
}]
}];
var width = 460,
height = 300,
cwidth = 25;
var color = d3.scale.category20();
var pie = d3.layout.pie()
.sort(null).value(function(d) {
return d.value; //since score is the parameter for the pie
});
var arc = d3.svg.arc();
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height)
.append("g")
.attr("transform", "translate(" + width / 2 + "," + height / 2 + ")");
var gs = svg.selectAll("g")
.data(dataset)
.enter()
.append("g");
var path = gs.selectAll("path")
.data(function(d) {
return pie(d.children);
})
.enter().append("path")
.attr("fill", function(d, i) {
return color(i);
})
.attr("d", function(d, i, j) {
return arc.innerRadius(10 + cwidth * j).outerRadius(cwidth * (j + 1))(d);
});
<script src="https://d3js.org/d3.v3.min.js"></script>

Tooltip in multiple ring charts d3js

While trying to use the tooltip for each ring in a multiple ring donut chart using d3js , while hovering on the ring it just shows the values for the first child . Below is the code which shows the rings as well as the tooltip . What would I be doing in order to get all the correct item on hover.How do I iterate through the json to get the correct tooltip.
var dataset = [{
"name": "Population Quater",
"code": "POP_QUATER",
"parent": "POP_BY_QUAT",
"children": [{
"name": "POP_CYQ1",
"code": "POP_CYQ1",
"parent": "POP_QUATER",
"value": "6772",
"label": "CYQ1",
"children": []
}, {
"name": "POP_CYQ2",
"code": "POP_CYQ2",
"parent": "POP_QUATER",
"value": "6716",
"label": "CYQ2",
"children": []
}, {
"name": "POP_CYQ3",
"code": "POP_CYQ3",
"parent": "POP_QUATER",
"value": "6714",
"label": "CYQ3",
"children": []
}, {
"name": "POP_CYQ4",
"code": "POP_CYQ4",
"parent": "POP_QUATER",
"value": "6703",
"label": "CYQ4",
"children": []
}, {
"name": "POP_LYQ1",
"code": "POP_LYQ1",
"parent": "POP_QUATER",
"value": "6721",
"label": "LYQ1",
"children": []
}, {
"name": "POP_LYQ2",
"code": "POP_LYQ2",
"parent": "POP_QUATER",
"value": "6671",
"label": "LYQ2",
"children": []
}, {
"name": "POP_LYQ3",
"code": "POP_LYQ3",
"parent": "POP_QUATER",
"value": "6708",
"label": "LYQ3",
"children": []
}, {
"name": "POP_LYQ4",
"code": "POP_LYQ4",
"parent": "POP_QUATER",
"value": "6734",
"label": "LYQ4",
"children": []
}]
}, {
"name": "Transient Pop",
"code": "TRANSIENT_POP",
"parent": "POP_BY_QUAT",
"label": "Transient Pop",
"children": [{
"name": "TRANSIENT_LYQ1",
"code": "TRANSIENT_LYQ1",
"parent": "TRANSIENT_POP",
"value": "54",
"label": "LYQ1",
"children": []
}, {
"name": "TRANSIENT_LYQ2",
"code": "TRANSIENT_LYQ2",
"parent": "TRANSIENT_POP",
"value": "86",
"label": "LYQ2",
"children": []
}, {
"name": "TRANSIENT_LYQ3",
"code": "TRANSIENT_LYQ3",
"parent": "TRANSIENT_POP",
"value": "219",
"label": "LYQ3",
"children": []
}, {
"name": "TRANSIENT_LYQ4",
"code": "TRANSIENT_LYQ4",
"parent": "TRANSIENT_POP",
"value": "191",
"label": "LYQ4",
"children": []
}, {
"name": "TRANSIENT_CYQ1",
"code": "TRANSIENT_CYQ1",
"parent": "TRANSIENT_POP",
"value": "52",
"label": "CYQ1",
"children": []
}, {
"name": "TRANSIENT_CYQ2",
"code": "TRANSIENT_CYQ2",
"parent": "TRANSIENT_POP",
"value": "91",
"label": "CYQ2",
"children": []
}, {
"name": "TRANSIENT_CYQ3",
"code": "TRANSIENT_CYQ3",
"parent": "TRANSIENT_POP",
"value": "222",
"label": "CYQ3",
"children": []
}, {
"name": "TRANSIENT_CYQ4",
"code": "TRANSIENT_CYQ4",
"parent": "TRANSIENT_POP",
"value": "186",
"label": "CYQ4",
"children": []
}]
}, {
"name": "Seasonal Pop",
"code": "SEASONAL_POP",
"parent": "POP_BY_QUAT",
"label": "Seasonal Pop",
"children": [{
"name": "SEASONAL_LYQ1",
"code": "SEASONAL_LYQ1",
"parent": "SEASONAL_POP",
"value": "2",
"label": "LYQ1",
"children": []
}, {
"name": "SEASONAL_LYQ2",
"code": "SEASONAL_LYQ2",
"parent": "SEASONAL_POP",
"value": "24",
"label": "LYQ2",
"children": []
}, {
"name": "SEASONAL_LYQ3",
"code": "SEASONAL_LYQ3",
"parent": "SEASONAL_POP",
"value": "152",
"label": "LYQ3",
"children": []
}, {
"name": "SEASONAL_LYQ4",
"code": "SEASONAL_LYQ4",
"parent": "SEASONAL_POP",
"value": "55",
"label": "LYQ4",
"children": []
}, {
"name": "SEASONAL_CYQ1",
"code": "SEASONAL_CYQ1",
"parent": "SEASONAL_POP",
"value": "2",
"label": "CYQ1",
"children": []
}, {
"name": "SEASONAL_CYQ2",
"code": "SEASONAL_CYQ2",
"parent": "SEASONAL_POP",
"value": "22",
"label": "CYQ2",
"children": []
}, {
"name": "SEASONAL_CYQ3",
"code": "SEASONAL_CYQ3",
"parent": "SEASONAL_POP",
"value": "161",
"label": "CYQ3",
"children": []
}, {
"name": "SEASONAL_CYQ4",
"code": "SEASONAL_CYQ4",
"parent": "SEASONAL_POP",
"value": "55",
"label": "CYQ4",
"children": []
}]
}];
var width = 460,
height = 300,
cwidth = 25;
var color = d3.scaleOrdinal(d3.schemeCategory20);
var pie = d3.pie()
.sort(null).value(function(d) {
return d.value; //since score is the parameter for the pie
});
var arc = d3.arc();
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height)
.append("g")
.attr("transform", "translate(" + width / 2 + "," + height / 2 + ")");
var gs = svg.selectAll("g")
.data(dataset)
.enter()
.append("g")
.attr("class", "arc").on("mouseover", function() {
tooltip.style("display", null);
})
.on("mouseout", function() {
tooltip.style("display", "none");
})
.on("mousemove", function(d, i) {
tooltip.transition().duration(200)
.style("opacity", 0.9);
tooltip.select("div").html(d.children[i].name + ":" + " <strong>" + d.children[i].value + "</strong>")
.style("position", "fixed")
.style("text-align", "center")
.style("width", "120px")
.style("height", "45px")
.style("padding", "2px")
.style("font", "12px sans-serif")
.style("background", "lightsteelblue")
.style("border", "0px")
.style("border-radius", "8px")
.style("left", (d3.event.pageX) + "px")
.style("top", (d3.event.pageY - 28) + "px");
});
var tooltip = d3.select("body").append("div")
.attr("class", "tooltip")
.style("opacity", 0.5);
tooltip.append("rect")
.attr("width", 30)
.attr("height", 20)
.attr("fill", "#ffffff")
.style("opacity", 0.5);
tooltip.append("div")
.attr("x", 15)
.attr("dy", "1.2em")
.style("text-anchor", "middle")
.attr("font-size", "1.5em")
.attr("font-weight", "bold");
var path = gs.selectAll("path")
.data(function(d, i) {
return pie(d.children).map(function(payload) {
return {
payload: payload,
parentIndex: i
}
})
})
.enter().append("path")
.attr("fill", function(d, i) {
return color(i);
})
.attr("d", function(d, i, j) {
return arc.innerRadius(10 + cwidth * d.parentIndex).outerRadius(cwidth * (d.parentIndex + 1))(d.payload);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/4.11.0/d3.min.js"></script>
var dataset = [{
"name": "Population Quater",
"code": "POP_QUATER",
"parent": "POP_BY_QUAT",
"children": [{
"name": "POP_CYQ1",
"code": "POP_CYQ1",
"parent": "POP_QUATER",
"value": "6772",
"label": "CYQ1",
"children": []
}, {
"name": "POP_CYQ2",
"code": "POP_CYQ2",
"parent": "POP_QUATER",
"value": "6716",
"label": "CYQ2",
"children": []
}, {
"name": "POP_CYQ3",
"code": "POP_CYQ3",
"parent": "POP_QUATER",
"value": "6714",
"label": "CYQ3",
"children": []
}, {
"name": "POP_CYQ4",
"code": "POP_CYQ4",
"parent": "POP_QUATER",
"value": "6703",
"label": "CYQ4",
"children": []
}, {
"name": "POP_LYQ1",
"code": "POP_LYQ1",
"parent": "POP_QUATER",
"value": "6721",
"label": "LYQ1",
"children": []
}, {
"name": "POP_LYQ2",
"code": "POP_LYQ2",
"parent": "POP_QUATER",
"value": "6671",
"label": "LYQ2",
"children": []
}, {
"name": "POP_LYQ3",
"code": "POP_LYQ3",
"parent": "POP_QUATER",
"value": "6708",
"label": "LYQ3",
"children": []
}, {
"name": "POP_LYQ4",
"code": "POP_LYQ4",
"parent": "POP_QUATER",
"value": "6734",
"label": "LYQ4",
"children": []
}]
}, {
"name": "Transient Pop",
"code": "TRANSIENT_POP",
"parent": "POP_BY_QUAT",
"label": "Transient Pop",
"children": [{
"name": "TRANSIENT_LYQ1",
"code": "TRANSIENT_LYQ1",
"parent": "TRANSIENT_POP",
"value": "54",
"label": "LYQ1",
"children": []
}, {
"name": "TRANSIENT_LYQ2",
"code": "TRANSIENT_LYQ2",
"parent": "TRANSIENT_POP",
"value": "86",
"label": "LYQ2",
"children": []
}, {
"name": "TRANSIENT_LYQ3",
"code": "TRANSIENT_LYQ3",
"parent": "TRANSIENT_POP",
"value": "219",
"label": "LYQ3",
"children": []
}, {
"name": "TRANSIENT_LYQ4",
"code": "TRANSIENT_LYQ4",
"parent": "TRANSIENT_POP",
"value": "191",
"label": "LYQ4",
"children": []
}, {
"name": "TRANSIENT_CYQ1",
"code": "TRANSIENT_CYQ1",
"parent": "TRANSIENT_POP",
"value": "52",
"label": "CYQ1",
"children": []
}, {
"name": "TRANSIENT_CYQ2",
"code": "TRANSIENT_CYQ2",
"parent": "TRANSIENT_POP",
"value": "91",
"label": "CYQ2",
"children": []
}, {
"name": "TRANSIENT_CYQ3",
"code": "TRANSIENT_CYQ3",
"parent": "TRANSIENT_POP",
"value": "222",
"label": "CYQ3",
"children": []
}, {
"name": "TRANSIENT_CYQ4",
"code": "TRANSIENT_CYQ4",
"parent": "TRANSIENT_POP",
"value": "186",
"label": "CYQ4",
"children": []
}]
}, {
"name": "Seasonal Pop",
"code": "SEASONAL_POP",
"parent": "POP_BY_QUAT",
"label": "Seasonal Pop",
"children": [{
"name": "SEASONAL_LYQ1",
"code": "SEASONAL_LYQ1",
"parent": "SEASONAL_POP",
"value": "2",
"label": "LYQ1",
"children": []
}, {
"name": "SEASONAL_LYQ2",
"code": "SEASONAL_LYQ2",
"parent": "SEASONAL_POP",
"value": "24",
"label": "LYQ2",
"children": []
}, {
"name": "SEASONAL_LYQ3",
"code": "SEASONAL_LYQ3",
"parent": "SEASONAL_POP",
"value": "152",
"label": "LYQ3",
"children": []
}, {
"name": "SEASONAL_LYQ4",
"code": "SEASONAL_LYQ4",
"parent": "SEASONAL_POP",
"value": "55",
"label": "LYQ4",
"children": []
}, {
"name": "SEASONAL_CYQ1",
"code": "SEASONAL_CYQ1",
"parent": "SEASONAL_POP",
"value": "2",
"label": "CYQ1",
"children": []
}, {
"name": "SEASONAL_CYQ2",
"code": "SEASONAL_CYQ2",
"parent": "SEASONAL_POP",
"value": "22",
"label": "CYQ2",
"children": []
}, {
"name": "SEASONAL_CYQ3",
"code": "SEASONAL_CYQ3",
"parent": "SEASONAL_POP",
"value": "161",
"label": "CYQ3",
"children": []
}, {
"name": "SEASONAL_CYQ4",
"code": "SEASONAL_CYQ4",
"parent": "SEASONAL_POP",
"value": "55",
"label": "CYQ4",
"children": []
}]
}];
var width = 460,
height = 300,
cwidth = 25;
var color = d3.scaleOrdinal(d3.schemeCategory20);
var pie = d3.pie()
.sort(null).value(function(d) {
return d.value; //since score is the parameter for the pie
});
var arc = d3.arc();
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height)
.append("g")
.attr("transform", "translate(" + width / 2 + "," + height / 2 + ")");
var gs = svg.selectAll("g")
.data(dataset)
.enter()
.append("g")
.attr("class", "arc").on("mouseover", function() {
tooltip.style("display", null);
});
var tooltip = d3.select("body").append("div")
.attr("class", "tooltip")
.style("opacity", 0.5);
tooltip.append("rect")
.attr("width", 30)
.attr("height", 20)
.attr("fill", "#ffffff")
.style("opacity", 0.5);
tooltip.append("div")
.attr("x", 15)
.attr("dy", "1.2em")
.style("text-anchor", "middle")
.attr("font-size", "1.5em")
.attr("font-weight", "bold");
var path = gs.selectAll("path")
.data(function(d, i) {
return pie(d.children).map(function(payload) {
return {
payload: payload,
parentIndex: i
}
})
})
.enter().append("path")
.attr("fill", function(d, i) {
return color(i);
})
.attr("d", function(d, i, j) {
return arc.innerRadius(10 + cwidth * d.parentIndex).outerRadius(cwidth * (d.parentIndex + 1))(d.payload);
})
.on("mouseout", function() {
tooltip.style("display", "none");
})
.on("mousemove", function(d, i) {
console.log(d)
tooltip.transition().duration(200)
.style("opacity", 0.9);
tooltip.select("div").html(d.payload.data.name + ":" + " <strong>" + d.payload.data.value + "</strong>")
.style("position", "fixed")
.style("text-align", "center")
.style("width", "120px")
.style("height", "45px")
.style("padding", "2px")
.style("font", "12px sans-serif")
.style("background", "lightsteelblue")
.style("border", "0px")
.style("border-radius", "8px")
.style("left", (d3.event.pageX) + "px")
.style("top", (d3.event.pageY - 28) + "px");
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/4.11.0/d3.min.js"></script>
The event handlers were bound to the g tags instead of the path tags :)
try this

Resources