0
私はcsvの値を集計し、折れ線グラフ(現在のチームの強さを数ヶ月にわたって)を使って値を集計しようとしています。さて、私は何もエラーを取得していない、&は、グラフが読み込まれています。何が欠けているのか分からないようです。ここでD3折れ線グラフが挿入されません。何が欠けている?
は私のコードです:
<!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"
}
]
そんなにGilshaありがとうございます。完璧に動作します! :-) – Anip
喜んでそれは助け:) – Gilsha