-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathd3_example1.html
43 lines (39 loc) · 1.39 KB
/
d3_example1.html
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
<!DOCTYPE html>
<meta charset="utf-8">
<!-- set some properties of the d3 object for later -->
<style>
.chart div {
font: 10px sans-serif;
background-color: steelblue;
text-align: right;
padding: 3px;
margin: 1px;
color: white;
}
</style>
<div class="chart"></div>
<!-- Get the most up to date version of d3 from online -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js"></script>
<script>
<!-- Define some data in a variable -->
var data = [4, 8, 15, 16, 23, 42];
<!-- Define the scale of the plot (map from the range in data to the physical size of the plot) -->
var x = d3.scale.linear()
<!-- The range of values that can be displayed on the plot -->
.domain([0, d3.max(data)])
<!-- The physical size of the plot in pixels -->
.range([0, 420]);
<!-- Select chart container - using class selector -->
d3.select(".chart")
<!-- Initiate data - by defining selection to which date will be joined -->
<!-- This is in the all to select, so imagine it is chart.selectAll("div") -->
.selectAll("div")
<!-- Join the data, again imagine chart.date(data) -->
.data(data)
<!-- Update the data by using the chart.enter().append("div") command -->
.enter().append("div")
<!-- Set the widths of each new bar, using the data, d -->
.style("width", function(d) { return x(d) + "px"; })
<!-- Label each bar with the value -->
.text(function(d) { return d; });
</script>