-
Notifications
You must be signed in to change notification settings - Fork 0
/
style-function.html
45 lines (33 loc) · 1.05 KB
/
style-function.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
44
45
<!DOCTYPE html>
<html>
<head>
<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
<title>style</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/7.6.1/d3.min.js"></script>
<script>
function main() {
d3.selectAll('div').style('background-color', function(data, index) {
document.getElementById('out').innerHTML += 'index: ' + index + "<br>";
return '#' + Math.floor(Math.random() * 256).toString(16) +
Math.floor(Math.random() * 256).toString(16) +
Math.floor(Math.random() * 256).toString(16);
})
}
</script>
</head>
<body onload='main();'>
Use <code>selectAll(...).style(..., function())</code> to change the style of selected elements.
<div>div 1</div>
<div>div 2</div>
<div>div 3</div>
<div>div 4</div>
<div>div 5</div>
<div>div 6</div>
<div>div 7</div>
<div>div 8</div>
<div>div 9</div>
<p>Compare with <a href='selectAll-data-style.html'>selectAll-data-style.html</a>
<h1>Out</h1>
<p id='out'></p>
</body>
</html>