d3.js--Arrow Drawing

Source: Internet
Author: User

First we need to understand how to draw arrows in SVG:

Write a pair of <defs> first, and then write a pair of <marker> inside, where the attribute of marker is:

ViewBox The area of the coordinate system
reFX, Refy The datum point within the ViewBox, which is plotted at the end of the line (note case).
Markerunits A datum with a size of two values: strokewidth (width of line) and Userspaceonuse (the size of the front of the graph)
Markerwidth, Markerheight Size of the identity
Orient Draw direction, can be set to: Auto (auto confirm direction) and angle value
Id ID number of the identity
Then we use the d3.js to draw the arrows more clearly:

Add Defs label var defs = Svg.append ("defs");//Add marker tag and its properties var arrowmarker = defs.append ("marker")    . attr ("id", " Arrow ").    attr (" Markerunits "," Strokewidth "). attr (" Markerwidth ").    attr (" Markerheight ",.)    attr ("ViewBox", "0 0"). attr ("reFX", 6). attr ("Refy",    6). attr ("Orient",    "Auto")
Draw straight arrow var Arrow_path = "m2,2 l10,6 l2,10 l6,6 l2,2"; Arrowmarker.append ("path")    . attr ("D", Arrow_path)    . attr ( "Fill", "#000")//Draw linear var line = Svg.append ("lines").    attr ("x1").    attr (    "Y1", "attr", x2).    attr ("y2").    attr ("Stroke", "red").    attr ("Stroke-width", 2)    . attr ("Marker-start", "url (#arrow)")    . attr ("Marker-end", "url (#arrow)")
Draw the curve arrow var curve_path = "m20,70 t80,100 t160,80 t200,90"; var curve = svg.append ("path")    . attr ("D", Curve_path) .    attr ("Fill", "white").    attr ("Stroke", "red").    attr ("Stroke-width", 2)    . attr ("Marker-start", URL (#arrow)).    attr ("Marker-mid", "url (#arrow)")    . attr ("Marker-end", "url (#arrow)");

The properties drawn at different locations are as follows:

    • Marker-start: At the beginning of the path
    • Marker-mid: At the middle end of the path (must be a point in the middle of Path)
    • Marker-end: At the end of the path
The drawing results are as follows:






d3.js--Arrow Drawing

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.