ts-drawing-components-polyline.md 3.2 KB
Newer Older
Z
zengyawen 已提交
1 2
# Polyline

Z
zengyawen 已提交
3 4
折线绘制组件。

T
third  
tianyu 已提交
5 6 7
>  **说明:**
>
>  该组件从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。
Z
zengyawen 已提交
8

Z
zengyawen 已提交
9 10

## 子组件
Z
zengyawen 已提交
11 12 13



Z
zengyawen 已提交
14 15 16

## 接口

L
fix doc  
luoying_ace_admin 已提交
17
Polyline(value?: {width?: string | number, height?: string | number})
Z
zengyawen 已提交
18

19 20
**参数:**

21
| 参数名 | 参数类型 | 必填 | 默认值 | 参数描述 |
22
| -------- | -------- | -------- | -------- | -------- |
23 24
| width | string \| number | 否 | 0 | 宽度。 |
| height | string \| number | 否 | 0 | 高度。 |
Z
zengyawen 已提交
25 26 27 28


## 属性

L
luoying_ace_admin 已提交
29 30
除支持[通用属性](ts-universal-attributes-size.md)外,还支持以下属性:

31
| 参数名称 | 参数类型 | 默认值 | 必填 | 参数描述 |
Z
zengyawen 已提交
32
| -------- | -------- | -------- | -------- | -------- |
33
| points | Array<Point> | [] | 否 | 折线经过坐标点列表。 |
H
HelloCrease 已提交
34 35 36
| fill | [ResourceColor](ts-types.md) | Color.Black | 否 | 设置填充区域颜色。 |
| fillOpacity | number \| string \| [Resource](ts-types.md#resource类型) | 1 | 否 | 设置填充区域透明度。 |
| stroke | [ResourceColor](ts-types.md) | Color.Black | 否 | 设置线条颜色。 |
L
luoying_ace_admin 已提交
37 38 39 40 41
| strokeDashArray | Array<Length> | [] | 否 | 设置线条间隙。 |
| strokeDashOffset | number \| string | 0 | 否 | 线条绘制起点的偏移量。 |
| strokeLineCap | [LineCapStyle](ts-appendix-enums.md#linecapstyle) | LineCapStyle.Butt | 否 | 设置线条端点绘制样式。 |
| strokeLineJoin | [LineJoinStyle](ts-appendix-enums.md#linejoinstyle) | LineJoinStyle.Miter | 否 | 设置线条拐角绘制样式。 |
| strokeMiterLimit | number \| string | 4 | 否 | 设置锐角绘制成斜角的极限值。 |
H
HelloCrease 已提交
42
| strokeOpacity | number \| string \| [Resource](ts-types.md#resource类型) | 1 | 否 | 设置线条透明度。 |
L
luoying_ace_admin 已提交
43 44 45 46 47 48 49 50 51 52
| strokeWidth | Length | 1 | 否 | 设置线条宽度。 |
| antiAlias | boolean | true | 否 | 是否开启抗锯齿效果。 |

## Point

点坐标类型。

| 名称      | 类型定义             | 描述                                                         |
| --------- | -------------------- | ------------------------------------------------------------ |
| Point | [number, number] | 第一个参数为x轴坐标,第二个参数为y轴坐标(相对坐标)。 |
Z
zengyawen 已提交
53 54

## 示例
Z
zengyawen 已提交
55

H
geshi  
HelloCrease 已提交
56 57
```ts
// xxx.ets
Z
zengyawen 已提交
58 59 60 61
@Entry
@Component
struct PolylineExample {
  build() {
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
    Column({ space: 10 }) {
      // 在 100 * 100 的矩形框中绘制一段折线,起点(0, 0),经过(20,60),到达终点(100, 100)
      Polyline({ width: 100, height: 100 })
        .points([[0, 0], [20, 60], [100, 100]])
        .fillOpacity(0)
        .stroke(Color.Blue)
        .strokeWidth(3)
      // 在 100 * 100 的矩形框中绘制一段折线,起点(20, 0),经过(0,100),到达终点(100, 90)
      Polyline()
        .width(100)
        .height(100)
        .fillOpacity(0)
        .stroke(Color.Red)
        .strokeWidth(8)
        .points([[20, 0], [0, 100], [100, 90]])
          // 设置折线拐角处为圆弧
        .strokeLineJoin(LineJoinStyle.Round)
          // 设置折线两端为半圆
        .strokeLineCap(LineCapStyle.Round)
    }.width('100%')
Z
zengyawen 已提交
82 83 84 85
  }
}
```

86
![zh-cn_image_0000001219744185](figures/zh-cn_image_0000001219744185.png)