准备工作创建画布、创建组之类的省略。
准备数据,并用比例尺扩大到整个画布(画布大小自己设置)

let data = [1,3,4,5,5]
let scale_x = d3.scaleLinear()
	.domain([0, data.length - 1])
	.range([0, this.svgWidth])
let scale_y = d3.scaleLinear()
	.domain([0, d3.max(data)])
	.range([0, this.svgHeight])

曲线生成器:

let curve_generator = d3.line()
	.x( (d) => scale_x(d) )
	.y( (d) => scale_y(d) )
	.curve(d3.curveBasis)

画出 path

svg.append('path')
	.attr('d', curve_generator(data)
	.attr('stroke', 'gray')
	.attr('stroke-width', 2)
	.attr('fill', 'none')

效果

d3 画曲线

相关文章:

  • 2021-06-19
  • 2022-12-23
  • 2022-12-23
  • 2021-08-04
  • 2021-06-24
  • 2022-02-07
  • 2022-01-05
猜你喜欢
  • 2022-12-23
  • 2021-05-19
  • 2022-12-23
  • 2021-07-20
  • 2021-09-02
  • 2021-08-15
  • 2021-07-23
相关资源
相似解决方案