score:3
Accepted answer
topojson.feature
takes two parameters, as seen in the topojson doc's:
topojson.feature(topology, object);
You have only specified the objects you wish to extract:
let counties = topojson.feature(data[0].objects.counties);
The error likely derives from the lack of a second parameter: type
is undefined for the second parameter since the second parameter is not defined.
Using both parameters, you can extract your features without error using both parameters below:
let counties = topojson.feature(data[0], data[0].objects.counties);
const promisses = [d3.json('https://raw.githubusercontent.com/no-stack-dub-sack/testable-projects-fcc/master/src/data/choropleth_map/counties.json'), d3.json('https://raw.githubusercontent.com/no-stack-dub-sack/testable-projects-fcc/master/src/data/choropleth_map/for_user_education.json')];
Promise.all(promisses).then((d)=>{return processData(d)});
function processData(data) {
for (let i = 0; i < data.length; i++) {
//console.log(JSON.stringify(data[i]));
}
let w = 800;
let h = 0.6 * w;
let padding = 40;
let svg = d3.select('#chart-bg').append('svg');
svg.attr('width', w + 2 * padding)
.attr('height', h + 2 * padding)
.attr('id','map')
//The next line is where I am having trouble
let counties = topojson.feature(data[0], data[0].objects.counties);
console.log(JSON.stringify(counties));
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/topojson/3.0.2/topojson.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/5.7.0/d3.min.js"></script>
Source: stackoverflow.com
Related Query
- Uncaught TypeError: Cannot read property 'linear' of undefined
- d3.svg.line() error: Uncaught TypeError: Cannot read property 'line' of undefined
- D3.js : Uncaught TypeError: Cannot read property 'document' of undefined
- Uncaught TypeError: Cannot read property 'arc' of undefined in AngularJS and D3
- NVD3 Line Chart Uncaught TypeError: Cannot read property 'x' of undefined
- Uncaught TypeError: Cannot read property 'textContent' of null error
- topojson.js:187: Uncaught TypeError: Cannot read property 'type' of undefined
- Uncaught TypeError: Cannot read property 'axis' of undefined
- Uncaught TypeError: Cannot read property 'albersUsa' of undefined
- d3.js - Uncaught TypeError: Cannot read property 'data' of undefined
- TypeScript type confusion (TypeError: Cannot read property 'slice' of undefined)
- topojson/d3.js: Uncaught (in promise) TypeError: Cannot read property 'type' of undefined
- Uncaught TypeError: Cannot read property 'type' of undefined with d3.js
- Displaying SVG elements with D3 and d3.slider: Uncaught TypeError: Cannot read property 'length' of undefined
- Uncaught TypeError: Cannot read property 'length' of undefined in d3.js
- Error when generating line Chart, Uncaught TypeError: Cannot read property 'each' of undefined
- D3 - Uncaught TypeError: Cannot read property 'length' of undefined
- Uncaught TypeError: Cannot read property 'startAngle'
- Creating links between nodes d3.js currently returning Uncaught TypeError: Cannot read property 'weight' of undefined
- Uncaught TypeError: Cannot read property 'length' of undefined in d3
- Uncaught TypeError: Cannot read property 'length' of undefined in line chart with json data
- D3 error - Uncaught TypeError: Cannot read property 'children' of undefined
- Getting Uncaught TypeError: Cannot read property 'length' of undefined on leafletjs
- Uncaught TypeError: Cannot read property 'y' of undefined in NV D3 StackedLine
- D3 Line Chart - Uncaught TypeError: Cannot read property 'length' of undefined
- JS;D3 Barchart UNDEFINED Error : Uncaught TypeError, Cannot read property
- Uncaught TypeError: Cannot read property 'arc' of undefined
- variable with .select method returns null - Uncaught TypeError: Cannot read property 'append' of null
- d3 json loading error Uncaught TypeError: Cannot read property 'length' of undefined
- D3 JS - Uncaught TypeError: Cannot read property 'length' of undefined - seems related to data issue
More Query from same tag
- Javascript: import error and can't non find variable
- D3.js - Working with major and minor gridlines
- D3: uncaught exception: Object
- d3.js chart from json object
- Selecting multiple dom elements by index with d3.selectAll()
- Compilation errors when drawing a piechart using D3.js, TypeScript and Angular
- D3 tree: lines instead of diagonal projection
- d3.js interactive grouped bar chart alternating rotation
- D3 chart example "TypeError: data is undefined"
- Reverse Axis in rCharts Without Sacrificing Animation?
- Links and textPaths in D3 cluster layout
- d3js: Svg element not getting resized on changing window size
- d3 react js - Failed to execute 'createElementNS' on 'Document': The qualified name provided contains the invalid character ','
- Titles not showing on links or nodes using JS D3.js Version 3
- Formatting bar graph for integers developed using d3.js
- Selecting a subset of circles using D3
- chrome extension using d3
- Unable to remove d3 transition despite calling interrupt on selection
- How to distinguish "0" values from filtered out values in a dc.js geoChoroplethChart?
- Chipping the ends of rectangle to make them spear-like
- how to modify xlink:href with jquery not working
- DS.js JSON file format from CSV
- Rebinding exports in d3.js v4
- Append links to side of rectangles in D3 tree layout
- Transitioning circles, one by one
- D3 spaces between groups
- Unbale to read the current dataset elements using d function in an onclick event
- How to load and print json array/object in javascript
- Adding c3.js padding without cutting off graph
- How to append elements to a nested layer