Skip to content

Instantly share code, notes, and snippets.

@davelandry
Last active August 22, 2016 15:24
Show Gist options
  • Save davelandry/5ed41ef03b58d681cc11 to your computer and use it in GitHub Desktop.
Save davelandry/5ed41ef03b58d681cc11 to your computer and use it in GitHub Desktop.
Custom Data Aggregations

By using the .aggs( ) method, the aggregation method of different variables can be modified. In this example, the aggregation method for the "value" key is changed to "mean" (the default is "sum").

In addition to supporting all of the standard D3 array comparators, this method also accepts custom functions.

Featured on D3plus.org

<!doctype html>
<meta charset="utf-8">
<script src="//d3plus.org/js/d3.js"></script>
<script src="//d3plus.org/js/d3plus.js"></script>
<div id="viz"></div>
<script>
var sample_data = [
{"value": 100, "name": "alpha", "group": "group 1"},
{"value": 70, "name": "beta", "group": "group 2"},
{"value": 40, "name": "gamma", "group": "group 2"},
{"value": 15, "name": "delta", "group": "group 2"},
{"value": 5, "name": "epsilon", "group": "group 1"},
{"value": 1, "name": "zeta", "group": "group 1"}
]
var visualization = d3plus.viz()
.container("#viz")
.data(sample_data)
.type("tree_map")
.id(["group","name"])
.size("value")
.aggs({"value": "mean"})
.draw()
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment