user3809938
user3809938

Reputation: 1304

How to set d3 stroke width

At the moment the following draws two lines, but I can't seem to change the width:

var a = [23,50];
for (b = 0; b < a.length; b++) {
  var stripe = vis.selectAll("line.stripep")
    .data(connections.filter(function(d,i) { return i == a[b];  }))
    .enter().append("svg:line")
      .attr("class", "stripe")
      .attr("stroke", function(d) { return "#000000"; })
      .attr("stroke-linecap", 'round')
      .attr("stroke-width", 500)
      .attr("x1", function(d) { return x(d.station1.longitude); })
      .attr("y1", function(d) { return y(d.station1.latitude); })
      .attr("x2", function(d) { return x(d.station2.longitude); })
      .attr("y2", function(d) { return y(d.station2.latitude); })
}

I want to set the width of the two black lines to 500.

At the moment I am trying:

.attr("stroke-width", 500)

I have also tried:

.attr("stroke-width",  function(d) { return "500"; })

This also did not work. What is the correct way to do this?

Upvotes: 1

Views: 4069

Answers (2)

chriswang123456
chriswang123456

Reputation: 501

Change .attr to .style, and it should work

.style("stroke-width", function(d) { return "500"; })

Upvotes: 1

Maciej
Maciej

Reputation: 31

I just had the same problem. Solution: I found a .path entry within my CSS file with a 'stroke-width' setting. CSS has priority :-)

Upvotes: 3

Related Questions