score:2
Accepted answer
If you want it in one line:
var max = d3.max(data.filter(d => d.enabled === "true"), e => d3.max(e.values, f => f.value));
Or, without the arrow functions:
var max = d3.max(data.filter(function(d) {
return d.enabled === "true";
}), function(e) {
return d3.max(e.values, function(f) {
return f.value;
});
});
Here is a demo:
var data = [{
"key": "name1",
"enabled": "true",
"values": [{
"date": "2016-09-13T02:11:44Z",
"value": "100",
}, {
"date": "2016-09-13T02:11:44Z",
"value": "200",
}]
}, {
"key": "name2",
"enabled": "false",
"values": [{
"date": "2016-09-13T02:11:44Z",
"value": "400",
}, {
"date": "2016-09-13T02:11:44Z",
"value": "500",
}]
}];
var max = d3.max(data.filter(d => d.enabled === "true"), e => d3.max(e.values, f => f.value));
console.log(max);
<script src="https://d3js.org/d3.v4.min.js"></script>
It accepts more than one object with enabled: "true"
, check this second demo, I put another object in your data array:
var data = [{
"key": "name1",
"enabled": "true",
"values": [{
"date": "2016-09-13T02:11:44Z",
"value": "100",
}, {
"date": "2016-09-13T02:11:44Z",
"value": "200",
}]
}, {
"key": "name2",
"enabled": "false",
"values": [{
"date": "2016-09-13T02:11:44Z",
"value": "400",
}, {
"date": "2016-09-13T02:11:44Z",
"value": "500",
}]
},{
"key": "name1",
"enabled": "true",
"values": [{
"date": "2016-09-13T02:11:44Z",
"value": "800",
}, {
"date": "2016-09-13T02:11:44Z",
"value": "200",
}]
}];
var max = d3.max(data.filter(d => d.enabled === "true"), e => d3.max(e.values, f => f.value));
console.log(max);
<script src="https://d3js.org/d3.v4.min.js"></script>
Source: stackoverflow.com
Related Query
- D3 js get a d3.max from an object that contains a specific key value
- How to get the specific JSON array from a value in that array
- D3js - Getting max value from d3.line() for a specific domain
- Javascript: Array of dictionaries, get all key value pairs from one dictionairy with condition
- D3.js-How can I get the maximum value of a specified key in an object
- Get max value from JSON objects D3JS
- How to get a value from a stylesheet into the code so that it can be used programmatically?
- Get max value from array with multiple columns
- D3 how to properly get the key value INSIDE of a json object
- Can I get a value returned from a $.Deferred() that can be used in the display?
- How do I assign ticks to be equal to a different key value from the same object from the one on which the axis is based on in D3.js?
- How to get a value from a nested object in a GeoJson object in d3js?
- Get value from json value key pair with D3
- How can I get a specific object from an array in javascript?
- Get the object with the max value with D3
- How to get maximum value from an array of objects to use in d3.scale.linear().domain()
- D3: Get nearest value from ordinal axis on mouseover
- d3.js - max and min value from json data which has array of values
- How to get value from the element using selection in d3
- Blazor, get Input value from Javascript created DOM Element
- Get unique max value for each y-axis in a bar chart
- D3 : best way to find max value in a JSON object
- Selecting a specific value from an array of objects in javascript
- How to get the X value of a ticks from the x axis?
- d3 line graphic, get data from Object instead of CSV
- Object key value destructuring in array arguments
- How do I get an object from d3.data()?
- D3 : get value from the array
- d3.tree get min & max value
- Merge objects that share a common key or value
More Query from same tag
- Group shapes/counties together by a list of attributes with D3.js
- d3 highlighting nodes on mouseover causes unexpected behaviour when mouse taken off of svg space
- D3 pie chart zero data point changes arc fill color
- D3- Drawing line on leaflet map through mouse events
- Not able to render/plot Composite chart dc.js
- Simulating Mouse event in Microsoft Edge for d3
- Call Django View from D3.js onclick event on Heatmap
- d3.v3 transitions happening instantly?
- D3.js - Zooming to bbox with a dropdown menu
- Changing one element of an array of arrays with event
- Sum by category in Piechart (Dc.js & Crossfilter)
- Bilevel Partition D3 create a simple 2 layer
- When integrate elasticsearch with d3.js, "Uncaught TypeError: Cannot read property 'Client' of undefined" I get this error
- d3.js selectAll method does not select all elements?
- Making a d3 chart reactive (v5)
- Showing online offline of a device with date and status js jquery d3
- How to simplify this D3 code?
- d3.js - transition interruption event?
- Create a semi circle pie char with variable attribute heights
- How do you draw d3-contour multipolygon output to canvas?
- I couldn't visualize data in d3
- D3 Donut chart: Display Value on segment hover
- Difference between access to mapped objects in array through for cycle/for in cycle
- Javascript - How to pass original object to callback function
- D3: Bar chart coloring
- Adding a Background to certain part of a graphic with nvd3
- charts not renderring in django-nvd3
- Update map rotation with angles with orthographic projection
- .style("background-position", function(){...}) not populating the attribute
- how can I set a height and width for this map in d3.js