Draw triangle at bottom or top of line

blue-sky

In below code I'm attempting to draw a triangle at bottom of line (to represent a arrow) :

Code :

var svgContainer = d3.select("body").append("svg")
        .attr("width", 200)
        .attr("height", 200);

//Draw the line
var line = svgContainer.append("line")
        .attr("x1", 5)
        .attr("y1", 5)
        .attr("x2", 5)
        .attr("y2", 50)
        .attr("stroke-width", 2)
        .attr("stroke", "black");

line.append("svg:path") 
        .attr("d", d3.svg.symbol.type("triangle-up"))
        .style("fill", "black");

jsfiddle : http://jsfiddle.net/Qh9X5/3420/

But receive error :

Uncaught TypeError: undefined is not a function 

How can the triangle be drawn at top or bottom of line ?

meetamit

First of all, you don't need to make the arrowhead so manually. SVG has a way to put a marker at the end and/or beginning of a path, and it rotates it for you to match the path's angle. Check out any tutorial about SVG arrowheads, like this one.

Still, if you want to do it the way you started:

d3.svg.symbol.type("triangle-up") should become d3.svg.symbol().type("triangle-up")

and

Instead of line.append("svg:path"), which puts a path inside a line element (hence invalid), do svgContainer.append("svg:path") to make the path a sibling of the line.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to make top line shorter than bottom line (within div)

How to make top and bottom of div triangle with CSS?

Keep stdin line at top or bottom of terminal screen

Top and bottom line on errorbar with python and seaborn

Draw round corners on top left top right bottom left bottom right using Path and RectF in Android

Draw line on top of subplot to render a zoom effect

ChartJS Line chart cut off at the top and bottom

css triangle top with rounded bottom with different colour

How to moving top line to the bottom of the text in css

How to triangle top and bottom border?

Draw a line on top of stacked bar_plot

How to draw a line with a pointed triangle in Flutter?

Round the top and bottom of dashed line drawn with UIBezierPath

My divs line up from bottom to top instead of from top to bottom

Draw vertical line on top of image

Top to bottom for numbered triangle

UIButton Top and Bottom Border additional line

Border top and bottom without triangle cut

How to draw a line to perfectly align top of a text?

Draw top left triangle with linear-gradient and put it in a container

I need to line the bars up at the bottom, not the top

Draw line chart on top of area chart

Draw diagonal line from top right corner to bottom left using nested for loop in c# console app

Flutter - Draw a triangle in bottom right corner using customPainter

Matrix with the bottom triangle of only `1`s and top triangle of only `0`s in R

pandas - draw two dataframe in one plot but xticks on top and bottom

Unable to draw a layout on top of a bottom sheet

Material UI - Stepper top and bottom labels with line

Draw simulation from top to bottom instead of from center to border

TOP Ranking

  1. 1

    Failed to listen on localhost:8000 (reason: Cannot assign requested address)

  2. 2

    How to import an asset in swift using Bundle.main.path() in a react-native native module

  3. 3

    Loopback Error: connect ECONNREFUSED 127.0.0.1:3306 (MAMP)

  4. 4

    pump.io port in URL

  5. 5

    Spring Boot JPA PostgreSQL Web App - Internal Authentication Error

  6. 6

    BigQuery - concatenate ignoring NULL

  7. 7

    ngClass error (Can't bind ngClass since it isn't a known property of div) in Angular 11.0.3

  8. 8

    Do Idle Snowflake Connections Use Cloud Services Credits?

  9. 9

    maven-jaxb2-plugin cannot generate classes due to two declarations cause a collision in ObjectFactory class

  10. 10

    Compiler error CS0246 (type or namespace not found) on using Ninject in ASP.NET vNext

  11. 11

    Can't pre-populate phone number and message body in SMS link on iPhones when SMS app is not running in the background

  12. 12

    Generate random UUIDv4 with Elm

  13. 13

    Jquery different data trapped from direct mousedown event and simulation via $(this).trigger('mousedown');

  14. 14

    Is it possible to Redo commits removed by GitHub Desktop's Undo on a Mac?

  15. 15

    flutter: dropdown item programmatically unselect problem

  16. 16

    Change dd-mm-yyyy date format of dataframe date column to yyyy-mm-dd

  17. 17

    EXCEL: Find sum of values in one column with criteria from other column

  18. 18

    Pandas - check if dataframe has negative value in any column

  19. 19

    How to use merge windows unallocated space into Ubuntu using GParted?

  20. 20

    Make a B+ Tree concurrent thread safe

  21. 21

    ggplotly no applicable method for 'plotly_build' applied to an object of class "NULL" if statements

HotTag

Archive