Hi so i'm in the middle of learning the D3 Framework, but no matter what I do, I can't seem to load my Json file. I'm running the script on a server and the JSON file is in the same directory as the html/d3 file im running it from but it keeps giving me a 404 error when I look at the console.
So Im running it on www.mywebsite.com, and then I have the Json file stored in www.mywebsite.com/mydata.json
Can anyone help me out?
<script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script>
</head>
<body>
<script type="text/javascript">
d3.json("mydata.json", function(data){
var canvas= d3.select("body").append("svg")
.attr("width",500)
.attr("height", 500)
canvas.selectAll("rect")
.data(data)
.enter()
.append("rect")
.attr("width", function(d){ return d.age *10;})
.attr("height", 50)
.attr("y", function(d ,i){ return i* 50; })
.attr("fill", "blue");
});
</script>
Take a look at this and this gotchas. Let us know if you succeeded accessing json after that.
You guys need not change any Formats. Just need to change some settings in Server.Here I am using IIS server so I have tested my files and got same 404 error for JSON Files and I made the following changes and it worked like a Charm. You just follow this If you are using an IIS Server...
Step 1: Open IIS Server and go to MIME Types
Step2: Click Add from right side and add JSON extension and restart the server
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With