3

Previously I was using a json file with the following format:

[{"lat":43.788458853157117,"lng":-79.282781549043008,"category":"volunteer","name":"Rita","url":"", "description":"xxx is a member of 13"},{"lat":43.7,"lng":-79.4,"category":"organization","name":"TCAN","url":"http://tcan.ca","description":"Lorem ipsum"}]

Now I am attempting to generate the json file from a Drupal site and am getting the following structure. How can I reference the lowest level fields. I have looked at examples using d3.net but have not found any that apply.

{
    "organizations": [
        {
            "member": {
                "field_category": "organization",
                "body": "A network of organizations in Toronto devoted to climate change mitigation and adaptation.",
                "URL": "xxx.ca",
                "title": "Toronto Climate Action Network",
                "field_lat": 43.7,
                "field_long": -79.4
            }
        },
        {
            "member": {
                "field_category": "abc",
                "body": "xxx.",
                "URL": "",
                "title": "yyy",
                "field_lat": 43.7,
                "field_long": -79.28
            }
        }
    ]
}

1 Answer 1

2

Assuming that your data is stored in the variable data:

var bottom = data.organizations.map(function(d) { return d.member; });
Sign up to request clarification or add additional context in comments.

4 Comments

I am using the following code to access the json file - how would this fit in? d3.json("d3_files/json/members4.json",function(error,data){ circles.selectAll("circle") .data(data) .enter() .append("image") .attr("xlink:href", function(data) { return lookupTable[data.category](); }) // end attr .attr("width", 64) // dimention of image .attr("height", 64) .attr("transform",function(data){ return"translate("+projection([data.lng,data.lat])+")" }) // end transform attr
In particular how would I reference the "body" field?
You would use bottom instead of data in your D3 code after the conversion. To reference the body field, you can use something like d3.selectAll("text").data(bottom).enter().append("text").text(function(d) { return d.body; }).
Lars, many thanks. That really helped me and I got it to work. Clearly I am still missing some fundamentals.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.