I'm working on a d3 visualization (inside of a flask application) and I'm struggling with getting my map to load. I have a csv file with various data columns as well as a json file with latitude and longitude coordinates. I know my filepaths are correct, yet when I run my app I dont see the map anywhere. Any help would be greatly appreciated.
Here are some of my script tags at the top:
<script src="https://d3js.org/d3.v3.min.js"></script>
<script src="https://unpkg.com/d3-geo@1"></script>
<script src="https://unpkg.com/d3-geo-polygon@1"></script>
<script src="https://unpkg.com/topojson@3"></script>
<script src="https://unpkg.com/topojson-client@3"></script>
<div id="chart"></div>
Here are my svg elements:
var width = 1000, height = 750;
var svg = d3.select("#chart").append("svg")
.attr("width", width)
.attr("height", height);
var modus = "Map", counter = 0;
var map = svg.append("g");
var cities = svg.append("g");
var projection = d3.geo.mercator()
.scale(500)
.translate([-500, 475]);
var path = d3.geo.path().projection(projection);
Here is my csv file:
var data = d3.csv("../static/data/serial_killers/info_v6.csv",
function(data) {
data.forEach(function(d) {
d.DateOfBirth = +d.DateOfBirth;
d.Latitude = +d.Latitude;
d.Longitude = +d.Longitude;
d.NumberOfVictims = +d.NumberOfVictims;
d.DateOfMurderRevised = +d.DateOfMurderRevised;
d.DateAtMurder = +d.DateAtMurder;
//d_id = +d_id;
});
console.log(data[0]);
});
Here is my json file:
d3.json("../static/data/serial_killers/location.json", function(data) {
console.log("hello i am in the loading function")
map.selectAll('.geo-path')
.data(data)
.enter()
.append('path')
.attr('class', 'geo-path')
.attr('d', path)
.attr("visibility", "visible")
.style("stroke-opacity", 1)
.style("fill-opacity", 0.5);
});
cities.selectAll(".cities")
.data(data)
.enter()
.append("circle")
.attr("class", "city")
.attr("id", function(d) { return "id" + d._id;})
.style("fill-opacity", 0)
.style("fill", "#ff0000")
.attr("r", 0)
.attr("cx", function(d) { return projection([d.Longitude,
d.Latitude])[0];})
.attr("cy", function(d) { return projection([d.Longitude,
d.Latitude])[1];});
Here is a slice of my json file:
[
{
"Latitude": 15.64624,
"Longitude": 32.46113,
"": ""
},
{
"Latitude": 37.67971,
"Longitude": -121.9076,
"": ""
},
{
"Latitude": 40.51361,
"Longitude": -74.25005999999998,
"": ""
}
]
I'm not sure if i'm mixing up my 'data' variables or something else is going on. Any help would be greatly appreciated.