我可以毫不费力地抽出spline using d3分.
<html>
<head>
<script src="https://d3js.org/d3.v7.min.js"></script>
<style>
.graph-container {
width: 100%;
height: 800px;
position: relative;
}
</style>
</head>
<body>
<div id="graph-container" class="graph-container"></div>
<script>
// Define the data points for the spline curve
const data = [
{ x: 0, y: 80, r: 12 },
{ x: 100, y: 100, r: 40 },
{ x: 200, y: 30, r: 6 },
{ x: 300, y: 50, r: 8 },
{ x: 400, y: 40, r: 10 },
{ x: 500, y: 80, r: 12 },
];
// Set up the SVG container
const svgWidth = 600;
const svgHeight = 200;
const svg = d3.select('#graph-container') // Select the graph-container div
.append('svg')
.attr('width', svgWidth)
.attr('height', svgHeight);
// Create the spline generator
const line = d3.line()
.x((d) => d.x)
.y((d) => d.y)
// .curve(d3.curveMonotoneX);
.curve(d3.curveCardinal);
// Draw the spline curve
svg.append('path')
.datum(data)
.attr('d', line)
.attr('fill', 'none')
.attr('stroke', 'green')
.attr('stroke-width', (d) => d.r);
</script>
</body>
</html>
我的问题是用不同的粗细(笔划宽度)绘制每个线段.我希望每条线段都能顺利过渡到下一个控制点.
D3.attr(‘笔划宽度’,(D)=>;D.R)似乎不起作用. 我怎么才能在Reaction JS中做到呢?
谢谢,