Soumettre la recherche
Mettre en ligne
[朝陽科大] D3.js 資料視覺化入門
•
43 j'aime
•
6,999 vues
Kuro Hsu
Suivre
D3.js 資料視覺化入門 @ 朝陽科大 2015.12.23
Lire moins
Lire la suite
Formation
Signaler
Partager
Signaler
Partager
1 sur 127
Télécharger maintenant
Télécharger pour lire hors ligne
Recommandé
twMVC#20 | 前端視覺化實戰 - D3.js
twMVC#20 | 前端視覺化實戰 - D3.js
twMVC
Prototype UI
Prototype UI
Sébastien Gruhier
第一次用 Vue.js 就愛上 [改]
第一次用 Vue.js 就愛上 [改]
Kuro Hsu
[JSDC 2015] Turf.js - 地理資訊的分析與地圖視覺化
[JSDC 2015] Turf.js - 地理資訊的分析與地圖視覺化
Kuro Hsu
Vue js 大型專案架構
Vue js 大型專案架構
Hina Chen
開放資料暨資料視覺化 (D3.js)
開放資料暨資料視覺化 (D3.js)
維佋 唐
D3.js 讓你的資料活起來
D3.js 讓你的資料活起來
oxxo studio
VueJs 簡介
VueJs 簡介
Jocelyn Hsu
Recommandé
twMVC#20 | 前端視覺化實戰 - D3.js
twMVC#20 | 前端視覺化實戰 - D3.js
twMVC
Prototype UI
Prototype UI
Sébastien Gruhier
第一次用 Vue.js 就愛上 [改]
第一次用 Vue.js 就愛上 [改]
Kuro Hsu
[JSDC 2015] Turf.js - 地理資訊的分析與地圖視覺化
[JSDC 2015] Turf.js - 地理資訊的分析與地圖視覺化
Kuro Hsu
Vue js 大型專案架構
Vue js 大型專案架構
Hina Chen
開放資料暨資料視覺化 (D3.js)
開放資料暨資料視覺化 (D3.js)
維佋 唐
D3.js 讓你的資料活起來
D3.js 讓你的資料活起來
oxxo studio
VueJs 簡介
VueJs 簡介
Jocelyn Hsu
Vue 淺談前端建置工具
Vue 淺談前端建置工具
andyyou
Rails Girls Weekly - 初探前端網頁技術 JavaScript 1/3
Rails Girls Weekly - 初探前端網頁技術 JavaScript 1/3
Kuro Hsu
Vue 2.0 + Vuex Router & Vuex at Vue.js
Vue 2.0 + Vuex Router & Vuex at Vue.js
Takuya Tejima
Rails Girls Weekly - 初探前端網頁技術 JavaScript 3/3
Rails Girls Weekly - 初探前端網頁技術 JavaScript 3/3
Kuro Hsu
資料視覺化的力量
資料視覺化的力量
Johnson Hsieh
Demo for ms azure machine learning
Demo for ms azure machine learning
Will Kuan 官大鈞
Tutorial for ms azure machine learning
Tutorial for ms azure machine learning
Will Kuan 官大鈞
郵遞公文追蹤系統操作說明
郵遞公文追蹤系統操作說明
小四 曾
Processing 基礎教學
Processing 基礎教學
CAVEDU Education
ES6 PPT FOR 2016
ES6 PPT FOR 2016
Manoj Kumar
大數據時代的行動支付風險控制
大數據時代的行動支付風險控制
Chris Cheng-Hsun Lin
資料視覺化 / 数据可视化 Data Visualization
資料視覺化 / 数据可视化 Data Visualization
Will Kuan 官大鈞
機器學習工具介紹 / 机器学习工具介绍 Demos for Machine Learning Tools
機器學習工具介紹 / 机器学习工具介绍 Demos for Machine Learning Tools
Will Kuan 官大鈞
Bootstrap4 與他的好搭檔
Bootstrap4 與他的好搭檔
Chih-cheng Wang
20151210 台灣創用cc計畫×開放文化基金會-台灣創用cc計畫教學教材參考投影片-創用cc知多少-odp
20151210 台灣創用cc計畫×開放文化基金會-台灣創用cc計畫教學教材參考投影片-創用cc知多少-odp
CCTaiwanCommunity
محاضرات الاحصاء التطبيقي لطلاب علوم الرياضة.pdf
محاضرات الاحصاء التطبيقي لطلاب علوم الرياضة.pdf
Khaled Elbattawy
RESOLUCION DEL SIMULACRO UNMSM 2023 ii 2.pptx
RESOLUCION DEL SIMULACRO UNMSM 2023 ii 2.pptx
scbastidasv
Castellà parelles 2n - Abril i Irina.pdf
Castellà parelles 2n - Abril i Irina.pdf
Ernest Lluch
Català parelles 3r - Emma i Ariadna (1).pdf
Català parelles 3r - Emma i Ariadna (1).pdf
Ernest Lluch
ClimART Action | eTwinning Project
ClimART Action | eTwinning Project
Nuckles
Català Individual 3r - Víctor.pdf JOCS FLORALS
Català Individual 3r - Víctor.pdf JOCS FLORALS
Ernest Lluch
Saunanaine_Helen Moppel_JUHENDATUD SAUNATEENUSE JA LOODUSMATKA SÜNERGIA_strat...
Saunanaine_Helen Moppel_JUHENDATUD SAUNATEENUSE JA LOODUSMATKA SÜNERGIA_strat...
Eesti Loodusturism
Contenu connexe
En vedette
Vue 淺談前端建置工具
Vue 淺談前端建置工具
andyyou
Rails Girls Weekly - 初探前端網頁技術 JavaScript 1/3
Rails Girls Weekly - 初探前端網頁技術 JavaScript 1/3
Kuro Hsu
Vue 2.0 + Vuex Router & Vuex at Vue.js
Vue 2.0 + Vuex Router & Vuex at Vue.js
Takuya Tejima
Rails Girls Weekly - 初探前端網頁技術 JavaScript 3/3
Rails Girls Weekly - 初探前端網頁技術 JavaScript 3/3
Kuro Hsu
資料視覺化的力量
資料視覺化的力量
Johnson Hsieh
Demo for ms azure machine learning
Demo for ms azure machine learning
Will Kuan 官大鈞
Tutorial for ms azure machine learning
Tutorial for ms azure machine learning
Will Kuan 官大鈞
郵遞公文追蹤系統操作說明
郵遞公文追蹤系統操作說明
小四 曾
Processing 基礎教學
Processing 基礎教學
CAVEDU Education
ES6 PPT FOR 2016
ES6 PPT FOR 2016
Manoj Kumar
大數據時代的行動支付風險控制
大數據時代的行動支付風險控制
Chris Cheng-Hsun Lin
資料視覺化 / 数据可视化 Data Visualization
資料視覺化 / 数据可视化 Data Visualization
Will Kuan 官大鈞
機器學習工具介紹 / 机器学习工具介绍 Demos for Machine Learning Tools
機器學習工具介紹 / 机器学习工具介绍 Demos for Machine Learning Tools
Will Kuan 官大鈞
Bootstrap4 與他的好搭檔
Bootstrap4 與他的好搭檔
Chih-cheng Wang
20151210 台灣創用cc計畫×開放文化基金會-台灣創用cc計畫教學教材參考投影片-創用cc知多少-odp
20151210 台灣創用cc計畫×開放文化基金會-台灣創用cc計畫教學教材參考投影片-創用cc知多少-odp
CCTaiwanCommunity
En vedette
(15)
Vue 淺談前端建置工具
Vue 淺談前端建置工具
Rails Girls Weekly - 初探前端網頁技術 JavaScript 1/3
Rails Girls Weekly - 初探前端網頁技術 JavaScript 1/3
Vue 2.0 + Vuex Router & Vuex at Vue.js
Vue 2.0 + Vuex Router & Vuex at Vue.js
Rails Girls Weekly - 初探前端網頁技術 JavaScript 3/3
Rails Girls Weekly - 初探前端網頁技術 JavaScript 3/3
資料視覺化的力量
資料視覺化的力量
Demo for ms azure machine learning
Demo for ms azure machine learning
Tutorial for ms azure machine learning
Tutorial for ms azure machine learning
郵遞公文追蹤系統操作說明
郵遞公文追蹤系統操作說明
Processing 基礎教學
Processing 基礎教學
ES6 PPT FOR 2016
ES6 PPT FOR 2016
大數據時代的行動支付風險控制
大數據時代的行動支付風險控制
資料視覺化 / 数据可视化 Data Visualization
資料視覺化 / 数据可视化 Data Visualization
機器學習工具介紹 / 机器学习工具介绍 Demos for Machine Learning Tools
機器學習工具介紹 / 机器学习工具介绍 Demos for Machine Learning Tools
Bootstrap4 與他的好搭檔
Bootstrap4 與他的好搭檔
20151210 台灣創用cc計畫×開放文化基金會-台灣創用cc計畫教學教材參考投影片-創用cc知多少-odp
20151210 台灣創用cc計畫×開放文化基金會-台灣創用cc計畫教學教材參考投影片-創用cc知多少-odp
Dernier
محاضرات الاحصاء التطبيقي لطلاب علوم الرياضة.pdf
محاضرات الاحصاء التطبيقي لطلاب علوم الرياضة.pdf
Khaled Elbattawy
RESOLUCION DEL SIMULACRO UNMSM 2023 ii 2.pptx
RESOLUCION DEL SIMULACRO UNMSM 2023 ii 2.pptx
scbastidasv
Castellà parelles 2n - Abril i Irina.pdf
Castellà parelles 2n - Abril i Irina.pdf
Ernest Lluch
Català parelles 3r - Emma i Ariadna (1).pdf
Català parelles 3r - Emma i Ariadna (1).pdf
Ernest Lluch
ClimART Action | eTwinning Project
ClimART Action | eTwinning Project
Nuckles
Català Individual 3r - Víctor.pdf JOCS FLORALS
Català Individual 3r - Víctor.pdf JOCS FLORALS
Ernest Lluch
Saunanaine_Helen Moppel_JUHENDATUD SAUNATEENUSE JA LOODUSMATKA SÜNERGIA_strat...
Saunanaine_Helen Moppel_JUHENDATUD SAUNATEENUSE JA LOODUSMATKA SÜNERGIA_strat...
Eesti Loodusturism
Díptic IFE (2) ifeifeifeife ife ife.pdf
Díptic IFE (2) ifeifeifeife ife ife.pdf
institutpladelbosc pladelbosc
Dernier
(8)
محاضرات الاحصاء التطبيقي لطلاب علوم الرياضة.pdf
محاضرات الاحصاء التطبيقي لطلاب علوم الرياضة.pdf
RESOLUCION DEL SIMULACRO UNMSM 2023 ii 2.pptx
RESOLUCION DEL SIMULACRO UNMSM 2023 ii 2.pptx
Castellà parelles 2n - Abril i Irina.pdf
Castellà parelles 2n - Abril i Irina.pdf
Català parelles 3r - Emma i Ariadna (1).pdf
Català parelles 3r - Emma i Ariadna (1).pdf
ClimART Action | eTwinning Project
ClimART Action | eTwinning Project
Català Individual 3r - Víctor.pdf JOCS FLORALS
Català Individual 3r - Víctor.pdf JOCS FLORALS
Saunanaine_Helen Moppel_JUHENDATUD SAUNATEENUSE JA LOODUSMATKA SÜNERGIA_strat...
Saunanaine_Helen Moppel_JUHENDATUD SAUNATEENUSE JA LOODUSMATKA SÜNERGIA_strat...
Díptic IFE (2) ifeifeifeife ife ife.pdf
Díptic IFE (2) ifeifeifeife ife ife.pdf
[朝陽科大] D3.js 資料視覺化入門
1.
Kuro Hsu @ D3.js 2015/12/23
2.
Kuro Hsu • @ •
COSCUP • JSDC • kurotanshi [at] gmail.com • http://kuro.tw
3.
D3 D3.js D3
4.
Web
5.
Web
6.
• • • •
7.
8.
9.
10.
• • • •
11.
12.
http://d3js.org/ Demo: https://goo.gl/idrDMt
13.
14.
* svg IE9+
15.
• D3 =
Data-Driven Documents. • (HTML / CSS / JavaScript / SVG) • Data-Driven DOM • SVG SVG jQuery • D3.js
16.
DOM
17.
JavaScript jQuery D3.js document.querySelectorAll(".block") $(".block") d3.selectAll(".block")
18.
d3.select("body").selectAll(".block") d3.selectAll("body .block")
19.
(method chaining) var box
= d3.selectAll('.box'); box.style('color', '#f00'); box.text('Hello World!'); var box = d3.selectAll('.box') .style('color', '#f00') .text('Hello World!');
20.
(attr) // attr() d3.selectAll("circle") .attr("cx", 50) .attr("cy",
50) .attr("r", 25) .style("fill", "red");
21.
(attr) // d3.selectAll("circle") .attr({ "cx": 50,
"cy": 50, "r": 25 }) .style("fill", "red"); // circle cx d3.select("circle").attr("cx");
22.
(property) d3.selectAll('.name') .property('value', 'Kuro'); attr()
property() : disabled, checked value d3.selectAll('.name') .property('disabled');
23.
class d3.selectAll('.block') .classed('item', true); d3.selectAll('.block') .classed('item',
false); d3.selectAll('.block') .classed('item big', true);
24.
styles d3.selectAll('.block') .style('color', '#f00'); d3.selectAll('.block') .style({ 'color':
'#f00', 'font-size': '15px' });
25.
text & html var
foo = d3.selectAll('.foo'); foo.text('Hello World!'); foo.html('<div class="bar">Hello</div>');
26.
27.
Data - var data
= [1, 3, 5, 2, 4, 6, 8, 10];
28.
Data - jsbin.com/kifihirugu var data
= [ {x: 10.0, y: 9.14}, {x: 8.0, y: 8.14}, {x: 13.0, y: 8.74}, {x: 9.0, y: 8.77}, …… ];
29.
key function var data
= [ { 'name': 'kuro', 'age': 30 }, { 'name': 'John', 'age': 20 }, { 'name': 'Mary', 'age': 18 } ]; var p = d3.select('body') .selectAll('p') .data(data) .enter() .append('p') .text(function(d, i) { return d.name + ': ' + d.age + ' '; });
30.
31.
Enter, Update, Exit
Pattern var data = [1, 2, 3, 4, 5]; d3.select('body') .selectAll('div') .data( data ) .enter() .append('div') .text(function(d, i){ return d; }); 1 2 3 4 5
32.
Enter, Update, Exit
Pattern data = [1, 3, 5, 7, 9]; d3.select('body') .selectAll('div') .data( data ) .text(function(d, i){ return d }); 1 3 5 7 9
33.
Enter, Update, Exit
Pattern data = [10, 20, 30]; d3.select('body') .selectAll('div') .data( data ) .exit() .remove(); 1 3 5 7 9
34.
Enter, Update, Exit
Pattern data = [10, 20, 30]; d3.select('body') .selectAll('div') .data( data ) .exit() .remove(); 1 3 5 7 9 ?
35.
Enter, Update, Exit
Pattern data = [10, 20, 30]; d3.select('body') .selectAll('div') .data( data ) .text( function(d, i){ return d; }) .exit() .remove(); 10 20 30 7 9
36.
37.
SELECTION Datas Enter & Update
Exit & Remove SELECTION
38.
Enter: Data >
Elements. Update: Data = Elements. Remove: Data < Elements.
39.
Ajax with D3 d3.json([URL],
function(error, data){ if (error) return console.warn(error); // do something }); d3.csv([URL]).get(function(error, data){ // do something });
40.
41.
d3.scale.linear().domain().range() 補間⽅法 輸入範圍 輸出範圍
42.
Domain Range
43.
0 1000 0 100 500 50 Domain Range
44.
var d3Scale =
d3.scale.linear() // linear .domain([0, 1000]) // .range([0, 100]); // console.log( d3Scale(500) ); // 50 console.log( d3Scale(123) ); // 12.3
45.
var colorScale =
d3.scale.linear() .domain([0, 20]) .range(["#f00", "#0f0"]); for (var i = 0; i < 21; i++) { body.append('div') .style('background-color', colorScale(i)); }
46.
var widthScale =
d3.scale.linear() .domain([0, 12]) .range(["0px", "720px"]); for (var i = 0; i < 13; i++) { body.append('div').text( widthScale(i) ); }
47.
var red =
d3.rgb(255,0,0); var green = d3.rgb(0,255,0); var compute = d3.interpolate(red, green); console.log( compute(0) ); // #ff0000 console.log( compute(0.3) ); // #b34d00 console.log( compute(0.5) ); // #808000 console.log( compute(0.7) ); // #4db300 console.log( compute(1) ); // #00ff00
48.
var a =
"50px"; var b = "1000px"; var compute = d3.interpolate(a, b); console.log( compute(0) ); // 50px console.log( compute(0.3) ); // 335px console.log( compute(0.5) ); // 525px console.log( compute(0.7) ); // 715px console.log( compute(1) ); // 1000px
49.
d3.scale.category10() d3.scale.category20() d3.scale.category20b() d3.scale.category20c()
50.
51.
var data =
[0, 150, 200, 300, 500, 1000]; // x scale var xScale = d3.scale.linear() .domain(d3.extent(data)) // [0, 1000] .range([0, 500]); // x-range // y scale var yScale = d3.scale.linear() .domain(d3.extent(data)) // [0, 1000] .range([0, 300]); // y-range
52.
// x var xAxis
= d3.svg.axis() .scale(xScale) .orient("bottom"); // // y var yAxis = d3.svg.axis() .scale(yScale) .orient("left"); //
53.
orient()
54.
Ticks - jsbin.com/cuvubiwipo // x var
xAxis = d3.svg.axis() .scale(xScale) .orient("bottom") .ticks(15) // , .tickFormat(function(d){ return d + "px"; }); // y var yAxis = d3.svg.axis() .scale(yScale) .orient("left");
55.
56.
57.
http://jsbin.com/yepapa
58.
SELECTION.transition() .duration(1000) // .delay(1000) // .ease(
... ) // Easing .attr({ 'transform': function(d){ ....... } }); *D3.js Easing Checker - http://bl.ocks.org/hunzy/9929724
59.
SELECTION.transition() .duration(1000) .each('start', function(){ …
}) // .attr({ … }) .each('end', function(){ … }); //
60.
SELECTION.on('click', function(){ alert('Hello D3!'); }); SELECTION.on('click',
null);
61.
SELECTION.on('click.event1', function(){ alert('Hello D3
event 1'); }); SELECTION.on('click.event2', function(){ alert('Hello D3 event 2'); });
62.
63.
SVG
64.
SVG source: http://www.cs.cmu.edu/~chuck/lennapg/lenna.shtml
65.
SVG source: http://komica.chiisana.net/vector/src/1205520731301.svg
66.
rect <rect x="20" y="20" width="150"
height="100" rx="0"></rect>
67.
circle <circle cx="55" cy="55"
r="50"></circle>
68.
line <line x1="10" y1="30"
x2="230" y2="60"></line> x1, y1 x2, y2
69.
text <text x="0" y="0"
dx="0" dy="0" font-size="50" text-anchor="start"> Hello </text> text-anchor="[start/middle/end]"
70.
text - tspan <text
x="0" y="20" style="font-size: 17px;"> <tspan>Hello, </tspan> <tspan fill="red">World </tspan> </text>
71.
text - tspan <text
x="0" y="20" style="font-size: 17px;"> <tspan x="10" dy="10">Hello, </tspan> <tspan x="10" dy="20">World </tspan> </text>
72.
g (group) <g transform="rotate(45
50 50)"> <line> … </line> <rect> … </rect> <text> … </text> </g>
73.
path • • d +
74.
path • : M
(MoveTo) • : L (LineTo) / H (Horizontal) /V (Vertical) • : C (CurveTo) / S (Shorthand/Smooth CurveTo) Q (Quadratic Bezier CurveTo) T (smooth quadratic Bezier CurveTo) • : A (elliptical Arc) • : Z (close-path)
75.
path <line x1="10" y1="50"
x2="390" y2="130"> <path d="M10,50L390,130">
76.
- d3.svg.line var linePath
= d3.svg.line(); var data = [[10,50], [390, 130]]; svg.append('path') .attr('d', linePath(data)); <path d="M10,50L390,130">
77.
- d3.svg.line var svg
= d3.select('.svg'); var linePath = d3.svg.line() .x(function(d, i){ return d; }) .y(function(d, i){ return (i%2 === 0) ? 40 : 120;}) var data = [40, 80, 120, 160, 200, 240, 280, 320, 360]; svg.append('path') .attr({ 'd': linePath(data) });
78.
79.
d3.svg.line() .x(…).y(…) .interpolate("linear"); .interpolate("linear-closed"); .interpolate("basis"); .interpolate("cardinal"); .interpolate("step"); https://github.com/mbostock/d3/wiki/SVG-Shapes#user-content-line_interpolate
80.
-
81.
- d3.svg.arc
82.
- d3.svg.arc var myArc1
= { "startAngle": 0, "endAngle": Math.PI }; var myArc2 = { "startAngle": Math.PI, "endAngle": Math.PI * 1.5 }; var myArc3 = { "startAngle": Math.PI * 1.5, "endAngle": Math.PI * 2 };
83.
- d3.svg.arc var arc
= d3.svg.arc() .innerRadius(50) .outerRadius(150); svg.append('path') .attr({ 'd': arc(myArc1) });
84.
- d3.svg.arc
85.
- d3.svg.arc http://community.yungching.com.tw/Building/9443
86.
- d3.svg.arc
87.
Responsive with D3
88.
www.nytimes.com/interactive/2015/06/17/world/middleeast/map-isis-attacks-around-the-world.html
89.
www.nytimes.com/interactive/2015/06/17/world/middleeast/map-isis-attacks-around-the-world.html
90.
Responsive with D3
91.
Responsive with D3 //
width = parseInt(d3.select(".content").style("width")) - margin*2; height = parseInt(d3.select(".content").style("height")) - margin*2; // var margin = 40, width = 960 - margin*2, height = 500 - margin*2;
92.
var svg =
d3.select('.svg'); // function function rendering() { // // } // window resize d3.select(window).on('resize', rendering); // rendering();
93.
94.
// resize ,
x, y , var yAxis = d3.svg.axis() .scale(yScale2) .orient("left") .ticks( Math.max(height/50, 2) ); Responsive with D3
95.
96.
Responsive with D3 •
SVG • • / • RWD
97.
d3 Layouts
98.
D3.js Layouts • d3.js
11 (layouts) • • layouts d3 • top, left, d
99.
Pie Layout
100.
Pie Layout -
101.
Chord Layout 2015 12
A
102.
Chord Layout - 4
4 8 4 7 1 - 6 1 8 2 7 5 - 1 11 16 9 5 3 - 2 4 7 7 7 0 - 7 1 1 1 0 1 -
103.
Chord Layout
104.
Chord Layout
105.
Chord Layout
106.
Chord Layout
107.
Hierarchy Layout : 2014
108.
Partition Layout
109.
Partition Layout // nodes
data() var gRects = svg.selectAll("g").data(nodes).enter().append("g"); // rect gRects.append("rect").attr({ ... }).style({ ... }); // gRects.append("text").attr({ ... }).style({ ... }); // : d3.layout.partition() // size , .nodes var nodes = d3.layout.partition() .size([600, 400]) // [width, height] .nodes(data);
110.
Partition Layout
111.
Partition Layout // :
d3.layout.partition() // size , .nodes var nodes = d3.layout.partition() .size([2 * Math.PI, radius * radius]) .nodes(data); // d3.svg.arc var arc = d3.svg.arc() .startAngle(function (d) { return d.x; }) .endAngle(function (d) { return d.x + d.dx; }) .innerRadius(function (d) { return Math.sqrt(d.y); }) .outerRadius(function (d) { return Math.sqrt(d.y + d.dy); });
112.
http://bl.ocks.org/mbostock/1256572
113.
500
114.
500 1500
115.
500 1500 1500 500
116.
https://www.facebook.com/forpeople/photos/a. 989035831154301.1073741835.153819538009272/989036197820931/
117.
( ) (
)
118.
119.
120.
0 200000000000000000000 400000000000000000000 600000000000000000000 800000000000000000000 1000000000000000000000
121.
122.
http://p.udn.com.tw/upf/newmedia/2015_data/20150930_udntyphoon/udntyphoon/index.html
123.
124.
http://blog.infographics.tw/
125.
126.
– Randy Krum,
Author of Cool Infographics.
127.
• Kuro Hsu •
Demo code: https://github.com/kurotanshi/d3js-samples • kurotanshi [at] gmail.com • http://kuro.tw Thanks!
Télécharger maintenant