score:2
It seems that there was an issue with your scale and center point. According to the d3-geo API, there is the method fitSize, which allows you to place easily on your projection inside a container.
Here is a snippet with (data is hardcoded inside it) :
var data ={
"type":"FeatureCollection",
"features":[
{
"type":"Feature",
"id":"CYP",
"properties":{
"name":"Cyprus"
},
"geometry":{
"type":"Polygon",
"coordinates":[
[
[
33.973617,
35.058506
],
[
34.004881,
34.978098
],
[
32.979827,
34.571869
],
[
32.490296,
34.701655
],
[
32.256667,
35.103232
],
[
32.73178,
35.140026
],
[
32.919572,
35.087833
],
[
33.190977,
35.173125
],
[
33.383833,
35.162712
],
[
33.455922,
35.101424
],
[
33.475817,
35.000345
],
[
33.525685,
35.038688
],
[
33.675392,
35.017863
],
[
33.86644,
35.093595
],
[
33.973617,
35.058506
]
]
]
}
}
]
}
var width = 960,
height = 500;
var projection = d3.geoEquirectangular().fitSize([width, height], data); // adding fitSize method instead of center and scale.
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height);
var path = d3.geoPath()
.projection(projection);
var g = svg.append("g");
g.selectAll("path")
.data(data.features)
.enter()
.append("path")
.attr("d", path)
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/5.5.0/d3.min.js"></script>
Source: stackoverflow.com
Related Query
- Unable to display a JSON map using d3.js
- Unable to display line chart for this JSON structure using D3.js?
- D3 map should read second external json data using queue and display on Hover
- How to divide a map into zipcodes using d3, javascript, and a json file?
- Displaying a JSON file as a map using D3js v4
- How to display each state name in d3 india map using GeoJSON
- Trying To Plot Json Data On World Map Using leafletjs But Data Displayed is Not Accurate
- Unable to load json file in html using d3.js
- Display geojson on a map using d3.js and d3-tile
- Unable to display table data from array using D3.js
- Visualizing world map using D3.js but cant visualize the json file
- Display legend in map chart using d3 in angularjs
- Unable to create a bar chart from json data using d3.js
- Using D3 version 5 to plot a map using JSON File
- Display Bar Chart for Last week, Last Month, and Last Year Data from JSON using D3.js
- 404 error - unable to find JSON file when making a map but it looks like it's in the right place
- How to save the state of the Map view using angularjs and in JSON format?
- Unable to display a polygon using d3
- Unable to render simple graph in d3.js by reading data from MySQL using JSON
- Importing local json file using d3.json does not work
- Properly display bin width in barChart using dc.js and crossfilter.js
- Displaying map using d3.js and geojson
- How do I create a tree layout using JSON data in d3.v4 - without stratify()
- Zooming and Panning a Mercator Map centered on the Pacific using d3.js
- Using d3.js, how can I display data faster on my chart?
- Display text on rect using D3.js
- Using JSON data in D3 Javascript visualisation
- d3.js, using d3.extent to find min/max of nest json values
- Rendering only a portion of a topojson map using D3.js
- D3 - Large GeoJSON File does not show draw map properly using projections
More Query from same tag
- Dynamically change width of d3.js sankey chart
- Why is domain not using d3.max(data) in D3?
- How to manipulate the Z-index of an SVG
- d3js path generator in collapsible tree layout
- d3JS v5 specifying domains from nested data for grouped bar charts
- D3.js Stacked Bar Chart, from vertical to horizontal
- D3 force directed graph drag and zoom functions not working
- How to add header row to d3.csv generated table
- nvd3 controls into 2 line
- D3 Mouseover and Mouseout
- d3 doesnt produce any output
- how can I put one element under another in d3.js
- multiple d3 graphs in one svg
- "Pinning" nodes in a D3 force-directed graph
- organizing objects by name
- d3 get element or object under current mousepointer?
- "TypeError: d is undefined" when transitioning on a bar chart with a mouseover event
- D3js filter selection
- d3.event.loaded in d3 version 4
- Is there a method to find a Y value that is exceeded X % of the time in a time series?
- d3.csv map column values as keys in object
- highlight neighbor in the force layout
- add JavaScript to w2ui panel
- In D3 how do you add labels to features in geojson feature collection
- D3.js - Donut charts with multiple rings
- D3 directed graph nodes as rectangle
- What exactly does extra select() on enter() selection do?
- How to append an svg loaded by d3.xml into an svg
- How best to use D3 without duplicating lots of code?
- D3 circles too big after reappearing