xxxxxxxxxx
<head>
<meta charset="utf-8">
<script src="https://d3js.org/d3.v3.min.js"></script>
<style>
body { margin:0;position:fixed;top:0;right:0;bottom:0;left:0; }
.line {
fill: none;
stroke: black;
stroke-width: 1.5px;
}
</style>
</head>
<body>
<script>
// Feel free to change or delete any of the code you see in this editor!
var svg = d3.select("body").append("svg")
.attr("width", 960)
.attr("height", 500)
var width = 800;
var height = 400;
// Ordinal scale
var x = d3.scale.ordinal()
.rangeRoundBands([0, width], .5);
var y = d3.scale.linear()
.range([height, height - 200]);
var line = d3.svg.line()
.x(function(d) { return x(d.name); })
.y(function(d) { return y(d.value); });
var g = svg.append("g")
.attr("transform", "translate(10, 0)")
d3.json("data_noms_stats.json", function(data) {
svg.selectAll("text").data(data).enter()
.append("text")
.text(function(d, i) { return "bob"; })
.attr("y", 420 )
.attr("x", function(d) { return x(d.name); })
.style("font-size", 10)
.style("font-family", "monospace");
g.selectAll(".value").data([data[data.length -1]]).enter()
.append("text")
.text(function(d, i) { return displayValue(d.value); })
.attr("class", "value")
.attr("y", function(d) { return y(d.value); })
.attr("x", width - 20)
.style("font-size", 20)
.style("font-family", "monospace");
g.selectAll("circle").data(data).enter().append("circle")
.attr("cx", function(d) {return x(d.name);})
.attr("cy", function(d) {return y(d.value);})
.attr("r", function(d) {return 10;})
.style("fill", "#b5b5fc")
.on("mouseover", function(d) {
d3.select(this).style("fill", "#4e4ef7");
g.selectAll("tooltip").data([d]).enter().append("text")
.text(function(d) {return d.value;})
.attr("id", "tooltip")
.attr("x", function(d) {return x(d.name)})
.attr("y", function(d) {return y(d.value) - 10})
g.selectAll("#tooltippath").data([d]).enter().append("line")
.attr("id", "tooltippath")
.attr("class", "line")
.attr("d", line)
.attr("x1", function(d){return x(d.name)})
.attr("x2", function(d){return x(d.name)})
.attr("y1", height)
.attr("y2", function(d){return y(d.value)})
.attr("stroke", "black")
.style("stroke-dasharray", ("3, 3"));
})
.on("mouseout", function(d) {
d3.select(this).style("fill", "#b5b5fc");
g.selectAll("#tooltip").remove();
g.selectAll("#tooltippath").remove();
});
g.selectAll("path").data([data]).enter().append("path")
.attr("class", "line")
.attr("d", line);
});
</script>
</body>
https://d3js.org/d3.v3.min.js