score:1
d3 works best when working with an array of objects. I would suggest restructuring your raw data so it looks like this:
[{x:1, y:2}, {x:2, y:100}, {x:3, y: 321}, ect}]
Right now,
.selectAll("li")
.data(data)
is joining each element of the data array to an 'li' element. Since data looks like this:
[
"x":[1, 2, 3, ect],
"y:[2, 100, 321, ect]
]
there are only two elements to join, "x" and "y". When you try to look up each elements x property with
.text(function (d, i){
console.log(d.x[i]);
it doesn't exist because 'd' is just an array.
score:0
Since d3 works best with and array of objects it would be best to restructure the raw data. If restructuring the raw data is not an option you can do restructure the data on-the-fly at runtime. The code in this fiddle should do the trick.
If you don't want to change the data you can also use it as-is if you change some parts script. Instead of passing data
to the .data()
function pass data.x
or data.y
. If you do this you can look at the corresponding element by data.x[i]
Here is a fiddle demonstrating this.
Source: stackoverflow.com
Related Query
- D3 is not rendering graph from an object list?
- Graph not rendering my Date data
- D3 - create network graph from 2 column list of nodes
- d3.js force layout graph : how to build the nodes object from scratch?
- Graph not rendering correct scale with NVD3
- D3.js code not rendering in browser when loaded from file, but works fine in console
- Stacked area graph not rendering
- Bar graph is not rendering
- NVD3 Sparkline not rendering correctly from CSV file
- Get the data from a GET request before rendering D3.js graph
- Update D3 Line Graph from List Options
- arrow d3 graph svg not rendering
- Line Graph using D3 is not starting from the date i want it to
- Could not group by list item in javascript object
- D3 Graph not rendering when using Timescale
- d3 functions not working in node.js when rendering charts from the server side
- D3 Line graph is not rendering on IE8
- d3 for loop retrieving data from a list of object
- Passing json object from grails controller to a gsp rendering a d3 chart?
- Line graph in d3 rendering but not displaying
- list will not go under d3.js graph
- I am trying to fill color of bars in a graph (svg element) using column values from a csv file, not working
- React component not rendering after useRef object gets updated
- D3 graph not displaying JSON information from variable
- How to transition line graph in d3.js ver4 when triggered by selection from dropdown list
- d3 function(d) return value from object not from the first index(0)
- Updating links on a force directed graph from dynamic json data
- SVG not rendering properly as a backbone view
- NVD3 Charts not rendering correctly in hidden tab
- Render D3 graph from a string of JSON instead of a JSON file
More Query from same tag
- D3.js: Rotate text on-spot
- d3 xScale is broken
- Element no longer draggable after adding parameter to d3 drag behavior
- D3 Hive plot highlight Node and its links
- How to display JSON data in form of different tree-like layouts?
- Margin Convention bugs?
- d3 mouseover on element conflicts with svg mousemove
- Problems with D3.js graph - single data element won't show up
- D3 annotations in wrong place along x axis
- hide one of the axes of a parallel-coordinates plot
- D3 bar chart and html data attributes
- Issue with scale module d3 on react
- In D3 zoomable sunburst, how to show only one level of children
- How to change the opacity of dots on overlap in d3js
- Not all d3 points are showing in correct position on leaflet map
- D3 Selection Works while svg Selection Doesn't
- In Spotfire Mods can I determine what has changed in the dataview as part of the reader?
- d3.js - Multiple line chart doesn't update circles
- How do I animate a line using d3.js?
- dynamic diameter in bubble chart in d3.js
- d3 line smoothing (stronger than monotone)
- Example of d3.js animated Radial Chart
- D3 force graph behaviour in Chrome vs IE
- Fast and responsive interactive charts/graphs: SVG, Canvas, other?
- Rect's equivalent to text's text-anchor presentation attribute?
- Visualizing Array as value of a Crossfilter dimension
- d3 can I recalculate data in place?
- How to get all d3.js charts on one page
- How to plot one circle after another with some delay?
- Add a slider in d3.js element