1e41f4b71Sopenharmony_ci# Polygon
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ciThe **\<Polygon>** component is used to draw a polygon.
4e41f4b71Sopenharmony_ci
5e41f4b71Sopenharmony_ci>  **NOTE**
6e41f4b71Sopenharmony_ci>
7e41f4b71Sopenharmony_ci>  This component is supported since API version 7. Updates will be marked with a superscript to indicate their earliest API version.
8e41f4b71Sopenharmony_ci
9e41f4b71Sopenharmony_ci
10e41f4b71Sopenharmony_ci## Child Components
11e41f4b71Sopenharmony_ci
12e41f4b71Sopenharmony_ciNot supported
13e41f4b71Sopenharmony_ci
14e41f4b71Sopenharmony_ci
15e41f4b71Sopenharmony_ci## APIs
16e41f4b71Sopenharmony_ci
17e41f4b71Sopenharmony_ciPolygon(value?: {width?: string | number, height?: string | number})
18e41f4b71Sopenharmony_ci
19e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9.
20e41f4b71Sopenharmony_ci
21e41f4b71Sopenharmony_ci**Parameters**
22e41f4b71Sopenharmony_ci
23e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Default Value| Description|
24e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | -------- |
25e41f4b71Sopenharmony_ci| width | string \| number | No| 0 | Width.<br>**NOTE**<br>An invalid value is handled as the default value.|
26e41f4b71Sopenharmony_ci| height | string \| number | No| 0 | Height.<br>**NOTE**<br>An invalid value is handled as the default value.|
27e41f4b71Sopenharmony_ci
28e41f4b71Sopenharmony_ci## Attributes
29e41f4b71Sopenharmony_ci
30e41f4b71Sopenharmony_ciIn addition to the [universal attributes](ts-universal-attributes-size.md), the following attributes are supported.
31e41f4b71Sopenharmony_ci
32e41f4b71Sopenharmony_ci### points
33e41f4b71Sopenharmony_ci
34e41f4b71Sopenharmony_cipoints(value: Array&lt;Point&gt;)
35e41f4b71Sopenharmony_ci
36e41f4b71Sopenharmony_ciSets the vertex coordinates of the polygon. An invalid value is handled as the default value.
37e41f4b71Sopenharmony_ci
38e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9.
39e41f4b71Sopenharmony_ci
40e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
41e41f4b71Sopenharmony_ci
42e41f4b71Sopenharmony_ci**Parameters**
43e41f4b71Sopenharmony_ci
44e41f4b71Sopenharmony_ci| Name| Type                                                        | Mandatory| Description                                 |
45e41f4b71Sopenharmony_ci| ------ | ------------------------------------------------------------ | ---- | ------------------------------------- |
46e41f4b71Sopenharmony_ci| value  | Array&lt;[Point](ts-drawing-components-polyline.md#point)&gt; | Yes  | Vertex coordinates of the polygon.<br>Default value: **[]**|
47e41f4b71Sopenharmony_ci
48e41f4b71Sopenharmony_ci### fill
49e41f4b71Sopenharmony_ci
50e41f4b71Sopenharmony_cifill(value: ResourceColor)
51e41f4b71Sopenharmony_ci
52e41f4b71Sopenharmony_ciColor of the fill area. An invalid value is handled as the default value.
53e41f4b71Sopenharmony_ci
54e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9.
55e41f4b71Sopenharmony_ci
56e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
57e41f4b71Sopenharmony_ci
58e41f4b71Sopenharmony_ci**Parameters**
59e41f4b71Sopenharmony_ci
60e41f4b71Sopenharmony_ci| Name| Type                                      | Mandatory| Description                                  |
61e41f4b71Sopenharmony_ci| ------ | ------------------------------------------ | ---- | -------------------------------------- |
62e41f4b71Sopenharmony_ci| value  | [ResourceColor](ts-types.md#resourcecolor) | Yes  | Color of the fill area.<br>Default value: **Color.Black**|
63e41f4b71Sopenharmony_ci
64e41f4b71Sopenharmony_ci### fillOpacity
65e41f4b71Sopenharmony_ci
66e41f4b71Sopenharmony_cifillOpacity(value: number | string | Resource)
67e41f4b71Sopenharmony_ci
68e41f4b71Sopenharmony_ciOpacity of the fill area. The value range is [0.0, 1.0]. A value less than 0.0 evaluates to the value **0.0**. A value greater than 1.0 evaluates to the value **1.0**. Any other value evaluates to the value **1.0**.
69e41f4b71Sopenharmony_ci
70e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9.
71e41f4b71Sopenharmony_ci
72e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
73e41f4b71Sopenharmony_ci
74e41f4b71Sopenharmony_ci**Parameters**
75e41f4b71Sopenharmony_ci
76e41f4b71Sopenharmony_ci| Name| Type                                                        | Mandatory| Description                          |
77e41f4b71Sopenharmony_ci| ------ | ------------------------------------------------------------ | ---- | ------------------------------ |
78e41f4b71Sopenharmony_ci| value  | number \| string \| [Resource](ts-types.md#resource) | Yes  | Opacity of the fill area.<br>Default value: **1**|
79e41f4b71Sopenharmony_ci
80e41f4b71Sopenharmony_ci### stroke
81e41f4b71Sopenharmony_ci
82e41f4b71Sopenharmony_cistroke(value: ResourceColor)
83e41f4b71Sopenharmony_ci
84e41f4b71Sopenharmony_ciSets the stroke color. If this attribute is not set, the component does not have any stroke. If the value is invalid, no stroke will be drawn.
85e41f4b71Sopenharmony_ci
86e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9.
87e41f4b71Sopenharmony_ci
88e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
89e41f4b71Sopenharmony_ci
90e41f4b71Sopenharmony_ci**Parameters**
91e41f4b71Sopenharmony_ci
92e41f4b71Sopenharmony_ci| Name| Type                                      | Mandatory| Description      |
93e41f4b71Sopenharmony_ci| ------ | ------------------------------------------ | ---- | ---------- |
94e41f4b71Sopenharmony_ci| value  | [ResourceColor](ts-types.md#resourcecolor) | Yes  | Stroke color.|
95e41f4b71Sopenharmony_ci
96e41f4b71Sopenharmony_ci### strokeDashArray
97e41f4b71Sopenharmony_ci
98e41f4b71Sopenharmony_cistrokeDashArray(value: Array&lt;any&gt;)
99e41f4b71Sopenharmony_ci
100e41f4b71Sopenharmony_ciStroke dashes. An invalid value is handled as the default value.
101e41f4b71Sopenharmony_ci
102e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9.
103e41f4b71Sopenharmony_ci
104e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
105e41f4b71Sopenharmony_ci
106e41f4b71Sopenharmony_ci**Parameters**
107e41f4b71Sopenharmony_ci
108e41f4b71Sopenharmony_ci| Name| Type            | Mandatory| Description                     |
109e41f4b71Sopenharmony_ci| ------ | ---------------- | ---- | ------------------------- |
110e41f4b71Sopenharmony_ci| value  | Array&lt;any&gt; | Yes  | Stroke dashes.<br>Default value: **[]**|
111e41f4b71Sopenharmony_ci
112e41f4b71Sopenharmony_ci### strokeDashOffset
113e41f4b71Sopenharmony_ci
114e41f4b71Sopenharmony_cistrokeDashOffset(value: number | string)
115e41f4b71Sopenharmony_ci
116e41f4b71Sopenharmony_ciSets the offset of the start point for drawing the stroke. An invalid value is handled as the default value.
117e41f4b71Sopenharmony_ci
118e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9.
119e41f4b71Sopenharmony_ci
120e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
121e41f4b71Sopenharmony_ci
122e41f4b71Sopenharmony_ci**Parameters**
123e41f4b71Sopenharmony_ci
124e41f4b71Sopenharmony_ci| Name| Type                      | Mandatory| Description                                |
125e41f4b71Sopenharmony_ci| ------ | -------------------------- | ---- | ------------------------------------ |
126e41f4b71Sopenharmony_ci| value  | number \| string | Yes  | Offset of the start point for drawing the stroke.<br>Default value: **0**|
127e41f4b71Sopenharmony_ci
128e41f4b71Sopenharmony_ci### strokeLineCap
129e41f4b71Sopenharmony_ci
130e41f4b71Sopenharmony_cistrokeLineCap(value: LineCapStyle)
131e41f4b71Sopenharmony_ci
132e41f4b71Sopenharmony_ciSets the cap style of the stroke.
133e41f4b71Sopenharmony_ci
134e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9.
135e41f4b71Sopenharmony_ci
136e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
137e41f4b71Sopenharmony_ci
138e41f4b71Sopenharmony_ci**Parameters**
139e41f4b71Sopenharmony_ci
140e41f4b71Sopenharmony_ci| Name| Type                                             | Mandatory| Description                                            |
141e41f4b71Sopenharmony_ci| ------ | ------------------------------------------------- | ---- | ------------------------------------------------ |
142e41f4b71Sopenharmony_ci| value  | [LineCapStyle](ts-appendix-enums.md#linecapstyle) | Yes  | Cap style of the stroke.<br>Default value: **LineCapStyle.Butt**|
143e41f4b71Sopenharmony_ci
144e41f4b71Sopenharmony_ci### strokeLineJoin
145e41f4b71Sopenharmony_ci
146e41f4b71Sopenharmony_cistrokeLineJoin(value: LineJoinStyle)
147e41f4b71Sopenharmony_ci
148e41f4b71Sopenharmony_ciSets the join style of the stroke.
149e41f4b71Sopenharmony_ci
150e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9.
151e41f4b71Sopenharmony_ci
152e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
153e41f4b71Sopenharmony_ci
154e41f4b71Sopenharmony_ci**Parameters**
155e41f4b71Sopenharmony_ci
156e41f4b71Sopenharmony_ci| Name| Type                                               | Mandatory| Description                                              |
157e41f4b71Sopenharmony_ci| ------ | --------------------------------------------------- | ---- | -------------------------------------------------- |
158e41f4b71Sopenharmony_ci| value  | [LineJoinStyle](ts-appendix-enums.md#linejoinstyle) | Yes  | Join style of the stroke.<br>Default value: **LineJoinStyle.Miter**|
159e41f4b71Sopenharmony_ci
160e41f4b71Sopenharmony_ci### strokeMiterLimit
161e41f4b71Sopenharmony_ci
162e41f4b71Sopenharmony_cistrokeMiterLimit(value: number | string)
163e41f4b71Sopenharmony_ci
164e41f4b71Sopenharmony_ciSets the limit on the ratio of the miter length to the value of **strokeWidth** used to draw a miter join. The miter length indicates the distance from the outer tip to the inner corner of the miter. This attribute works only when **strokeLineJoin** is set to **LineJoinStyle.Miter**.
165e41f4b71Sopenharmony_ci
166e41f4b71Sopenharmony_ciThe value must be greater than or equal to 1.0. If the value is in the [0, 1) range, the value **1.0** will be used. In other cases, the default value will be used.
167e41f4b71Sopenharmony_ci
168e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9.
169e41f4b71Sopenharmony_ci
170e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
171e41f4b71Sopenharmony_ci
172e41f4b71Sopenharmony_ci**Parameters**
173e41f4b71Sopenharmony_ci
174e41f4b71Sopenharmony_ci| Name| Type                      | Mandatory| Description                                          |
175e41f4b71Sopenharmony_ci| ------ | -------------------------- | ---- | ---------------------------------------------- |
176e41f4b71Sopenharmony_ci| value  | number \| string | Yes  | Limit on the ratio of the miter length to the value of **strokeWidth** used to draw a miter join.<br>Default value: **4**|
177e41f4b71Sopenharmony_ci
178e41f4b71Sopenharmony_ci### strokeOpacity
179e41f4b71Sopenharmony_ci
180e41f4b71Sopenharmony_cistrokeOpacity(value: number | string | Resource)
181e41f4b71Sopenharmony_ci
182e41f4b71Sopenharmony_ciSets the stroke opacity. The value range is [0.0, 1.0]. A value less than 0.0 evaluates to the value **0.0**. A value greater than 1.0 evaluates to the value **1.0**. Any other value evaluates to the value **1.0**.
183e41f4b71Sopenharmony_ci
184e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9.
185e41f4b71Sopenharmony_ci
186e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
187e41f4b71Sopenharmony_ci
188e41f4b71Sopenharmony_ci**Parameters**
189e41f4b71Sopenharmony_ci
190e41f4b71Sopenharmony_ci| Name| Type                                                        | Mandatory| Description                      |
191e41f4b71Sopenharmony_ci| ------ | ------------------------------------------------------------ | ---- | -------------------------- |
192e41f4b71Sopenharmony_ci| value  | number \| string \| [Resource](ts-types.md#resource) | Yes  | Stroke opacity.<br>Default value: **1**|
193e41f4b71Sopenharmony_ci
194e41f4b71Sopenharmony_ci### strokeWidth
195e41f4b71Sopenharmony_ci
196e41f4b71Sopenharmony_cistrokeWidth(value: Length)
197e41f4b71Sopenharmony_ci
198e41f4b71Sopenharmony_ciSets the stroke width. If of the string type, this attribute cannot be set in percentage. A percentage is processed as 1 px.
199e41f4b71Sopenharmony_ci
200e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9.
201e41f4b71Sopenharmony_ci
202e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
203e41f4b71Sopenharmony_ci
204e41f4b71Sopenharmony_ci**Parameters**
205e41f4b71Sopenharmony_ci
206e41f4b71Sopenharmony_ci| Name| Type                        | Mandatory| Description                    |
207e41f4b71Sopenharmony_ci| ------ | ---------------------------- | ---- | ------------------------ |
208e41f4b71Sopenharmony_ci| value  | [Length](ts-types.md#length) | Yes  | Stroke width.<br>Default value: **1**|
209e41f4b71Sopenharmony_ci
210e41f4b71Sopenharmony_ci### antiAlias
211e41f4b71Sopenharmony_ci
212e41f4b71Sopenharmony_ciantiAlias(value: boolean)
213e41f4b71Sopenharmony_ci
214e41f4b71Sopenharmony_ciSpecifies whether anti-aliasing is enabled.
215e41f4b71Sopenharmony_ci
216e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9.
217e41f4b71Sopenharmony_ci
218e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
219e41f4b71Sopenharmony_ci
220e41f4b71Sopenharmony_ci**Parameters**
221e41f4b71Sopenharmony_ci
222e41f4b71Sopenharmony_ci| Name| Type   | Mandatory| Description                                 |
223e41f4b71Sopenharmony_ci| ------ | ------- | ---- | ------------------------------------- |
224e41f4b71Sopenharmony_ci| value  | boolean | Yes  | Whether anti-aliasing is enabled.<br>Default value: **true**|
225e41f4b71Sopenharmony_ci
226e41f4b71Sopenharmony_ci## Point
227e41f4b71Sopenharmony_ci
228e41f4b71Sopenharmony_ciDescribes the coordinates of a point.
229e41f4b71Sopenharmony_ci
230e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9.
231e41f4b71Sopenharmony_ci
232e41f4b71Sopenharmony_ci| Name     | Type            | Description                                                        |
233e41f4b71Sopenharmony_ci| --------- | -------------------- | ------------------------------------------------------------ |
234e41f4b71Sopenharmony_ci| Point | [number, number] | Coordinates of a point. The first parameter is the x-coordinate, and the second parameter is the y-coordinate (relative coordinate).|
235e41f4b71Sopenharmony_ci
236e41f4b71Sopenharmony_ci
237e41f4b71Sopenharmony_ci## Example
238e41f4b71Sopenharmony_ci
239e41f4b71Sopenharmony_ci```ts
240e41f4b71Sopenharmony_ci// xxx.ets
241e41f4b71Sopenharmony_ci@Entry
242e41f4b71Sopenharmony_ci@Component
243e41f4b71Sopenharmony_cistruct PolygonExample {
244e41f4b71Sopenharmony_ci  build() {
245e41f4b71Sopenharmony_ci    Column({ space: 10 }) {
246e41f4b71Sopenharmony_ci      // Draw a triangle in a 100 x 100 rectangle. The start point is (0, 0), the end point is (100, 0), and the passing point is (50, 100).
247e41f4b71Sopenharmony_ci      Polygon({ width: 100, height: 100 })
248e41f4b71Sopenharmony_ci        .points([[0, 0], [50, 100], [100, 0]])
249e41f4b71Sopenharmony_ci        .fill(Color.Green)
250e41f4b71Sopenharmony_ci      // Draw a quadrilateral in a 100 x 100 rectangle. The start point is (0, 0), the end point is (100, 0), and the passing points are (0, 100) and (100, 100).
251e41f4b71Sopenharmony_ci      Polygon().width(100).height(100)
252e41f4b71Sopenharmony_ci        .points([[0, 0], [0, 100], [100, 100], [100, 0]])
253e41f4b71Sopenharmony_ci        .fillOpacity(0)
254e41f4b71Sopenharmony_ci        .strokeWidth(5)
255e41f4b71Sopenharmony_ci        .stroke(Color.Blue)
256e41f4b71Sopenharmony_ci      // Draw a pentagon in a 100 x 100 rectangle. The start point is (50, 0), the end point is (100, 50), and the passing points are (0, 50), (20, 100), and (80, 100).
257e41f4b71Sopenharmony_ci      Polygon().width(100).height(100)
258e41f4b71Sopenharmony_ci        .points([[50, 0], [0, 50], [20, 100], [80, 100], [100, 50]])
259e41f4b71Sopenharmony_ci        .fill(Color.Red)
260e41f4b71Sopenharmony_ci        .fillOpacity(0.6)
261e41f4b71Sopenharmony_ci    }.width('100%').margin({ top: 10 })
262e41f4b71Sopenharmony_ci  }
263e41f4b71Sopenharmony_ci}
264e41f4b71Sopenharmony_ci```
265e41f4b71Sopenharmony_ci
266e41f4b71Sopenharmony_ci![en-us_image_0000001174582856](figures/en-us_image_0000001174582856.png)
267