Built with blockbuilder.org for mailing list discussion d3-js › Add class in .text().
Last active
November 22, 2016 15:31
-
-
Save curran/62329a53e3becf3cbe329d9070ecf590 to your computer and use it in GitHub Desktop.
Spans Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
license: mit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<head> | |
<meta charset="utf-8"> | |
<script src="https://d3js.org/d3.v4.min.js"></script> | |
<style> | |
.entry { | |
font-size: 4em; | |
line-height: 120px; | |
margin-top: 30px; | |
margin-left: 20px; | |
} | |
.entry-name { | |
font-weight: bold; | |
} | |
.entry-value { | |
font-style: italic; | |
} | |
</style> | |
</head> | |
<body> | |
<script> | |
var data = [ | |
{ name: "Isaac Newton", value: "Scientist"}, | |
{ name: "Leonardo DiCaprio", value: "Actor"}, | |
{ name: "Leonardo DaVinci", value: "Awesomeness"}, | |
]; | |
var entry = d3.select("body") | |
.selectAll("div") | |
.data(data) | |
.enter().append("div") | |
.attr("class", "entry"); | |
entry.append("span") | |
.attr("class", "entry-name") | |
.text(function (d){ return d.name; }); | |
entry.append("span") | |
.text(" : "); | |
entry.append("span") | |
.attr("class", "entry-value") | |
.text(function (d){ return d.value; }); | |
</script> | |
</body> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment