Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <script>
- requirejs.config({
- paths: {
- d3: "scripts/d3.v3",
- nvd3: "scripts/nv.d3",
- elasticsearch: "scripts/elasticsearch"
- },
- shim: {
- nvd3: {
- exports: 'nv',
- deps: ['d3.global']
- }
- }
- });
- // workaround for nvd3 using global d3
- define("d3.global", ["d3"], function(_) {
- d3 = _;
- });
- require(["scripts/main"], function () {});
- </script>
- //main.js:
- define(['d3', 'nvd3', 'elasticsearch'], function (d3, nv, elasticsearch) {
- var client = new elasticsearch.Client();
- client.search({
- ...
- }).then(function (resp) {
- var data = resp.aggregations.someaggregationthatyoumade.buckets;
- nv.addGraph(function() {
- var chart = nv.models.pieChart()
- .x(function(d) { return d.key; })
- .y(function(d) { return d.valueintheaggregation; })
- .showLabels(true);
- d3.select("#thechart svg")
- .datum(data)
- .call(chart);
- return chart;
- });
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement