1# Gauge 2 3The **\<Gauge>** component is used to display data in a ring chart. 4 5 6> **NOTE** 7> 8> This component is supported since API version 8. Updates will be marked with a superscript to indicate their earliest API version. 9 10 11## Child Components 12 13This component can contain only one child component. 14 15> **NOTE** 16> 17> You are advised to use the **\<Text>** component to build the current value and auxiliary text. 18> 19> If the width and height of a child component are in percentage, the reference range is the rectangle whose outer ring is used as the inscribed circle. 20 21 22## APIs 23 24Gauge(options:{value: number, min?: number, max?: number}) 25 26Since API version 9, this API is supported in ArkTS widgets. 27 28**Parameters** 29 30| Name| Type| Mandatory| Description| 31| -------- | -------- | -------- | -------- | 32| value | number | Yes| Current value of the chart, that is, the position to which the pointer points in the chart. It is used as the initial value of the chart when the component is created.<br>**NOTE**<br>If the value is not within the range defined by the **min** and **max** parameters, the value of **min** is used.| 33| min | number | No| Minimum value of the current data segment.<br>Default value: **0**| 34| max | number | No| Maximum value of the current data segment.<br>Default value: **100**<br>**NOTE**<br>If the value of **max** is less than that of **min**, the default values **0** and **100** are used.<br>The values of **max** and **min** can be negative numbers.| 35 36## Attributes 37 38In addition to the [universal attributes](ts-universal-attributes-size.md), the following attributes are supported. 39 40| Name| Type| Description| 41| -------- | -------- | -------- | 42| value | number | Value of the chart. It can be dynamically changed.<br>Default value: **0**<br>Since API version 9, this API is supported in ArkTS widgets.| 43| startAngle | number | Start angle of the chart. The value **0** indicates 0 degrees, and a positive value indicates the clockwise direction.<br>Default value: **0**<br>Since API version 9, this API is supported in ArkTS widgets.| 44| endAngle | number | End angle of the chart. The value **0** indicates 0 degrees, and a positive value indicates the clockwise direction.<br>Default value: **360**<br>Since API version 9, this API is supported in ArkTS widgets.| 45| colors | [ResourceColor<sup>11+</sup>](ts-types.md#resourcecolor) \| [LinearGradient<sup>11+</sup>](ts-basic-components-datapanel.md#lineargradient10) \| Array<[ColorStop](#colorstop)> | Colors of the chart. Colors can be set for individual segments.<br>Default value in API version 9: **Color.Black**<br>Since API version 9, this API is supported in ArkTS widgets.<br>Since API version 11, this API follows the following rules:<br> If the parameter type is ResourceColor, the ring is of the monochrome type.<br> If the parameter type is LinearGradient, the ring is of the gradient type.<br> If the parameter type is array, the ring is of the gradient type.<br> A ring of the gradient type contains a maximum of nine color segments. If there are more than nine segments, the excess is not displayed.<br>Default value in API version 11:<br>If no color is passed or the passed array is empty, the ring will be a gradient consisting of the following colors: 0xFF64BB5C, 0xFFF7CE00, and 0xFFE84026.<br>If a color is passed but the color value is invalid, the ring will be in the color of 0xFFE84026.| 46| strokeWidth | [Length](ts-types.md#length) | Stroke width of the chart.<br>Default value: **4**<br>Unit: vp<br>Since API version 9, this API is supported in ArkTS widgets.<br>**NOTE**<br>A value less than 0 evaluates to the default value.<br>The value cannot be in percentage.| 47| description<sup>11+</sup> | [CustomBuilder](ts-types.md#custombuilder8) | Description of the chart.<br>**NOTE**<br>You need to customize the content – text or imagery recommended – in @Builder.<br>If the width and height of the custom content are in percentage, the reference range is a rectangle whose area is 44.4% x 25.4% of the ring diameter (28.6% x 28.6% for imagery), 0 vp away from the bottom of the ring, and centered horizontally.<br>If this parameter is set to null, no description is displayed.<br>If this parameter is not set, what's displayed is subject to the maximum and minimum value settings.<br>If either or both of the maximum and minimum values are set, they are displayed.<br>If neither maximum nor minimum values are set, no description is displayed.<br>The maximum and minimum values are displayed at the bottom of the ring and cannot be relocated. They may be blocked by the ring if the ring's start and end angles are not set properly.| 48| trackShadow<sup>11+</sup> | [GaugeShadowOptions](#gaugeshadowoptions11) | Shadow style of the chart.<br>**NOTE**<br>The shadow color is the same as the ring color.<br>If this attribute is set to **null**, the shadow effect is disabled.| 49| indicator<sup>11+</sup> | [GaugeIndicatorOptions](#gaugeindicatoroptions11) | Indicator style of the chart.<br>**NOTE**<br>If this attribute is set to **null**, no indicator is displayed.| 50 51## ColorStop 52 53Describes the gradient color stop. 54 55Since API version 9, this API is supported in ArkTS widgets. 56 57| Name | Type | Description | 58| --------- | -------------------- | ------------------------------------------------------------ | 59| ColorStop | [[ResourceColor](ts-types.md#resourcecolor) \| [LinearGradient<sup>11+</sup>](ts-basic-components-datapanel.md#lineargradient10), number] | Gradient color stop. The first parameter indicates the color value. If it is set to a non-color value, the color of 0xFFE84026 is used. The second parameter indicates the color weight. If it is set to a negative number or a non-numeric value, the color weight is 0.| 60 61## GaugeShadowOptions<sup>11+</sup> 62| Name | Type| Mandatory| Description| 63| ------------- | ------- | ---- | -------- | 64| radius | number \| [Resource](ts-types.md#resource)| No| Shadow blur radius.<br>Default value: **20**<br>Unit: vp<br>**NOTE**<br>A value less than or equal to 0 evaluates to the default value.| 65| offsetX | number \| [Resource](ts-types.md#resource)| No| Offset on the x-axis.<br>Default value: **5**<br>Unit: vp| 66| offsetY | number \| [Resource](ts-types.md#resource)| No| Offset on the y-axis.<br>Default value: **5**<br>Unit: vp| 67 68## GaugeIndicatorOptions<sup>11+</sup> 69| Name | Type| Mandatory| Description| 70| ------------- | ------- | ---- | -------- | 71| icon | [Resource](ts-types.md#resource)| No| Image path of the icon.<br>**NOTE**<br>If this parameter is not set, the default triangle style indicator is used.<br>Icons in SVG format are supported. If icons in other formats are used, the default triangle style indicator is used.| 72| space | [Dimension](ts-types.md#dimension10) | No| Distance between the indicator and the outer edge of the ring. The value cannot be in percentage.<br>Default value: **8**<br>Unit: vp<br>**NOTE**<br> For the default triangle style indicator, the distance is the amount of space between the triangle and the outer edge of the ring.<br> If this parameter is set to a value less than 0, the default value will be used.<br>If this parameter is set to a value greater than the ring radius, the default value will be used.| 73 74## Example 75### Example 1 76This example sets the current value, description, and auxiliary text. 77```ts 78@Entry 79@Component 80struct Gauge1 { 81 @Builder descriptionBuilder() { 82 Text('Description') 83 .maxFontSize('30sp') 84 .minFontSize("10.0vp") 85 .fontColor("#fffa2a2d") 86 .fontWeight(FontWeight.Medium) 87 .width('100%') 88 .height("100%") 89 .textAlign(TextAlign.Center) 90 } 91 92 build() { 93 Column() { 94 Gauge({ value: 50, min: 1, max: 100 }) { 95 Column() { 96 Text('50') 97 .fontWeight(FontWeight.Medium) 98 .width('62%') 99 .fontColor("#ff182431") 100 .maxFontSize("60.0vp") 101 .minFontSize("30.0vp") 102 .textAlign(TextAlign.Center) 103 .margin({ top: '35%' }) 104 .textOverflow({ overflow: TextOverflow.Ellipsis }) 105 .maxLines(1) 106 Text('Auxiliary text') 107 .maxFontSize("16.0fp") 108 .minFontSize("10.0vp") 109 .fontColor($r('sys.color.ohos_id_color_text_secondary')) 110 .fontColor($r('sys.color.ohos_id_color_text_secondary')) 111 .fontWeight(FontWeight.Regular) 112 .width('67.4%') 113 .height('9.5%') 114 .textAlign(TextAlign.Center) 115 }.width('100%').height('100%') 116 } 117 .value(50) 118 .startAngle(210) 119 .endAngle(150) 120 .colors([[new LinearGradient([{ color: "#deb6fb", offset: 0 }, { color: "#ac49f5", offset: 1 }]), 9], 121 [new LinearGradient([{ color: "#bbb7fc", offset: 0 }, { color: "#564af7", offset: 1 }]), 8], 122 [new LinearGradient([{ color: "#f5b5c2", offset: 0 }, { color: "#e64566", offset: 1 }]), 7], 123 [new LinearGradient([{ color: "#f8c5a6", offset: 0 }, { color: "#ed6f21", offset: 1 }]), 6], 124 [new LinearGradient([{ color: "#fceb99", offset: 0 }, { color: "#f7ce00", offset: 1 }]), 5], 125 [new LinearGradient([{ color: "#dbefa5", offset: 0 }, { color: "#a5d61d", offset: 1 }]), 4], 126 [new LinearGradient([{ color: "#c1e4be", offset: 0 }, { color: "#64bb5c", offset: 1 }]), 3], 127 [new LinearGradient([{ color: "#c0ece5", offset: 0 }, { color: "#61cfbe", offset: 1 }]), 2], 128 [new LinearGradient([{ color: "#b5e0f4", offset: 0 }, { color: "#46b1e3", offset: 1 }]), 1]]) 129 .width('80%') 130 .height('80%') 131 .strokeWidth(18) 132 .trackShadow({ radius: 7, offsetX: 7, offsetY: 7 }) 133 .description(this.descriptionBuilder) 134 .padding(18) 135 }.margin({ top: 40 }).width('100%').height('100%') 136 } 137} 138``` 139 140 141### Example 2 142This example sets the current value and icon. 143```ts 144@Entry 145@Component 146struct Gauge2 { 147 @Builder descriptionBuilderImage() { 148 Image($r('sys.media.ohos_ic_public_clock')).width(72).height(72) 149 } 150 151 build() { 152 Column() { 153 Gauge({ value: 50, min: 1, max: 100 }) { 154 Column() { 155 Text('50') 156 .fontWeight(FontWeight.Medium) 157 .width('62%') 158 .fontColor("#ff182431") 159 .maxFontSize("60.0vp") 160 .minFontSize("30.0vp") 161 .textAlign(TextAlign.Center) 162 .margin({ top: '35%' }) 163 .textOverflow({ overflow: TextOverflow.Ellipsis }) 164 .maxLines(1) 165 }.width('100%').height('100%') 166 } 167 .startAngle(210) 168 .endAngle(150) 169 .colors('#cca5d61d') 170 .width('80%') 171 .height('80%') 172 .strokeWidth(18) 173 .description(this.descriptionBuilderImage) 174 .padding(18) 175 }.margin({ top: 40 }).width('100%').height('100%') 176 } 177} 178``` 179 180 181### Example 3 182This example sets the current value and description. 183```ts 184@Entry 185@Component 186struct Gauge3 { 187 @Builder descriptionBuilder() { 188 Text('Description') 189 .maxFontSize('30sp') 190 .minFontSize("10.0vp") 191 .fontColor("#fffa2a2d") 192 .fontWeight(FontWeight.Medium) 193 .width('100%') 194 .height("100%") 195 .textAlign(TextAlign.Center) 196 } 197 198 build() { 199 Column() { 200 Column() { 201 Gauge({ value: 50, min: 1, max: 100 }) { 202 Column() { 203 Text('50') 204 .fontWeight(FontWeight.Medium) 205 .width('62%') 206 .fontColor("#ff182431") 207 .maxFontSize("60.0vp") 208 .minFontSize("30.0vp") 209 .textAlign(TextAlign.Center) 210 .margin({ top: '35%' }) 211 .textOverflow({ overflow: TextOverflow.Ellipsis }) 212 .maxLines(1) 213 }.width('100%').height('100%') 214 } 215 .startAngle(210) 216 .endAngle(150) 217 .colors([[new LinearGradient([{ color: "#deb6fb", offset: 0 }, { color: "#ac49f5", offset: 1 }]), 9], 218 [new LinearGradient([{ color: "#bbb7fc", offset: 0 }, { color: "#564af7", offset: 1 }]), 8], 219 [new LinearGradient([{ color: "#f5b5c2", offset: 0 }, { color: "#e64566", offset: 1 }]), 7], 220 [new LinearGradient([{ color: "#f8c5a6", offset: 0 }, { color: "#ed6f21", offset: 1 }]), 6], 221 [new LinearGradient([{ color: "#fceb99", offset: 0 }, { color: "#f7ce00", offset: 1 }]), 5], 222 [new LinearGradient([{ color: "#dbefa5", offset: 0 }, { color: "#a5d61d", offset: 1 }]), 4], 223 [new LinearGradient([{ color: "#c1e4be", offset: 0 }, { color: "#64bb5c", offset: 1 }]), 3], 224 [new LinearGradient([{ color: "#c0ece5", offset: 0 }, { color: "#61cfbe", offset: 1 }]), 2], 225 [new LinearGradient([{ color: "#b5e0f4", offset: 0 }, { color: "#46b1e3", offset: 1 }]), 1]]) 226 .width('80%') 227 .height('80%') 228 .strokeWidth(18) 229 .description(this.descriptionBuilder) 230 .trackShadow({ radius: 7, offsetX: 7, offsetY: 7 }) 231 .padding(18) 232 }.margin({ top: 40 }).width('100%').height('100%') 233 } 234 } 235} 236``` 237 238 239### Example 4 240This example sets the current value and auxiliary text. 241```ts 242@Entry 243@Component 244struct Gauge4 { 245 build() { 246 Column() { 247 Gauge({ value: 50, min: 1, max: 100 }) { 248 Column() { 249 Text('50') 250 .maxFontSize("72.0vp") 251 .minFontSize("10.0vp") 252 .fontColor("#ff182431") 253 .width('40%') 254 .textAlign(TextAlign.Center) 255 .margin({ top: '35%' }) 256 .textOverflow({ overflow: TextOverflow.Ellipsis }) 257 .maxLines(1) 258 Text('Auxiliary text') 259 .maxFontSize("30.0vp") 260 .minFontSize("18.0vp") 261 .fontWeight(FontWeight.Medium) 262 .fontColor($r('sys.color.ohos_id_color_text_secondary')) 263 .width('62%') 264 .height('15.9%') 265 .textAlign(TextAlign.Center) 266 }.width('100%').height('100%') 267 } 268 .startAngle(210) 269 .endAngle(150) 270 .colors([[new LinearGradient([{ color: "#deb6fb", offset: 0 }, { color: "#ac49f5", offset: 1 }]), 9], 271 [new LinearGradient([{ color: "#bbb7fc", offset: 0 }, { color: "#564af7", offset: 1 }]), 8], 272 [new LinearGradient([{ color: "#f5b5c2", offset: 0 }, { color: "#e64566", offset: 1 }]), 7], 273 [new LinearGradient([{ color: "#f8c5a6", offset: 0 }, { color: "#ed6f21", offset: 1 }]), 6], 274 [new LinearGradient([{ color: "#fceb99", offset: 0 }, { color: "#f7ce00", offset: 1 }]), 5], 275 [new LinearGradient([{ color: "#dbefa5", offset: 0 }, { color: "#a5d61d", offset: 1 }]), 4], 276 [new LinearGradient([{ color: "#c1e4be", offset: 0 }, { color: "#64bb5c", offset: 1 }]), 3], 277 [new LinearGradient([{ color: "#c0ece5", offset: 0 }, { color: "#61cfbe", offset: 1 }]), 2], 278 [new LinearGradient([{ color: "#b5e0f4", offset: 0 }, { color: "#46b1e3", offset: 1 }]), 1]]) 279 .width('80%') 280 .height('80%') 281 .strokeWidth(18) 282 .description(null) 283 .trackShadow({ radius: 7, offsetX: 7, offsetY: 7 }) 284 .padding(18) 285 }.margin({ top: 40 }).width('100%').height('100%') 286 } 287} 288``` 289 290 291### Example 5 292This example sets the current value, maximum value, and minimum value. 293```ts 294@Entry 295@Component 296struct Gauge5 { 297 build() { 298 Column() { 299 Gauge({ value: 50, min: 1, max: 100 }) { 300 Column() { 301 Text('50') 302 .maxFontSize("80sp") 303 .minFontSize("60.0vp") 304 .fontWeight(FontWeight.Medium) 305 .fontColor("#ff182431") 306 .width('40%') 307 .height('30%') 308 .textAlign(TextAlign.Center) 309 .margin({ top: '22.2%' }) 310 .textOverflow({ overflow: TextOverflow.Ellipsis }) 311 .maxLines(1) 312 }.width('100%').height('100%') 313 } 314 .startAngle(225) 315 .endAngle(135) 316 .colors(new LinearGradient([{ color: "#e84026", offset: 0 }, 317 { color: "#f7ce00", offset: 0.6 }, 318 { color: "#64bb5c", offset: 1 }])) 319 .width('80%') 320 .height('80%') 321 .strokeWidth(18) 322 .trackShadow({ radius: 7, offsetX: 7, offsetY: 7 }) 323 .padding(18) 324 }.margin({ top: 40 }).width('100%').height('100%') 325 } 326} 327``` 328 329 330### Example 6 331This example sets the current value, maximum and minimum values, and auxiliary text. 332```ts 333@Entry 334@Component 335struct Gauge6 { 336 build() { 337 Column() { 338 Gauge({ value: 50, min: 1, max: 100 }) { 339 Column() { 340 Text('50') 341 .maxFontSize('60sp') 342 .minFontSize('30.0vp') 343 .fontWeight(FontWeight.Medium) 344 .fontColor("#ff182431") 345 .width('62%') 346 .textAlign(TextAlign.Center) 347 .margin({ top: '35%' }) 348 .textOverflow({ overflow: TextOverflow.Ellipsis }) 349 .maxLines(1) 350 Text('Auxiliary text') 351 .maxFontSize('16sp') 352 .minFontSize("10.0vp") 353 .fontColor($r('sys.color.ohos_id_color_text_secondary')) 354 .fontWeight(FontWeight.Regular) 355 .width('67.4%') 356 .height('9.5%') 357 .textAlign(TextAlign.Center) 358 }.width('100%').height('100%') 359 } 360 .startAngle(225) 361 .endAngle(135) 362 .colors(Color.Red) 363 .width('80%') 364 .height('80%') 365 .indicator(null) 366 .strokeWidth(18) 367 .trackShadow({ radius: 7, offsetX: 7, offsetY: 7 }) 368 .padding(18) 369 }.margin({ top: 40 }).width('100%').height('100%') 370 } 371} 372``` 373 374 375### Example 7 376This example sets the current value, maximum value, and minimum value. 377```ts 378@Entry 379@Component 380struct Gauge7 { 381 build() { 382 Column() { 383 Gauge({ value: 50, min: 1, max: 100 }) { 384 Column() { 385 Text('50') 386 .maxFontSize('60sp') 387 .minFontSize('30.0vp') 388 .fontWeight(FontWeight.Medium) 389 .fontColor("#ff182431") 390 .width('62%') 391 .textAlign(TextAlign.Center) 392 .margin({ top: '35%' }) 393 .textOverflow({ overflow: TextOverflow.Ellipsis }) 394 .maxLines(1) 395 }.width('100%').height('100%') 396 } 397 .startAngle(225) 398 .endAngle(135) 399 .colors(Color.Red) 400 .width('80%') 401 .height('80%') 402 .indicator(null) 403 .strokeWidth(18) 404 .trackShadow({ radius: 7, offsetX: 7, offsetY: 7 }) 405 .padding(18) 406 }.margin({ top: 40 }).width('100%').height('100%') 407 } 408} 409``` 410 411