score:0
Here is the entire code for review:
!DOCTYPE html>
<html>
<head>
<title></title>
<script src="http://d3js.org/d3.v2.js"></script>
<style>
.link {
stroke: #ccc;
}
.nodetext {
pointer-events: none;
font: 10px sans-serif;
}
</style>
</head>
<body>
<script type="text/javascript">
var w = 1280,
h = 1024;
var color = d3.scale.category20();
var vis = d3.select("body").append("svg:svg")
.attr("width", w)
.attr("height", h);
d3.json("graph3-copy.json", function (json) {
var force = self.force = d3.layout.force()
.nodes(json.nodes)
.links(json.links)
.gravity(.05)
.distance(100)
.charge(-100)
.size([w, h])
.start();
var link = vis.selectAll("line.link")
.data(json.links)
.enter().append("svg:line")
.attr("class", "link")
.attr("x1", function (d) { return d.source.x; })
.attr("y1", function (d) { return d.source.y; })
.attr("x2", function (d) { return d.target.x; })
.attr("y2", function (d) { return d.target.y; });
var node_drag = d3.behavior.drag()
.on("dragstart", dragstart)
.on("drag", dragmove)
.on("dragend", dragend);
function dragstart(d, i) {
force.stop() // stops the force auto positioning before you start dragging
}
function dragmove(d, i) {
d.px += d3.event.dx;
d.py += d3.event.dy;
d.x += d3.event.dx;
d.y += d3.event.dy;
tick(); // this is the key to make it work together with updating both px,py,x,y on d !
}
function dragend(d, i) {
d.fixed = true; // of course set the node to fixed so the force doesn't include the node in its auto positioning stuff
tick();
force.resume();
}
var node = vis.selectAll("g.node")
.data(json.nodes)
.enter().append("svg:g")
.attr("class", "node")
.call(node_drag);
node.append("svg:image")
.attr("class", "circle")
.attr("xlink:href", "https://github.com/favicon.ico")
.attr("x", "-8px")
.attr("y", "-8px")
.attr("width", "16px")
.attr("height", "16px");
node.append("svg:text")
.attr("class", "nodetext")
.attr("dx", 12)
.attr("dy", ".35em")
.text(function (d) { return d.name });
force.on("tick", tick);
function tick() {
link.attr("x1", function (d) { return d.source.x; })
.attr("y1", function (d) { return d.source.y; })
.attr("x2", function (d) { return d.target.x; })
.attr("y2", function (d) { return d.target.y; });
node.attr("transform", function (d) { return "translate(" + d.x + "," + d.y + ")"; });
};
});
</script>
</body>
</html>
The firefox console is telling me the json file is empty. That is not correct I have verified the data is there and the page runs outside visual studio.
score:1
The ASP.NET
project runs at IIS Web Server
and its behavior doesn't like windows directory, so you should set the d3.json()
url property just same as json
file URL
, Actually you are running your project at a virtual server, so you should follow these steps:
Add this code inside
web.config
file<configuration></configuration>
tag to allowIIS
to serve the json file as well, without this code IIS thinks the json file is a path ofURL
.<system.webServer> <handlers> <remove name="BlockViewHandler"/> <add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" /> </handlers> <staticContent> <mimeMap fileExtension=".json" mimeType="application/json" /> </staticContent> </system.webServer>
Get the json file
URL
and give it to thed3.json()
functionIf you are using Razor View Engine you can get the url like this:
'I suggest you keep graph.json inside a folder that is named Data'
var url = "@Url.Content("~/Data/graph.json")"; d3.json(url, function (error, graph) { graph.links.forEach(function (d) { d.source = graph.nodes[d.source]; d.target = graph.nodes[d.target]; });
If you are using ASP.NET Webforms just convert
d3.json()
to this:d3.json("~/Data/graph.json", function (error, graph) { graph.links.forEach(function (d) { d.source = graph.nodes[d.source]; d.target = graph.nodes[d.target]; });
Start from solution explorer and follow the folders to find the graph.json and save it like a windows directory. I'm always using
~
to remove all the path and begin from the top.
Hope this helps.
Source: stackoverflow.com
Related Query
- json file not loading frim Visual Studio 2013
- Importing local json file using d3.json does not work
- No 'Access-Control-Allow-Origin' header is present on the requested resource Error when loading JSON file
- D3.csv not loading the csv file
- loading json file to d3.js
- D3 not rendering map data in JSON file
- d3.js 404 json file not found
- Loading a .csv file in d3.js inside django is not working
- Crossfilter - Loading a JSON file from localStorage
- Links not visible when loading json data dynamically into D3 Network Visualization
- Can not see changes in json file in java project (jsp)
- Loading JSON FIle in FileMaker for D3 in WebViewer
- d3js - force: nodes and links from json file not loaded in my svg during redrawing
- Loading internal JSON data rather than from an external resource / file for a sunburst in d3
- D3 + Angular 4 + chrome not able to read JSON file from local IP
- loading a local JSON file with d3
- D3js pack-layout visualization of generated json file does not work
- Reading json data from a file in d3.js not working
- d3.js not reading my JSON data from PHP file
- scope not updating after loading csv file with d3
- When reading a Json file it would not understand HTML content?
- Take input for treemap using json objects not to read from csv file
- Blank web page without any error while loading json file
- d3js not removing previous element when select a new JSON file
- D3 - tree nodes not built from external JSON file
- Dynamic JSON not loading - D3.js Line chart
- nvd3 not loading json
- Javascript not referencing local json file
- not able to load external json file using d3.js
- d3 js - loading json without a http get
More Query from same tag
- un stacking a stacker area chart in d3
- D3 Binding Text and SVG
- D3 - How to update hidden branches in tree layout
- Can d3.js graph put inside a table?
- Why is constructor function not setting <h6> text correctly?
- How to zoom and translate to center of force directed graph in D3
- How do I debug / catch errors for D3
- D3 chord diagram - selecting individual chords
- Popup form to edit shape position and label?
- Conflict of IonicModal with AngularNVD3 (based on D3)
- d3.map() function not returning expected results
- D3: x-axis with time interval of a year
- Last element added to a D3 bar chart doesn't sort
- Set opacity of circles based on the occurrences in the parent element (Group) - D3.js
- No data in area chart
- D3 JS append to div weird result
- problem with D3 lasso circle element with text
- My right axis is cut off...how do I correct it?
- D3 Javascript / SVG Part III ISsue
- D3 - Selection in differents DIV
- Keep D3 objects size constant on Map while zoom in/out
- How to zoom a d3 chart correctly?
- d3 - Brush/Panning Zoom - disable panning on upper x-axis
- timeformat in d3.js not working
- Numbering the "Number of child's" on a parent node in collapsible tree chart in D3
- Convert d3v6 Observable example using zoom.center
- SVG circles don't get repositioned when zooming leaflet map
- understanding d3 selections
- D3.js Pie Chart transitions
- Linq query to d3.js chart