How could I add insert a d3js script inside a post which would show me the charts there .I see the results in a black window and it works on hover.
This is the correct one on a html page right now.
<svg width="900" height="640"></svg>
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/4.4.4/d3.min.js" type="text/JavaScript"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3-queue/3.0.3/d3-queue.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/topojson/2.2.0/topojson.min.js"></script>
<script>
var svg = d3.select("svg"),
width = +svg.attr("width"),
height = +svg.attr("height");
var projection = d3.geoAlbers()
.translate([width / 2, height / 2])
.scale(1280);
var radius = d3.scaleSqrt()
.domain([0, 100])
.range([0, 14]);
var path = d3.geoPath()
.projection(projection)
.pointRadius(2.5);
var circles = svg.append("svg:nflteams")
.attr("name", "circles");
var voronoi = d3.voronoi()
.extent([[-1, -1], [width + 1, height + 1]]);
d3.queue()
.defer(d3.json, "us.json")
.defer(d3.csv, "nflteams.csv", typeTeam)
.defer(d3.csv, "nflresults2017.csv", typeSeason)
.await(ready);
function typeTeam(d) {
d[0] = +d.longitude;
d[1] = +d.latitude;
d.arcs = {type: "MultiLineString", coordinates: []};
return d;
}
function ready(error, us, nflteams, nflresults2017) {
if (error) throw error;
var teambyName = d3.map(nflteams, function(d) { return d.name; });
nflresults2017.forEach(function(nfl2017) {
var source = teambyName.get(nfl2017.origin),
target = teambyName.get(nfl2017.destination);
source.arcs.coordinates.push([source, target]);
target.arcs.coordinates.push([target, source]);
});
nflteams = nflteams
.filter(function(d) { return d.arcs.coordinates.length; });
svg.append("path")
.datum(topojson.feature(us, us.objects.land))
.attr("class", "land")
.attr("d", path);
svg.append("path")
.datum(topojson.mesh(us, us.objects.states, function(a, b) {return a !== b;}))
.attr("class", "state-boundary")
.attr("d", path);
svg.append("path")
.datum({type: "MultiPoint", coordinates: nflteams})
.attr("class", "nflteam-dots")
.attr("d", path);
var nflteam = svg.selectAll(".nflteam")
.data(nflteams)
.enter().append("g")
.attr("class", "nflteam");
nflteam.append("title")
.text(function(d) { return d.name + "\n" + d.wins + " wins"; });
nflteam.append("path")
.attr("class", "nflteam-arc")
.attr("d", function(d) { return path(d.arcs) })
.text(function(d){return "test" + d.wins;});
nflteam.append("path")
.data(voronoi.polygons(nflteams.map(projection)))
.attr("class", "nflteam-cell")
.attr("d", function(d) { return d ? "M" + d.join("L") + "Z" : null; });
circles.selectAll("circle")
.data(nflteams)
.enter().append("svg:circle")
.attr("r", function(d) { return d.wins*100; });
}
function typeSeason(d) {
d.result= +d.result
;
return d;
}
</script><img src="//cdck-file-uploads-global.s3.dualstack.us-west-2.amazonaws.com/flex036/uploads/gohugo/original/2X/9/9b7d43fda298c59ee8ce2477491cebfa58dd2980.PNG" width="690" height="404">