ts-basic-components-gauge.md 3.3 KB
Newer Older
Z
zengyawen 已提交
1 2
# Gauge

E
ester.zhou 已提交
3 4
The **\<Gauge>** component is used to display data in a ring chart.

E
ester.zhou 已提交
5

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


E
esterzhou 已提交
11
## Child Components
Z
zengyawen 已提交
12

13
Not supported
Z
zengyawen 已提交
14 15 16 17


## APIs

E
ester.zhou 已提交
18
Gauge(options:{value: number, min?: number, max?: number})
Z
zengyawen 已提交
19

E
ester.zhou 已提交
20
**Parameters**
Z
zengyawen 已提交
21

E
ester.zhou 已提交
22 23
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
E
ester.zhou 已提交
24
| 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.|
E
ester.zhou 已提交
25 26
| min | number | No| Minimum value of the current data segment.<br>Default value: **0**|
| max | number | No| Maximum value of the current data segment.<br>Default value: **100**|
Z
zengyawen 已提交
27 28 29

## Attributes

E
ester.zhou 已提交
30 31 32 33
In addition to the [universal attributes](ts-universal-attributes-size.md), the following attributes are supported.

| Name| Type| Description|
| -------- | -------- | -------- |
E
ester.zhou 已提交
34 35 36 37
| value | number | Value of the chart. It can be dynamically changed.<br>Default value: **0**|
| 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**|
| 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**|
| colors | Array&lt;[ColorStop](#colorstop)&gt; | Colors of the chart. Colors can be set for individual segments.|
E
ester.zhou 已提交
38
| strokeWidth | Length | Stroke width of the chart.|
Z
zengyawen 已提交
39

E
ester.zhou 已提交
40 41 42 43 44 45
## ColorStop

Describes a gradient stop.

| Name     | Type            | Description                                                        |
| --------- | -------------------- | ------------------------------------------------------------ |
E
ester.zhou 已提交
46
| ColorStop | [[ResourceColor](ts-types.md#resourcecolor), number] | Type of the gradient stop. The first parameter indicates the color value. If it is set to a non-color value, the black color 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, which means that the color is not displayed.|
E
ester.zhou 已提交
47

Z
zengyawen 已提交
48 49 50 51

## Example


52 53
```ts
// xxx.ets
Z
zengyawen 已提交
54 55 56 57
@Entry
@Component
struct GaugeExample {
  build() {
E
ester.zhou 已提交
58 59 60 61 62 63 64 65 66 67
    Column({ space: 20 }) {
      // Use the default value of min and max, which is 0-100, and the default values of startAngle and endAngle, which are 0 and 360, respectively.
      // Set the current value to 75.
      Gauge({ value: 75 })
        .width(200).height(200)
        .colors([[0x317AF7, 1], [0x5BA854, 1], [0xE08C3A, 1], [0x9C554B, 1]])
      
      // Set the value parameter to 75 and the value attribute to 25. The attribute setting is used.
      Gauge({ value: 75 })
        .value(25) // If both the attribute and parameter are set, the parameter setting is used.
Z
zengyawen 已提交
68
        .width(200).height(200)
E
ester.zhou 已提交
69 70 71 72 73 74 75 76 77 78
        .colors([[0x317AF7, 1], [0x5BA854, 1], [0xE08C3A, 1], [0x9C554B, 1]])
      
      // A ring chart of 210 to 150 degrees
      Gauge({ value: 30, min: 0, max: 100 })
        .startAngle(210)
        .endAngle(150)
        .colors([[0x317AF7, 0.1], [0x5BA854, 0.2], [0xE08C3A, 0.3], [0x9C554B, 0.4]])
        .strokeWidth(20)
        .width(200)
        .height(200)
Z
zengyawen 已提交
79 80 81 82 83
    }.width('100%').margin({ top: 5 })
  }
}
```

E
ester.zhou 已提交
84
![gauge](figures/gauge-image.png)