score:1
Accepted answer
That result is expected: you have undefined
values in the scale's domain.
The issue is that Array.prototype.map
cannot skip elements. For instance:
const arr = [70, 20, 50, 80, 10, 90, 40];
console.log(arr.map(d => {
if (d > 40) return d;
}))
As you can see this does not filter the array removing elements whose value is less than 40: the array's length keeps the same, but now it has several undefined
.
Therefore, the solution is filtering the data
, just like you did in the data()
method:
data = data.filter(function(d){if(d.sales>40) {return d;}})
And use that filtered array for the scale's domain.
By the way, you can simplify the filter to just this:
data = data.filter(function(d){return d.sales>40})
Source: stackoverflow.com
Related Query
- Load and display data with condition, but the condition is not met
- d3.create() returns an element with .node(), but does not display in the browser
- Why animated d3 svg line is not synchronized with the axis shift in IE9 but synchronized in IE11 and Chrome?
- Embedded Google Map with d3.js overlay shows UI options and overlay element but NOT the map itself
- I want to remove the commas from the X axis with d3, but tickFormat does not work and instead, throws an error
- Data points and ticks in the scaleBand axis are not aligned
- With D3, how can I set attribute ("fill", "none") of axis path and line, but not text (without editing stylesheet)
- D3.js: Zooming the x-axis and data with mouse wheel scroll
- d3 multiline update path and transition path does not work with nested data
- Visualization data inserted in the webpage is not properly indented and not appearing at desired position
- d3 line and area charts not updating with new data array
- the data is changed, but reloading does not fetch new data, D3
- Updating data values with HTML input and changing the data array
- Data filter works with json data but not with csv data
- Updating nodes and links with labels in d3 force directed network graph is not removing the nodes properly
- d3.js : re-inserting elements during dragstart/mousedown interferes with click events in Chrome and Safari but not Firefox
- How can i bind an json data with a key and Name for display
- Using d3 in meteor on windows 8.1, how can I display a world map, zoomed in on the US, with country borders and US state borders?
- How to use D3 to load csv, display table and style it with bootstrap in javascript
- How can I apply a clipPath in SVG with multiple paths and NOT clip out the area between the paths?
- Trying to make reusable javascript function, but the data is not returning
- Time in x-axis and data for the y-axis for line chart in d3.js doesn't match/show with what (data) is on JSON
- dc.js - Chart not rendering (single row bar chart - horizontal row), with the exception of legend, axes and tick marks/values (which do render)
- How do I configure Ghost in in dev and production to make a json data available via url to load with d3.json?
- How to show the unhighlighted/ not selected data points on scatter plots when using brush/group in dc.js? And is multiple brushes possible in dc.js
- d3 bar chart labels not getting updated on updating the chart with the new data
- dc.js with crossfilter and d3, how to load multiple csv files at once, without knowing how many files the user will upload
- d3: drawing elements correctly but not adding new data to the dom
- D3.JS how to load 3 csv files and change data on line chart with button click event?
- I've been trying to use dc.js and crossfilter to build the datatable functionality to listout some data.But the data is not displaying as expected
More Query from same tag
- d3.json cant read from json file more than one object
- D3JS: appending simple nested HTML in a single command
- How to get container dimensions before compile?
- Get attribute x for axis' text element
- D3 find the angle of line
- How to change Horizontal bar chart to vertical bar chart in D3 v4
- D3 Tree layout: How to fill rectangles with text, but have them in uniform size?
- Need d3 brush to NOT work on touch devices
- D3js How to format the content of some columns in a table
- Converting static code into reusable D3.js pie animation
- Two way binding of wordcloud data
- add circle in a spiral chart with d3js with line connecting to center
- D3 brushes: accessing absolute values from axis
- Hierarchical Arc's in D3.js Sunbursts that include values at every level not just an aggegregate of the leaves
- d3.js setting all fill colors to stroke colors for a given selection
- D3.js: Pie graph, adding a border only to the outter region
- Changing color range in a d3 reusable donut chart depending on the number of data points
- Dis Alignment of bar chart in D3.js
- d3js chart transition not functioning properly
- Sankey Diagram (D3) - How to use multiple units for link values and how to add notes to mouseover popup box?
- How do I override d3.js chart function behavior?
- Use both "d3.event.preventDefault" and "d3.event.which"
- Accessing the correct array of objects column
- d3.js. How to animate throughout all data set from start to end?
- How do I merge two images into one?
- Extending the axis bar height in d3 js charts
- Highcharts Shadow/Fill Graph
- Network around rectangle with text inside in d3
- D3 cluster: can lines make no crossing?
- Why does D3 not render TopoJSON correctly?