- Expert Data Visualization
- Jos Dirksen
- 192字
- 2021-07-09 18:22:43
Adding group elements
At this point, we've got the data into a form that we can use. The next step is to create a number of containers, to which we can add the rect that represents the number of times the name was used, and we'll also add a text element there that displays the name:
var bars = chart.selectAll("g").data(both)
.enter()
.append('g')
.attr('transform', function (d, i) {
var yPos = ((barWidth + barMargin) * i);
return 'translate( 0 ' + yPos + ')';
});
Here, we bind the both array to a number of g elements. We only need to use the enter function here, since we know that there aren't any g elements that can be reused. We position each g element using the translate operation of the transform attribute. We translate the g element along its y-axis based on the barWidth, the barMargin, and the position of the data element (d) in our data (both) array. If you use the Chrome developer tools, you'll see something like this, which nicely shows the calculated translate values:

All that is left to do now, is draw the rectangles and add the names.
- Extending Jenkins
- 數據庫程序員面試筆試真題與解析
- Progressive Web Apps with React
- 軟件項目管理(第2版)
- Mastering Rust
- Learning Zurb Foundation
- 用戶體驗增長:數字化·智能化·綠色化
- Advanced Oracle PL/SQL Developer's Guide(Second Edition)
- Mastering Data Mining with Python:Find patterns hidden in your data
- Learning Apache Cassandra
- Procedural Content Generation for C++ Game Development
- JavaScript腳本特效編程給力起飛
- 深度探索Go語言:對象模型與runtime的原理特性及應用
- MongoDB Cookbook(Second Edition)
- Python預測分析與機器學習