-
// svg
const SVG_WIDTH = 500
const SVG_HEIGHT = 250
const SVG_MARGIN = { left: 50, top: 30, right: 20, bottom: 20 }
const G_WIDTH = SVG_WIDTH - SVG_MARGIN.left - SVG_MARGIN.right
const G_HEIGHT = SVG_HEIGHT - SVG_MARGIN.top - SVG_MARGIN.bottom
// d3.select('#container').append('svg:svg')
const svg = d3
?.select('#container')
?.append('svg')
?//width height
?.attr('width', SVG_WIDTH) // attribute
?.attr('height', SVG_HEIGHT)
const g = d3
?.select('svg')
?.append('g')
?.attr('transform', `translate(${SVG_MARGIN.left}, ${SVG_MARGIN.top})`)
const data = [1, 3, 5, 7, 8, 4, 3, 7]
const scaleX = d3
?.scaleLinear()
?.domain([0, data.length]) // 輸入的范圍
?.range([0, G_WIDTH]) // 輸出的范圍
const scaleY = d3
?.scaleLinear()
?.domain([0, d3.max(data)]) // 輸入的范圍
?.range([G_HEIGHT, 0]) // 輸出的范圍
// const lineGenerartor = d3.svg
const lineGenerartor = d3
?.line()
?// .x((d, i) => i) // 0,1,2,3,4
?.x((d, i) => scaleX(i)) // 0,1,2,3,4
?.y((d) => scaleY(d)) // 1, 3, 5, 7, 8, 4, 3, 7
?// .interpolate('cardinal') // 線的擬合方式
?.curve(d3.curveCatmullRom.alpha(0.5)) // 線的擬合方式
g.append('path').attr('d', lineGenerartor(data)) //d=M1,0L20,$0L40,50L!00,200L0,200 ? d : is a short for path data
const xAxis = d3.axisBottom(scaleX)
const yAxis = d3.axisLeft(scaleY)
g.append('g').call(xAxis).attr('transform', `translate(0, ${G_HEIGHT})`)
g.append('g').call(yAxis)
查看全部 -
// svg
const SVG_WIDTH = 500
const SVG_HEIGHT = 250
const SVG_MARGIN = { left: 50, top: 30, right: 20, bottom: 20 }
const G_WIDTH = SVG_WIDTH - SVG_MARGIN.left - SVG_MARGIN.right
const G_HEIGHT = SVG_HEIGHT - SVG_MARGIN.top - SVG_MARGIN.bottom
// d3.select('#container').append('svg:svg')
const svg = d3
?.select('#container')
?.append('svg')
?//width height
?.attr('width', SVG_WIDTH) // attribute
?.attr('height', SVG_HEIGHT)
const g = d3
?.select('svg')
?.append('g')
?.attr('transform', `translate(${SVG_MARGIN.left}, ${SVG_MARGIN.top})`)
const data = [1, 3, 5, 7, 8, 4, 3, 7]
const scaleX = d3
?.scaleLinear()
?.domain([0, data.length]) // 輸入的范圍
?.range([0, G_WIDTH]) // 輸出的范圍
const scaleY = d3
?.scaleLinear()
?.domain([0, d3.max(data)]) // 輸入的范圍
?.range([G_HEIGHT, 0]) // 輸出的范圍
// const lineGenerartor = d3.svg
const lineGenerartor = d3
?.line()
?// .x((d, i) => i) // 0,1,2,3,4
?.x((d, i) => scaleX(i)) // 0,1,2,3,4
?.y((d) => scaleY(d)) // 1, 3, 5, 7, 8, 4, 3, 7
?// .interpolate('cardinal') // 線的擬合方式
?.curve(d3.curveCatmullRom.alpha(0.5)) // 線的擬合方式
g.append('path').attr('d', lineGenerartor(data)) //d=M1,0L20,$0L40,50L!00,200L0,200 ? d : is a short for path data
const xAxis = d3.axisBottom(scaleX)
const yAxis = d3.axisLeft(scaleY)
g.append('g').call(xAxis).attr('transform', `translate(0, ${G_HEIGHT})`)
g.append('g').call(yAxis)
查看全部 -
簡單可視化查看全部
-
enter查看全部
-
https://blog.csdn.net/ysj1218/article/details/80523474,鏈式調(diào)用有點類似于jQuery
查看全部 -
查看瀏覽器的支持列表
????支持svg的瀏覽器,對d3的支持還是比較好的
查看全部 -
d3代碼在github上
查看全部 -
select&selectAll? 選擇html上的dom元素
append? 添加我們想要的一些元素
讀取和使用數(shù)據(jù)? 使用一些函數(shù)來讀取和使用數(shù)據(jù),也可以使用dsv、csv一些數(shù)據(jù)格式
查看全部 -
可以做什么
查看全部 -
g元素 相當于html中的div,可以理解為group查看全部
-
d3.select(selector) 選擇符合條件的第一個元素 d3.selectAll(selector)選擇符合條件的所有元素查看全部
-
v4用新的曲線API來說明如何根據(jù)數(shù)據(jù)為line和area插值。line.interpolate和area.interpolate方法由line.curve和area.curve代替。 1, curveCatmullRom 2, curveCatmullRomClosed 3, curveCatmullRomOpen this._d3.line().curve(this._d3.curveCatmullRom.alpha(.5));查看全部
-
V4 nterpolate("cardinal") -> curve(d3.curveCardinal); d3.svg.line() -> d3.line() d3.scale.linear() -> d3.scaleLinear()查看全部
-
bost.ocks.org/mike/circles/查看全部
舉報