• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Polyline
2
3>  **说明:**
4>
5>  该组件从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。
6
7
8折线绘制组件。
9
10
11## 权限列表
12
1314
15
16## 子组件
17
1819
20
21## 接口
22
23Polyline(options?: {width?: string | number, height?: string | number})
24
25**参数:**
26
27| 参数名 | 参数类型 | 必填 | 默认值 | 参数描述 |
28| -------- | -------- | -------- | -------- | -------- |
29| width | string \| number | 否 | 0 | 宽度。 |
30| height | string \| number | 否 | 0 | 高度。 |
31
32
33## 属性
34
35除支持[通用属性](ts-universal-attributes-size.md)外,还支持以下属性:
36
37| 名称 | 类型 | 默认值 | 描述 |
38| -------- | -------- | -------- | -------- |
39| points | Array<Point> | [] | 折线经过坐标点列表。 |
40| fill | [ResourceColor](ts-types.md#resourcecolor8) | Color.Black | 设置填充区域颜色。 |
41| fillOpacity | number \| string \| [Resource](ts-types.md#resource) | 1 | 设置填充区域透明度。 |
42| stroke | [ResourceColor](ts-types.md#resourcecolor8) | - | 设置线条颜色。 |
43| strokeDashArray | Array<Length> | [] | 设置线条间隙。 |
44| strokeDashOffset | number \| string | 0 | 线条绘制起点的偏移量。 |
45| strokeLineCap | [LineCapStyle](ts-appendix-enums.md#linecapstyle) | LineCapStyle.Butt | 设置线条端点绘制样式。 |
46| strokeLineJoin | [LineJoinStyle](ts-appendix-enums.md#linejoinstyle) | LineJoinStyle.Miter | 设置线条拐角绘制样式。 |
47| strokeMiterLimit | number&nbsp;\|&nbsp;string | 4 | 设置斜接长度与边框宽度比值的极限值。斜接长度表示外边框外边交点到内边交点的距离,边框宽度即strokeWidth属性的值。<br/>**说明:**<br/>该属性取值需大于等于1,且在strokeLineJoin属性取值LineJoinStyle.Miter时生效。 |
48| strokeOpacity | number&nbsp;\|&nbsp;string&nbsp;\|&nbsp;[Resource](ts-types.md#resource) | 1 | 设置线条透明度。<br/>**说明:**<br/>该属性的取值范围是[0.0, 1.0],若给定值小于0.0,则取值为0.0;若给定值大于1.0,则取值为1.0。 |
49| strokeWidth | Length | 1 | 设置线条宽度。 |
50| antiAlias | boolean | true | 是否开启抗锯齿效果。 |
51
52## Point
53
54点坐标类型。
55
56| 名称      | 类型定义             | 描述                                                         |
57| --------- | -------------------- | ------------------------------------------------------------ |
58| Point | [number,&nbsp;number] | 第一个参数为x轴坐标,第二个参数为y轴坐标(相对坐标)。 |
59
60
61## 示例
62
63```ts
64// xxx.ets
65@Entry
66@Component
67struct PolylineExample {
68  build() {
69    Column({ space: 10 }) {
70      // 在 100 * 100 的矩形框中绘制一段折线,起点(0, 0),经过(20,60),到达终点(100, 100)
71      Polyline({ width: 100, height: 100 })
72        .points([[0, 0], [20, 60], [100, 100]])
73        .fillOpacity(0)
74        .stroke(Color.Blue)
75        .strokeWidth(3)
76      // 在 100 * 100 的矩形框中绘制一段折线,起点(20, 0),经过(0,100),到达终点(100, 90)
77      Polyline()
78        .width(100)
79        .height(100)
80        .fillOpacity(0)
81        .stroke(Color.Red)
82        .strokeWidth(8)
83        .points([[20, 0], [0, 100], [100, 90]])
84          // 设置折线拐角处为圆弧
85        .strokeLineJoin(LineJoinStyle.Round)
86          // 设置折线两端为半圆
87        .strokeLineCap(LineCapStyle.Round)
88    }.width('100%')
89  }
90}
91```
92
93![zh-cn_image_0000001219744185](figures/zh-cn_image_0000001219744185.png)
94