- 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.
- Apache Oozie Essentials
- iOS 9 Game Development Essentials
- JavaScript:Functional Programming for JavaScript Developers
- SQL Server 2012數據庫技術及應用(微課版·第5版)
- 新編Premiere Pro CC從入門到精通
- Python時間序列預測
- 執劍而舞:用代碼創作藝術
- Visual Basic程序設計上機實驗教程
- 蘋果的產品設計之道:創建優秀產品、服務和用戶體驗的七個原則
- C++ Fundamentals
- BeagleBone Robotic Projects(Second Edition)
- 深入理解BootLoader
- 零基礎學HTML+CSS第2版
- Go語言入門經典
- C語言從入門到精通