Last active
February 3, 2019 16:53
-
-
Save AvocadoVenom/8fc4de04d1723ba670fbcdc67b102047 to your computer and use it in GitHub Desktop.
Adding labels to d3 bar chart
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
private labels: any; // Labels | |
private draw() { | |
// ... | |
this.drawLabels(); | |
} | |
private repaint() { | |
// ... | |
this.drawLabels(); | |
} | |
private drawLabels() { | |
this.labels = this.mainContainer.selectAll('.label') | |
.remove().exit() | |
.data(this.dataSource) | |
.enter().append('text').attr('class', 'label') | |
.attr('x', d => this.xScale(d.name) + (this.xScale.bandwidth() / 2)) | |
.attr('y', d => this.yScale(d.value) - 5)) | |
.text(d => Math.floor(d.value)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment