Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/redis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
D3.js d3 js中两个区域之间的线条宽度不反射_D3.js - Fatal编程技术网

D3.js d3 js中两个区域之间的线条宽度不反射

D3.js d3 js中两个区域之间的线条宽度不反射,d3.js,D3.js,我试图在两个区域之间画一条曲线,但我不能给这条线指定笔划宽度。这是我试过的 var w = 700, h = 250, margin = { top: 40, right: 20, bottom: 20, left: 40 }, radius = 6; var linePoints = [ [0, 100], [20, 150], [40, 90], [50, 120], [60, 8

我试图在两个区域之间画一条曲线,但我不能给这条线指定笔划宽度。这是我试过的

    var w = 700,
          h = 250,
          margin = { top: 40, right: 20, bottom: 20, left: 40 },
          radius = 6;


var linePoints = [
    [0, 100],
    [20, 150],
    [40, 90],
    [50, 120],
    [60, 80],
    [60, 150],
    [130, 80],
    [150, 80],
    [200, 75],
    [250, 70],
];



var lineGenerator = d3.line()
   .curve(d3.curveNatural);

var xScale = d3.scaleLinear().domain(
    [0, 250]
).range([0,750])
var yScale = d3.scaleLinear().domain(
    [0, 200]
).range([0, 150])



var areaBelow = d3.area()
    .x(function(d) { return xScale(d[0]); })
    .y0(h)
    .y1(function(d) { return yScale(d[1]); });
var areaAbove  =  d3.area()
    .x(function(d) { return xScale(d[0]); })
    .y0(0)
    .y1(function(d) { return yScale(d[1]); });  

var circlePoints = [
    [5, 100],
    [20, 150],
    [50, 120],
    [60, 80],
    [200, 75],

]
var pathData = lineGenerator(linePoints.map(function(d){ return [xScale(d[0]), yScale(d[1])]}));



d3.select('svg').append('path')
    //.attr("class", "line")
    .attr('d', pathData)
    .attr('stroke-width', 5)
    .attr('stroke', 'white')
    .attr("fill", "none");


d3.select('svg').append("path")
        .datum(linePoints)
        .attr("class", "area-below")
        .attr("d", areaBelow);

d3.select('svg').append("path")
        .datum(linePoints)
        .attr("class", "area-above")
        .attr("d", areaAbove);



d3.select('svg')
    .selectAll('circle')
    .data(circlePoints)
    .enter()
    .append('circle')
    .attr('cx', function(d) {
        return xScale(d[0]);
    })
    .attr('cy', function(d) {
        return yScale(d[1]);
    })
    .attr('r', 10)
    .attr('id', function(d, i) {
        return `circle-${i}`
    });    


d3.select('#circle-1').attr('class', 'inner-circle');

它有我指定的宽度-只是你用下面的区域和后面的区域来覆盖它。如果在这两个区域后添加带有笔划宽度的行,它将位于顶部,笔划宽度将可见。@Andrewerid是的,它起作用了!非常感谢。