There seems to be an issue with the loading of the JSON file

I have created a JSON representation that I would like to visualize using D3JS as a treemap.

Following this tutorial: https://bl.ocks.org/d3indepth/d4f8938a1fd0914b41ea7cb4e2480ca8

The JSON I generated from the data is displaying correctly in the treemap. However, when attempting to use my own JSON from this link: , the treemap does not appear. What could be causing this issue?

This is the code I am using:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Treemap layout</title>
    <style>
        rect {
          fill: cadetblue;
          opacity: 0.3;
          stroke: white;
        }
        </style>
</head>

<body>
  <svg width="420" height="220">
    <g></g>
  </svg>

  <script src="//d3js.org/d3.v4.min.js"></script>
  <script>

d3.json("test.json", function(error, data) {

    var treemapLayout = d3.treemap()
    .size([400, 200])
    .paddingOuter(10);

    var root = d3.hierarchy(data)

    root.sum(function(d) {
     return d.value;
    });

    treemapLayout(root);

    d3.select('svg g')
      .selectAll('rect')
      .data(root.descendants())
      .enter()
      .append('rect')
      .attr('x', function(d) {return d.x0; })
      .attr('y', function(d) {return d.y0; })
      .attr('width', function(d) {return d.x1 - d.x0; })
      .attr('height', function(d) {return d.y1 - d.y0; })
    })
</script>
</body>
</html>

Answer №1

When working with JSON, it is important to remember that it is case sensitive.

In the Treemap layout, a node must always have a "name" property and a "children" property that is of type array.

Additionally, the leaf nodes of the tree must have a "value" property.

It appears that the tree you are sending does not contain "name" properties on the nodes (although it may not be required) and uses "Children" instead of "children".

Perhaps correcting the cases would resolve the issue.

By the way, JSON conventionally follows camelCase, so your JSON structure deviates from this standard.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the reason for innerHTML not functioning properly when trying to include HTML?

Apologies for my poor English, but I am determined to solve this issue using HTML code. <body> <div id="booklist"> <?php include("../templates/nav.php"); ?> <div class="hero"> <?php include("../templates/aside.ph ...

The mysterious anomaly in Vue.js

I am attempting to assign a data object named types upon receiving a response in the ready() method. This is what I have: export default { data () { return { types: null } }, ready () { TypeService.showAll(1) .then(functio ...

Issue with preventdefault() function in Internet Explorer 8

I've encountered a problem while working on a page that heavily utilizes ajax. Everything seems to be functioning well across different browsers, except for one final step that is broken in IE8 and below. You can view the issue on this demo page: To ...

Extension with a responsive design - Conceal all columns with the exception of the initial one

I am currently utilizing the latest version of jQuery DataTables along with the Responsive extension. While everything is functioning properly on tablets and desktops, I encounter an issue when the screen size drops below approximately 600px. When the res ...

How can I avoid C3.js legends from overlapping when hiding or showing a div?

Every time I visit a specific page, a simple chart is automatically generated: function displayOptions() { $("#div1").show(); chartRef.flush(); } function displayChoices() { $("#div1").show(); } $("#div1").hid ...

Merge multiple arrays into a single array

In this scenario, given the array provided, I am trying to achieve the desired output by modifying the reduce function. While attempting to assign [cur] to a plans key, I noticed that it is only extracting the first element. I suspect the issue lies in the ...

What could be causing a problem with the select query in SQLite for iOS using PhoneGap

Could someone please assist me with retrieving values from a database? Here is my code: <script type="text/javascript" charset="utf-8"> // Wait for Cordova to load document.addEventListener("deviceready", onDeviceReady, false); ...

Retrieve information from a controller and pass it to a Component in AngularJs

Having an issue with passing data from a controller to a component in AngularJs. The data is successfully passed to the template component, but it shows up as undefined in the controller! See below for my code snippets. The controller angular.module(&a ...

Tips on sending data with a unique identifier to the backend through a route parameter

Can anyone help me figure out how to send a message to a specific backend route parameter while passing the current ID? I'm not sure how to inform the system about this ID. Here's the Vuex action: postMessage({commit}, payload, id) { axios.pos ...

Utilize an A-frame feature to dynamically enable or disable a component through a

I have set up a virtual environment using A-frame () with some raining effects and a button. What I want to achieve is to have a function executed when the button is clicked, that function should remove the rain component from the scene. Here is the code s ...

A guide for implementing fast-json-patch in your Angular 2 projects

Looking to incorporate the "fast-json-patch" library into my Angular 2 project. This library can be found at https://github.com/Starcounter-Jack/JSON-Patch. I attempted to include the following code: 'fast-json-patch': 'vendor/fast-json-pa ...

Turn off a feature

I'm having trouble disabling a tooltip that is being utilized from this specific website. The code for setting and calling the tooltip looks like this: this.tooltip = function(){....} $(document).ready(function(){ tooltip(); }); I've attempte ...

In React Native, what is the method for utilizing index.js rather than separate index.ios.js and index.android.js files to create a cross-platform app?

Thank you for the help so far, I am new to React Native, and I'm trying to develop a cross-platform app. Here is my index.js file: import React from 'react'; { Component, View, Text, } from 'react-nativ ...

In making reference to a particular subpage within a parent page

My website is designed with all inner pages linked to one master file. I'm looking to change the title font size on just one specific page, without affecting the rest of the pages that use the master file. Is there a way to target a specific page titl ...

Do NodeJS and Express require sanitizing the request body for post requests to prevent cross-site scripting (XSS) attacks?

There is a website I have where users can input data into fields and submit it. Once submitted, the information is sent to my server through a POST request and saved in the database. However, this user-generated content is also returned to the front-end f ...

What is the best way to implement media queries for mobile phones and desktop computers?

I've come across similar questions before but still can't wrap my head around it. Here's my dilemma: I want the index page of my website to display in desktop layout on desktops and mobile jquery on mobile devices. Currently, I have set up m ...

Exploring the World of JSON Iteration

At my job, I primarily use a language called AL, but we frequently work with JSON Objects, Arrays, and more. Currently, I am accessing data from this API: , and saving the result in a text variable. My goal is to create a separate table containing the ID ...

Modify a JavaScript object in JSON format using another object as reference

Consider two JSON formatted JavaScript objects: obj1 = { prop1: 1, prop2: 2, prop3: 3 } obj2 = { prop1: 1, prop2: 3 } In the context of jQuery or Angular, what is the recommended practice to update obj2 into obj1 while also re ...

The path aligns with the route, yet the component designated for that route fails to render

I wrote a React component named Workout that looks like this: const Workout = props => { console.log(props); return ( <div> <h1>hello</h1> </div> ); }; export default Workout; Next, I imported this componen ...

"Utilizing jQuery to set up a backup URL for a

Here is a code snippet I created to dynamically load a language file for a webpage based on the user's browser language: $.ajax({ 'async': false, 'global': false, 'url': "./languages/"+navigator.languag ...