score:2
Accepted answer
if your list is extremely long and you don't want to loop it more than once, you can do this all in one call:
<!doctype html>
<html>
<head>
<script data-require="d3@4.0.0" data-semver="4.0.0" src="https://d3js.org/d3.v4.min.js"></script>
</head>
<body>
<script>
var input = [{
x: new date("2014-01-01"),
y: 1223
}, {
x: new date("2015-06-01"),
y: 12
}, {
x: new date("2015-07-01"),
y: 1025
}, {
x: new date("2015-08-01"),
y: 125
}, {
x: new date("2017-01-01"),
y: 143
}],
mindate = new date("2015-01-01"),
maxdate = new date("2016-01-01");
var minmax = d3.extent(input, function(d) {
if (d.x <= mindate || d.x >= maxdate){
return nan;
}
return d.y;
})
console.log(minmax);
</script>
</body>
</html>
score:2
you have the possibility to filter the elements from within your array to fit the range of dates you need:
inputarray.filter(d => d.x > "2015-01-01" && d.x < "2016-01-01")
then you can map (transform) the filtered elements to transform them into their associated y value:
.map(d => d.y)
to finally get the min or max of the resulting array:
d3.min(..)
which gives:
var input = [
{
x: "2014-01-01",
y: 1223
},
{
x: "2015-06-01",
y: 12
},
{
x: "2015-07-01",
y: 1025
},
{
x: "2015-08-01",
y: 125
},
{
x: "2017-01-01",
y: 143
}
]
var output = input
.filter(d => d.x > "2015-01-01" && d.x < "2016-01-01")
.map(d => d.y);
console.log("filter/map array: " + output);
console.log("min: " + d3.min(output));
console.log("max: " + d3.max(output));
<script src="https://d3js.org/d3.v5.min.js"></script>
Source: stackoverflow.com
Related Query
- How to get the minimum and maximum value between a given range in data set in d3.js
- How to get the minimum and maximum value from a Json
- Set axis range based on data set minimum and maximum in d3.js
- Get the value of Y axis minimum and maximum limits in Billboard.js
- dc.js - how to get the average of a column in data set
- How to highlight the similarity of the value between rows and columns?
- How to select the color of node on data value and the Data value of tool as name?
- How to plot points on a map projection in D3.js and filter the data using range sliders?
- change the domain when a value exceeds the maximum and minimum value
- d3 Plus bar chart how to force fixed max y axis range independent of the max data value
- How to get a dashed line on Y axis and how to display the value beside the graph in d3
- How to get the data from given array of objects in d3.js
- How do I reformat the data in d3 having values to the key and another values to the value of the key?
- I have created tree using D3 tree js. Point is I need the value of top and left of each tree node. How can I get the top and left value of tree node?
- In d3 how can I get the value between two points?
- D3.js: How to get the computed width and height for an arbitrary element?
- How can I get the D3.js axis ticks and positions as an array?
- How to get maximum value from an array of objects to use in d3.scale.linear().domain()
- In d3, how to get the interpolated line data from a SVG line?
- d3.js how to get minimum value of scale's domain when using nice()
- how to set the domain and scale on an axis on a nvd3.js multiBarChart
- D3: How do I set "click" event and "dbclick" event at the same time?
- How to set the domain and scale on an yaxis on a discreteBarChart nvd3.js
- How can i get the startAngle and endAngle of each arc in the sunburst example using d3.js?
- How can I get the natural width and height of an svg image element?
- How to get the data from the c3.js
- How get the returned value of d3.ease?
- How to get a set of subpoints between two points?
- How do I get D3 Data Driven Document to display a moment.js datetime in the correct time zone?
- Draw a map with D3.js: How to get the right scale() and translate()?
More Query from same tag
- D3 returns no JSON objects
- D3.js X axis line not displaying
- Ignore duplicate date values
- When i click on the marker, the pop up doesn't appear. I get the following error
- How to set a tooltip width dynamically?
- Display image in d3.js from Android tablet image path
- I can not move my nodes, the force diagram does not apply in 3.js
- Resize my d3 chart so that it is 100% when the page loads and when you resize the window
- D3.js or Sigmajs is more good for network visualisation?
- d3 transform translate only the second parameter
- RangePoints for circles of different sizes
- Using D3 to Animate a virtual wheel, How to make it spin realistically?
- D3 blur out / lower the opacity of non-related links when dragging a particular node
- The legend is not displayed correctly (text cut off) You can test it with jsbin
- Javascript d3 pie chart doesn't pull data from JSON file with list of dictionaries
- d3 data reshape: properties to array
- D3 Treechart : Text on link(path) in version 4
- D3 JS Graphs not getting toggled on click of radio buttons
- R shiny: Change "height" attribute of rectangle in gvisTimeline
- How to update text in heatmap using D3?
- addEventListener doesn't work for element added by append method from d3js
- undefined d3.scale in Typescript
- SVG implementation of Monotone cubic interpolation without a Library like d3
- dc.js heatmap deselected colors
- Can we use custom JSON Data on Cubism?
- d3 - zoom to bounding box of SVG map element by clicking on a table row
- d3.svg.line() issues
- Replicating Mike Bostock's collapsible tree
- Adding a correctly sized rectangle behind text
- Partial border/stroke using SVG