Having difficulties with getting D3 JavaScript/JSON to execute

I've been attempting to run this tutorial script, but for some reason, I just can't seem to get it to execute properly. Can someone please take a look and help me figure out what I'm missing? I would greatly appreciate it!

Here is the original tutorial link:

<!DOCTYPE html>
<meta charset="utf-8">
<style>

#demo{
height: 200px;
background-color: blue;
}


</style>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script> var JSONData = [
  { "id": 3, "created_at": "Sun May 05 2013", "amount": 12000},
  { "id": 1, "created_at": "Mon May 13 2013", "amount": 2000},
  { "id": 2, "created_at": "Thu Jun 06 2013", "amount": 17000},
  { "id": 4, "created_at": "Thu May 09 2013", "amount": 15000},
  { "id": 5, "created_at": "Mon Jul 01 2013", "amount": 16000}
]
</script>;

<head></head>
<body>

<div id="demo"></div>

</body>


<script>

(function() {
  var data = JSONData.slice();
  var format = d3.time.format("%a %b %d %Y");
  var amountFn = function(d) { return d.amount };
  var dateFn = function(d) { return format.parse(d.created_at) };

  var x = d3.time.scale()
    .range([10, 280])
    .domain(d3.extent(data, dateFn));

  var y = d3.scale.linear()
    .range([180, 10])
    .domain(d3.extent(data, amountFn));
  
  var svg = d3.select("#demo").append("svg:svg")
  .attr("width", 300)
  .attr("height", 200);

  svg.selectAll("circle").data(data).enter()
   .append("svg:circle")
   .attr("fill", white)
   .attr("r", 4)
   .attr("cx", function(d) { return x(dateFn(d)) })
   .attr("cy", function(d) { return y(amountFn(d)) });
})();

</script>

Answer №1

Spelling Error

  svg.selectAll("circle").data(data).enter()
   .append("svg:circle")
   .attr("fill", white)
                 ^^^^^
   .attr("r", 4)
   .attr("cx", function(d) { return x(dateFn(d)) })
   .attr("cy", function(d) { return y(amountFn(d)) });

The correct string should be "white"

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

Enhancing jQuery functionality: Ensuring newly added elements are aware of existing functions

I need assistance with my HTML table. Each row (tr) contains a value, for example 200$, and a delete button. How can I ensure that each new row added automatically knows the recent functions without having to call them every time? $(function () { $(&ap ...

Comparing sqlsrv_fetch_array with sqlsrv_fetch_object

Currently using PHP with both MS SQL Server 2005 and 2012. I'm curious about the variances between sqlsrv_fetch_array and sqlsrv_fetch_object functions. Can anyone help clarify? ...

What is the best way to use the map function to print an array of arrays containing objects in a React component?

I am dealing with a functional component that takes an array of arrays with objects, but I am struggling with accessing the data in the render return function. let dataItems = [ [ { data1: "1234", data2: "ABCD", ...

What is the resolution if I need to utilize a property that is untyped?

Transitioning to TypeScript from plain old JavaScript is a step I'm taking because I believe it offers significant advantages. However, one drawback that has come to light is that not all attributes are typed, as I recently discovered. For instance: ...

Annotation of JSONDoc on complex objects with multiple dimensions

I have been attempting to add annotations from JSONDoc onto multidimensional objects, but I have been encountering difficulties. For example: @ApiObjectField(description = "Multidimensional array with flags") private boolean[][] flags; An error occurs a ...

Struggling to combine select dropdown choices in one calculation

​​I'm currently working on a project where I need to create a website that multiplies three numbers selected from dropdown menus together. However, when I attempt to perform the calculation, I only get the result "1" displayed. I've spent sev ...

Searching for data between two specific dates can be achieved in Laravel Vue by utilizing the filter

I've successfully implemented a search feature for normal fields in my form. However, I'm encountering difficulty when trying to search within a date range. Here's my controller code: public function index() { $query = Matter::query(); $qu ...

Place a cookie on the alternate language domain

Within my website, we utilize 2 distinct domains, each dedicated to a different language. www.mysite.com en.mysite.com I am interested in implementing JavaScript to establish a cookie on en.mysite.com when clicking a link on www.mysite.com. Here is my ...

Deliberately "locking" a JavaScript variable with a immediately-invoked function expression

While browsing through a blog post here that discusses creating a web scraper using node.js, I stumbled upon an intriguing piece of javascript that has left me somewhat perplexed. This particular snippet of code seems like something I could implement in my ...

Button on aspx page not functioning properly when clicked

I seem to be experiencing an issue with buttons. To check if the function is being triggered, I used alert("") and found that it does enter the function when the button is clicked. However, after the alert, any other code inside the function seems to not w ...

Parsing additional JSON strings from a single file

Having two separate JSON files, I am looking to combine them and extract JSON strings from one of the files. {"ipAddress":"1.1.1.1","port":80, "protocol":"http"} {"ipAddress":"1.1.1.1", "domainName":"domain.com"} I attempted a solution, but it is not fu ...

Dynamic fields added using JavaScript are not recognized by PHP

I have a MySQL database where orders are stored along with various activities. My PHP/HTML page retrieves these activities when an order is clicked and allows users to modify them using a form. Upon submission, another PHP file updates the database by loop ...

Encountered a problem while trying to connect to WCF service using c

Currently, I am in the process of developing a SOAP software solution for one of our clients. The reason behind this migration to SOAP is that we have plans to launch a mobile application soon. After creating the .svc file and successfully establishing a ...

I'm curious about the origin and purpose of req.user - where does it come from and

Recently, I've been delving into Nestjs and found myself a bit puzzled by the req.user. Where does this come from and do we have to manually request it? What exactly is req.user and what advantages does it offer? Must I assign payload to it manually? ...

Uh oh! The dreaded Error [ERR_HTTP_HEADERS_SENT] has struck again in the Node Express MongoDB world. Headers cannot be set after they have

Hey there, newbie in the coding world! I've been diving into a guide on setting up a backend server using Node.js, Express, and MongoDB. You can find the guide here: But I seem to keep running into an error when testing with Postman. Error [ERR_HTTP ...

Exploring JSON response handling in jQuery using Coffeescript

When retrieving data from a JSON using an HTTP request, I am faced with a challenge. The response contains 10 objects, each comprising multiple keys. Although I can access a particular object, extracting the key proves to be difficult. The following code ...

Struggling to incorporate typeWriter.js into the code with no luck

I'm attempting to make this script work. The script is designed to be referenced from an external script file, but I need it to be embedded for certain reasons which I won't delve into. I believe I've set it up correctly, but it seems that w ...

While in the process of developing a React application, I have encountered the following challenge

PS F:\Programming Tutorials Videos\R Practice> npx create-react-app custom-hook npm ERR! code ENOTFOUND npm ERR! syscall getaddrinfo npm ERR! errno ENOTFOUND npm ERR! network request to https://registry.npmjs.org/create-react-app failed, reaso ...

Struggling to identify the cause of the null pointer exception error

Lately, I've been working on developing an Android app and everything was running smoothly up until now. Suddenly, I encountered a null pointer error that has me stumped. The strange thing is that the app was functioning perfectly before this error po ...

Encountering a parsing error with JSON - Type mismatch detected

I have a sample JSON data that looks like this: { "findItemsByKeywordsResponse":[ { "ack":[ "Success" ], "version":[ "1.13.0" ], "timestamp":[ "2015-02-10T18:12:21.785Z" ], "searchResult":[ ...