You need to sign in or sign up before continuing.
js-components-svg-line.md 2.5 KB
Newer Older
E
ester.zhou 已提交
1
# line
Z
zengyawen 已提交
2

E
ester.zhou 已提交
3
The **\<line>** component is used to draw a line.
Z
zengyawen 已提交
4

E
ester.zhou 已提交
5 6 7
>  **NOTE**
>
>  This component is supported since API version 7. Updates will be marked with a superscript to indicate their earliest API version.
Z
zengyawen 已提交
8

E
ester.zhou 已提交
9 10

## Required Permissions
Z
zengyawen 已提交
11 12 13 14

None


E
ester.zhou 已提交
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
## Child Components

The following are supported: [\<animate>](js-components-svg-animate.md), [\<animateMotion>](js-components-svg-animatemotion.md), and [\<animateTransform>](js-components-svg-animatetransform.md).


## Attributes

The [universal attributes](../arkui-js/js-components-svg-common-attributes.md) and the attributes listed below are supported.

| Name| Type| Default Value| Mandatory| Description|
| -------- | -------- | -------- | -------- | -------- |
| id | string | - | No| Unique ID of the component.|
| x1 | &lt;length&gt;\|&lt;percentage&gt; | - | No| X-coordinate of the start point of the line. Attribute animations are supported.|
| y1 | &lt;length&gt;\|&lt;percentage&gt; | - | No| Y-coordinate of the start point of the line. Attribute animations are supported.|
| x2 | &lt;length&gt;\|&lt;percentage&gt; | - | No| X-coordinate of the end point of the line. Attribute animations are supported.|
| y2 | &lt;length&gt;\|&lt;percentage&gt; | - | No| Y-coordinate of the end point of the line. Attribute animations are supported.|


## Example

```html
Z
zengyawen 已提交
36 37 38 39 40 41
<!-- xxx.hml -->
<div class="container">
  <svg width="400" height="400">
    <line x1="10" x2="300" y1="50" y2="50" stroke-width="4" fill="white" stroke="blue"></line>
    <line x1="10" x2="300" y1="100" y2="100" stroke-width="4" fill="white" stroke="blue"></line>
    <line x1="10" x2="300" y1="150" y2="150" stroke-width="10" stroke="red" stroke-dasharray="5 3" stroke-dashoffset="3"></line>
E
ester.zhou 已提交
42
    // round: At the end of each path the stroke is extended by a half circle with a diameter equal to the stroke width.
Z
zengyawen 已提交
43
    <line x1="10" x2="300" y1="200" y2="200" stroke-width="10" stroke="black" stroke-linecap="round"></line>
E
ester.zhou 已提交
44
    // butt: The stroke for each path does not extend beyond its two endpoints.
Z
zengyawen 已提交
45
    <line x1="10" x2="300" y1="220" y2="220" stroke-width="10" stroke="black" stroke-linecap="butt"></line>
E
ester.zhou 已提交
46
    // square: At the end of each path the stroke is extended by a half circle, with the width being equal to half of the stroke width, and the height being equal to the stroke width.
Z
zengyawen 已提交
47 48 49 50 51 52
    <line x1="10" x2="300" y1="240" y2="240" stroke-width="10" stroke="black" stroke-linecap="square"></line>
  </svg>
</div>
```


E
ester.zhou 已提交
53
![en-us_image_0000001127284954](figures/en-us_image_0000001127284954.png)