Utilizing D3.js v4 to showcase a JSON file on a map

I am attempting to create a map similar to the one created by Mike Bostock.

You can access my JSON file (here), which represents Europe divided into NUTS 2 regions. The structure of the JSON file is as follows:

{
    "type": "Topology",
    "objects":
    {
        "nuts2":
        {
            "type": "GeometryCollection",
            "bbox": [-63.15345500000001, -21.387309500000015, 55.83662850000002, 71.18531800099998],
            "geometries": [
            {
                "type": "Polygon",
                "properties":
                {
                    "nuts_id": "AT11",
                    "name": "Burgenland (AT)",
                    "population": 286691
                },
                "id": "AT11",
                "arcs": [
                    [0, 1, 2, 3, 4]
                ]
            },
            ...
...

To display the European map colored with the Italian vaccination coverage data from the CSV file using radio buttons for antigen selection.

Upon testing two solutions in creating the map, I encountered issues. The first solution didn't display anything while the second had trouble locating the path for the CSV file.

Here are snippets of code from my attempts:
// First Solution (map.js)
// Code runs but doesn't display the map

// Second Solution (map.js)
var width = 700;
var height = 600;

...
...

If anyone can assist me in resolving these issues, I would greatly appreciate it.

Answer №1

When dealing with a BIG JSON file, do we need to extract only the information related to Italy or include all EU data? Let's proceed by running with the full JSON and breaking down the steps from simple to difficult.

#index.html

Add the following code snippet to the top of your HTML document: <!DOCTYPE html>
Correct the script source path as follows:

<script src="https://d3js.org/topojson.v2.min.js"></script>

#map.js (in JavaScript section)

Steps one and two:

var width = 700;
var height = 600;

var svg = d3.select("#container-map").append("svg")
  .attr("width", width)
  .attr("height", height);

// more code here...

Step three and four:

Now that you've worked successfully with the JSON data, let's move on to handling CSV files (specifically coverage data for Italy). The process involves working with different delimiters such as ",", ";", etc. Finally, we'll delve into integrating a database (CSV) for enhanced data management.

Step five:

In this step, we'll focus on color filling the map for a specific region in Italy - Piemonte. Emphasis will be given on parsing data from the CSV embedded within an HTML element.

Update 1 (2020):

An original CSV file 'Coverage Italy 24 months.csv' was deleted causing a halt in operations. However, efforts are now being made to implement color filling specifically for the Piemonte region.

(Data from CSV stored inside an HTML <pre> tag)

<pre id="data-IT">
ID;NUTS2-ID;NUTS2-NAME;YEAR;ANTIGEN;COVERAGE-PERC
1;IT;Italy;2000;POL;96,6
...
</pre>

For access to DB(CSV) utilizing D3:

var data = d3.dsvFormat(delimiter).parse(d3.select("pre#data-IT").text());

Visit the provided link for further details and test out the Beta version. Wishing you a HAPPY NEW YEAR!

https://i.sstatic.net/qnotD.png PS: Explore this example further on JSFiddle

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

ReferenceError: _jquery2.default.ajax is not a function" encountered in a React Native application

I have been attempting to use jQuery to retrieve xml data from an internal website. My expo project setup is quite basic and resembles the following: import React from 'react'; import { StyleSheet, Text, View } from 'react-native'; imp ...

Content OverFlow: DropDown Menu is not overlapping the content, but rather pushing it downwards

In my webpage, I have a drop-down menu that traditionally pushes the content below it down to make space for its items. However, I want the drop-down to overlap the contents below without affecting their position. I've tried various solutions, such a ...

Managing the versions of ViewState and serialized objectsIs this what you

We utilize ASP.NET viewstate to store custom objects (as opposed to only primitive types). With each build, the build number undergoes incrementation. The challenge we face arises during a server update: Visitor loads the page We roll out a fresh build o ...

Using an array in jade rendering

I'm currently working on a node.js server using express and I'm facing an issue with passing an array to jade rendering. Here's the code snippet from my node.js file: router.get('/render', function(req, res) { var t; var ...

Utilize ngFor in Angular Ionic to dynamically highlight rows based on specific criteria

I'm working on an application where I need to highlight rows based on a count value using ngFor in Angular. After trying different approaches, I was only able to highlight the specific row based on my count. Can someone please assist me? Check out m ...

Ways to transmit the appropriate model

Using AJAX, I am sending a model to the server via a POST request. I have defined a model and a controller method for processing it. public class TestDto: BaseDto { [Required] public ProductGalleryDto GalleryProduct { get; set; } public int ...

The CSS stylesheet is not being applied to the components in Next.js

I am currently facing an issue with styling my React/Next component. Despite trying to apply a stylesheet to enhance its appearance, the CSS doesn't seem to be taking effect. Could someone please provide guidance on how I can resolve this? I have att ...

JavaScript not functioning properly with HTML loaded via .load()

I'm facing a perplexing dilemma: My issue revolves around this JS code: EDIT updated JS $(".img-thumb").on("click", function(){ // displaying the same behavior as .click() thumbID = $(this).attr("id"); console.log(thumbID); $(".gal-act" ...

Using JSON in Highcharts: Customizing Border and Label Colors

Currently using Highcharts in JSON format with the following syntax: var neutral_color = '#c4c4c4', medium_grey = '#929292'; lineChartJSON['chart']['plotBorderColor'] = medium_grey; lineChartJSON['chart&ap ...

Move the option from one box to another in jQuery and retain its value

Hey guys, I need some assistance with a jQuery function. The first set of boxes works perfectly with the left and right buttons, but the second set is not functioning properly and doesn't display its price value. I want to fix it so that when I click ...

Splitting a string in Typescript based on regex group that identifies digits from the end

Looking to separate a string in a specific format - text = "a bunch of words 22 minutes ago some additional text". Only interested in the portion before the digits, like "a bunch of words". The string may contain 'minute', & ...

What is the best way to add a `<div>` before or after a specific `<p>` element based on the client's height?

I am facing an issue with inserting a div before a paragraph element based on the given clientHeight. Specifically, I need to locate the closest paragraph element from the specified clientHeight and then add a div before or after that particular element. ...

Selenium WebDriver keeps crashing with a newSession error after around 70 seconds of running

Recently, a perplexing error surfaced in my previously functional project without any changes to the code. The sudden appearance of this issue may be attributed to a FireFox update or a dependency failure. To help troubleshoot the abrupt cessation, I added ...

Discovering ways to optimize argument type declarations in TypeScript

If we consider having code structured like this: function updateById( collection: Record<string, any>[], id: number, patch: Record<string, any> ): any[] { return collection.map(item => { if (item.id === id) { return { ...

Tips for concealing the bar graph while maintaining the visibility of the data labels in HighCharts

Is there a way to hide one bar but keep the data labels in HighCharts? I have 3 bars: Target Realization Percentage I want to display only the first and second bars, with only 1 data label which is the percentage. So, I made some adjustments to my co ...

The render props on the child component are not appearing on the screen as expected

Recently diving into React Native, I created a stateless component designed to iterate through props that contain objects with arrays of tags. The goal was to extract and display a single tag from each array item. (Refer to the console log in the screensh ...

Limit the selected values to calculate a partial sum

Imagine two distinct classes called professor and student: professor.ts export class Professor { id: number name: string } student.ts import { Professor } from "./professor" export class Student { ...

The issue of Rails 4 serving JavaScript as plain text instead of executing it when attempting to utilize AJAX

I am in the process of constructing a basic page layout featuring two side-by-side columns. The left column is intended for user input via a form submission. Upon submitting the form, I want the right column to dynamically update (using AJAX) and display a ...

Mapping dynamic JSON in JAX-RS: A comprehensive guide

I need to convert a JSON structure into Java Plain Old Java Objects (PoJos) using JAX-RS with Resteasy as the implementation. The challenge lies in the fact that the JSON is dynamic, as illustrated in the following example: { "typeCode": "SAMPLE", "da ...

Information that is not included in the Linq query's join will not be present in the resulting JSON output. Only data that is connected in both classes will be displayed

This question is based on a previous question: Combining 2 classes with added data and having one table consist of a collection list from the other table, aiming to use linq for display Initially, I believed that the issue had been resolved. However, af ...