score:1
Accepted answer
Another approach might employ some more of D3's functionality:
function getExtent(list) {
return d3.extent( // 4. Get the extent from that array
d3.merge( // 3. Merge all arrays into a single one
data.map(function(d) { // 2. Map each object's values to an array
return list.map(function(y) { // 1. Get the array of values to map
return d[y];
});
})
)
);
}
console.log(getExtent(["Branch1"])); // [1200, 1588]
console.log(getExtent(["Branch2"])); // [2000, 3495]
console.log(getExtent(["Branch1", "Branch2"])); // [1200, 3495]
y.domain(getExtent(yAxisList)); // This extent can be used directly
I am not making any claims on performance, but at least to the eye this seems to be more pleasing and elegant.
Source: stackoverflow.com
Related Query
- D3.js how to extract Y domain value from data array with multiple Y axis columns
- Get max value from array with multiple columns
- how to get data with tsv or csv to array in d3.js from a txt file?
- Enter() statement with a function from one data array to multiple arrays? (Adding multiple Gradient Paths)
- How do I update multiple columns of data with D3?
- How to create multiple pie charts with D3 from a single array with multiple objects?
- How to set multiple attributes with one value function?
- How to get maximum value from an array of objects to use in d3.scale.linear().domain()
- How to load data from an internal JSON array rather than from an external resource / file for a collapsible tree in d3.js?
- How to pull data from mysql database and visualize with D3.JS?
- d3.js - max and min value from json data which has array of values
- How can D3 select multiple shapes with shared attributes from a group?
- In D3, how can I create multiple elements for each data element based on value in data?
- Javascript: Array of dictionaries, get all key value pairs from one dictionairy with condition
- How do I use d3.domain to get d3.min and d3.max from multiple columns in a JSON file?
- dc.js - how to create a row chart from multiple columns
- How to get the specific JSON array from a value in that array
- How to summarize an array with group and rollup from d3-array?
- How do I access a datum's parent array from within a value function?
- How to create left axis with variable tick interval in tick values and has same distance between tick value
- how to add array of text to multiple divs with d3
- D3 How to update the chart after selection from drop down menu with new data
- How to plot data points on multi-line chart with multiple y axes
- How to change JSON data to Javascript array of objects with D3
- Generating multiple DOM elements from a single data point with D3.js
- How to make a mouseover interactive line graph with multiple data series and 2 y axes?
- How to make multiple charts with d3.chart using nested data
- How do you call data from nested JSON array using d3?
- how to display data from 1st point on words on y axis for line chart in d3.js
- How to return only unique value from array objects bound to an element in d3.js
More Query from same tag
- D3 lines getting rendered as polygons
- Changing from d3v4 to d3v3 makes the bars disappear
- Convert string timestamp to hour axis
- d3 Stacked Bar chart - assign olors
- How to solve duplicate label in zoom
- How to transition along a path partially or by percentage only
- d3 Preserve scale/translate after resetting range
- heatmap in d3js has weird x axis
- D3 tree: lines instead of diagonal projection
- How to smoothen a path using D3
- What's the increment operator doing here and how it changes the scale?
- javascript indexed array variance math with matching dates
- How to see what nodes are selected with d.selected ? D3/JS
- why does appending a foreignObject into an SVG break jquery ui's resize?
- D3 Map Projection Not Showing Map
- What is the difference between svg's x and dx attribute?
- C3 / D3 bar chart with horizontal scroll
- D3.js adding a new object with nest and key
- Creating tooltips for SVG objects after they were translated and scaled
- how to focus the clicked bar in C3.js bar graph?
- d3js how to select the element i'm currently working on
- Converting D3.js CSS Styles to Inline Styles
- Appending elements to d3 selection
- d3.js set attributes in v4
- Colour transition in d3 always starting with black
- Structuring Plain Text to JSON
- D3: How to select every thing under svg element
- D3 Force-directed graph using texts instead of nodes
- D3.js show heatmap for each pixel (coordinate) in choropleth
- How to find links in d3 v4?