- 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.
- FuelPHP Application Development Blueprints
- 工程軟件開發技術基礎
- C語言程序設計習題解析與上機指導(第4版)
- React Native Cookbook
- Three.js開發指南:基于WebGL和HTML5在網頁上渲染3D圖形和動畫(原書第3版)
- JavaScript Unlocked
- Python Game Programming By Example
- Mastering OpenCV 4
- Learning ArcGIS for Desktop
- JavaScript動態網頁編程
- Mastering Apache Storm
- 后臺開發:核心技術與應用實踐
- Java Web開發實例大全(基礎卷) (軟件工程師開發大系)
- QlikView Unlocked
- 大學計算機基礎實訓教程