官术网_书友最值得收藏!

Data-Driven Documents (D3)

D3 is a project featured by the Stanford Visualization Group developed by Mike Bostock.

D3 provides us with web-based visualization, which is an excellent way to deploy information and help us to see things such as proportions, relationships, correlations, and patterns, and discover things previously unknown. Since web browsers provide us with a very flexible and interactive interface in practically any device such as PC, tablet, and smart phone, D3 is an amazing tool for visualization based on data using HTML, JavaScript, SVG, and CSS.

In Chapter 1, Getting Started, we saw the importance of data visualization and in this chapter, we will present examples in order to understand the use of D3.js. In the following screenshot, we can see the basic structure of an HTML document. D3 is going to be included in a basic script tag or into a JavaScript file (.js):

HTML

HyperText Markup Language (HTML) provides the basic skeleton for our visualization. An HTML document will define the structure of our web page, based on a series of tags, which are labels inside angle brackets (<br/>) commonly coming in pairs (<p>...</p>). D3 will take advantage of the structure of HTML by creating new elements in the document structure, such as adding new div tags (which defines a section in a document). We can see the basic structure of an HTML document in the previous screenshot.

Tip

For a complete reference about HTML, please refer to the link http://www.w3schools.com/html/.

DOM

Document Object Model (DOM) helps in representing and interacting with objects in HTML documents. Objects in the DOM tree can be addressed and manipulated by programming languages such as Python or JavaScript through the elements (tags) of the web page. D3 will change the structure of the HTML document by accessing the DOM tree either by the element ID or its type.

CSS

Cascading Style Sheets (CSS) can help us to style the web page. A CSS style is based on rules and selectors. We can apply styles to a specific element (tag) through selectors. An example of CSS is shown as follows:

<style>
body {
  font: 10px arial;
}
</style>

JavaScript

JavaScript is a dynamic scripting programming language typically implemented in the client (web browser). All the code in D3.js is developed with JavaScript. JavaScript will help us to create great visualizations, with full interactivity which can be updated in real time. In D3.js we can link to the library directly (stored in a separate file) with the snippet listed as follows:

<script src="http://d3js.org/d3.v3.min.js"></script>

SVG

Scalable Vector Graphics (SVG) is an XML-based vector image format for two-dimensional graphics. SVG can be directly included in your web page. SVG provides basic shape elements such as rectangle, line, circle, and text to build complicated lines and shapes inside a canvas. Much of the success of D3 is because it implements a wrapper for SVG. With D3 we will not have to modify the XML directly, instead D3 provides an API to help us place our elements (rectangle, circle, line, and so on) in the correct location on the canvas.

主站蜘蛛池模板: 龙江县| 玉龙| 萍乡市| 平度市| 大安市| 嵊州市| 康保县| 东乡| 遂平县| 漳州市| 长治市| 海丰县| 扎赉特旗| 清涧县| 阿克陶县| 潮安县| 大名县| 长沙市| 龙门县| 峨山| 安国市| 巴林左旗| 红河县| 石嘴山市| 资中县| 新闻| 武邑县| 张家口市| 宜黄县| 吉隆县| 新疆| 习水县| 金坛市| 东辽县| 林甸县| 根河市| 巩义市| 井陉县| 芒康县| 扬州市| 正定县|