-
Notifications
You must be signed in to change notification settings - Fork 0
/
d3_hello_world.js
46 lines (37 loc) · 1.21 KB
/
d3_hello_world.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
looker.plugins.visualizations.add({
// Set up the initial state of the visualization
create: function(element, config) {
// Insert a <style> tag with some styles we'll use later.
element.innerHTML = `
<style>
div.bar {
display: inline-block;
width: 20px;
height: 75px; /* Gets overridden by D3-assigned height below */
margin-right: 2px;
background-color: teal;
}
</style>
`;
// Create a container element to let us center the text.
var container = element.appendChild(document.createElement("div"));
},
// Render in response to the data or settings changing
updateAsync: function(data, element, config, queryResponse, details, done) {
// Clear any errors from previous updates
this.clearErrors();
var dataset = [ 5, 10, 13, 19, 21, 25, 22, 18, 15, 13,
11, 12, 15, 20, 18, 17, 16, 18, 23, 25 ];
d3.select("body").selectAll("div")
.data(dataset)
.enter()
.append("div")
.attr("class", "bar")
.style("height", function(d) {
var barHeight = d * 5;
return barHeight + "px";
});
// We are done rendering! Let Looker know.
done()
}
});