-1

This is my project so far--->http://jsfiddle.net/ddfsb/2/ Observe the var data in the code.For testing purpose I am using only few records.In reality I have around 89k records.

I have a json file named content.json.This is exactly how it goes:--

["51b59c162de88", [["parties", 0.0, 0.011]]]
["51b59c1b4f52f", [["star-speak", 0.0, 0.006], ["parties", 0.0, 0.011]]]
["51b59c2bdd5c5", [["signature", 0.002, 0.006], ["parties", 0.0037, 0.011]]]
["51b59c10ca18f", [["parties", 0.0, 0.017]]]
["51b59c15913b6", [["parties", 0.0, 0.011]]]
["51b59c2635997", [["fashion", 0.002, 0.006], ["parties", 0.0037, 0.011], ["royal-challenge", 0.002, 0.006]]]
["51b59c1a94870", [["parties", 0.0, 0.011]]]
["51b59c2844bcf", [["royal-challenge", 0.0077, 0.023]]]
["51b59c2d92798", [["signature", 0.002, 0.006], ["parties", 0.0037, 0.011]]]
["51b59c19aaa7f", [["parties", 0.0, 0.011], ["fashion", 0.0, 0.006]]]
["51b59c18ec68d", [["parties", 0.0, 0.028]]]

I want to load the content of this json file without disturbing the output..How do I put this data in to variable.Putting 89K records in my script will be insane.So how do I get rid of this problem.

22
  • Use AJAX to load the JSON data? Commented Jul 3, 2013 at 8:49
  • I want to load json data in to my script.How can i use ajax in this? Commented Jul 3, 2013 at 8:50
  • 3
    a) Your file is not valid JSON. There are multiple arrays in there, so standard JSON parser will fail. b) Do you really need all entries at once? Else build an AJAX solution, that just transfers the required entries. Commented Jul 3, 2013 at 8:52
  • @Dogbert:just have a look at my code.You will realise what my actual problem is. observe the format of var data. Commented Jul 3, 2013 at 8:53
  • You will kill browser if you try to render table with 89K rows. You need grid with paging support. Commented Jul 3, 2013 at 8:54

2 Answers 2

1

You can do it directly from D3.js if you have it in a file:

d3.json("your_file.json", function(json) {
     // do stuff   
});

Although, you should note the comment that states that your data isn't valid JSON. D3.js won't be able to properly handle it in that case.

Sign up to request clarification or add additional context in comments.

2 Comments

I just realised that your question is a duplicate of many other similar questions here in SO. The D3.js tag needs a cleanup ASAP...
Can I ask why my answer is no longer valid?
0

Use an AJAX call to load it from your server. Here's a jQuery implementation:

<script src="http://code.jquery.com/jquery-1.10.0.min.js"></script>
<script>

$(document).ready(function() {
  $.getJSON( "content.json", function(data) {

    // Do stuff with your data here.

  });
});
<script>

5 Comments

I appreciate you answer,buti think you dint see my code,i am using javascript.
jQuery is Javascript. If you prefer you could code this with an xmlHTTPRequest object.
the way I am using it is i am putting up all my data in a variable,if i do it by your method..can you guide me what changes have to be made in my code to render the same output.I have never tried jquery,thats why I was mentioned its javascript
With an AJAX call your data is loaded directly into in a single variable. In my example here the data argument contains the data received from the server. You should be able to move your code that creates the table into the function where I've marked // Do your stuff here with minimal modification. However, your script for rendering 89k rows in a table will take a long time . As Tommi said - you need some paging support for this.
:i havent come across paging in the past,i am going through it now,but if possible can you give me a small fiddle about loading data via ajax,the entire code is done in the above link...

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.