- 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.
- ASP.NET Web API:Build RESTful web applications and services on the .NET framework
- Java范例大全
- JavaScript全程指南
- Python數據可視化:基于Bokeh的可視化繪圖
- Interactive Data Visualization with Python
- 神經網絡編程實戰:Java語言實現(原書第2版)
- Blockly創意趣味編程
- Python高效開發實戰:Django、Tornado、Flask、Twisted(第2版)
- Learning Salesforce Einstein
- Learning Vaadin 7(Second Edition)
- BIM概論及Revit精講
- Service Mesh實戰:基于Linkerd和Kubernetes的微服務實踐
- Solr Cookbook(Third Edition)
- Mastering Android Studio 3
- Google Adsense優化實戰