score:16
Accepted answer
You need to use the group.reduce(add, remove, initial) method, like:
var col1DimTotal = col1Dim.group().reduce(reduceAdd, reduceRemove, reduceInitial);
function reduceAdd(p, v) {
++p.count;
p.total += v.value;
return p;
}
function reduceRemove(p, v) {
--p.count;
p.total -= v.value;
return p;
}
function reduceInitial() {
return {count: 0, total: 0};
}
Because you're using dc.js, you'll need to use chart.valueAccessor method to use the average in your charts, like:
chart.valueAccessor(function(p) { return p.value.count > 0 ? p.value.total / p.value.count : 0; });
Source: stackoverflow.com
Related Query
- dc.js - how to get the average of a column in data set
- How to get the minimum and maximum value between a given range in data set in d3.js
- In d3, how to get the interpolated line data from a SVG line?
- How to get the data from the c3.js
- How do I get D3 Data Driven Document to display a moment.js datetime in the correct time zone?
- How do you retrieve the key values of a nested data set in D3
- How to get SVG path data of TopoJSON feature without adding it to the DOM?
- How to get the index of the data element in a histogram on mouseover?
- How to retrieve the key values of a nested data set in D3
- How to specify a data column as the property used in a line generator?
- How to get Average from DOW of Date column using crossfilter to populate in bar chart
- In d3 4.0, how can I get extra data from the stratified object?
- D3.js: How to get the selection index, instead of the data index?
- How to parse to get the data in d3.js
- How to set my variable so D3 data update finds the right object property?
- D3 How to I get the size of the data after filtering
- d3 line chart x, y not in the same level of a data structure, how to set x, y function?
- How do I structure data in php to get the correct json result?
- How to get the data of a D3 node in Chrome Extension content script
- How to get the data from given array of objects in d3.js
- How can I find the frequency of each member in my data set
- How do I get the column following a particular column?
- How to get a D3.js pie chart to render data dynamically from the DOM
- C3.js Scatter plot - how to associate third data (additional value) as part of original column data for callbacks to set radius and display in tooltip
- D3.js: How to get the computed width and height for an arbitrary element?
- How to get data of parent node in d3.js
- How to set the background-color of a D3.js svg?
- How do I get the width of an svg element using d3js?
- D3.js: Get an array of the data attached to a selection?
- d3.js - How can I set the cursor to hand when mouseover these elements on SVG container?
More Query from same tag
- how to integrate d3 with require.js
- How to use python pandas to get intersection of sets from a csv file
- How to fix truncated y-axis and x-axis
- d3js - image not showing in arc
- Selecting IDs with numbers within a range
- D3.js onclick switching other line color
- How to convert my data into a format suitable for d3.js sunburst?
- How to parse a date string with microseconds
- CSS-Sprites + D3.js
- automatically set dimensions of d3/dimple data visualization for legibility
- Making circular label in d3js
- Open pop up upon clicking a datapoint in chart
- Cannot use @types/d3-tip: Argument of type 'Tooltip' is not assignable
- Rickshaw misinteprets the datetime
- if i pre-render d3js charts on the server, how will their width/height be calculated?
- D3 pan+ zoom constraints
- D3 live pie chart not updating?
- d3 axis sits in [0,1] domain
- d3.js v4 sankey diagram-- particles and drag not working
- How can I append text to and render that text from a line in a force directed graph in D3.js?
- Preventing overlap of text in D3 pie chart
- Plotting an empty interval for elasticsearch date histogram
- Javascript Function only working for 1st element
- Construct an array of dates between start and end dates. (d3.js)
- D3 JS chart is cut off after adding labels for X and Y axis
- D3 - Map with custom json
- Why the data can't be bind with JSON file?
- D3 Horizontal Bar Chart Animation Continously
- Optimizing charge, linkDistance and gravity in d3 force-directed layouts
- How can I add links to dendrogram texts?