ts-basic-components-datapanel.md 2.7 KB
Newer Older
Z
zengyawen 已提交
1
# DataPanel
Z
zengyawen 已提交
2

3
The **\<DataPanel>** component displays proportions in a chart.
Z
zengyawen 已提交
4

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

Z
zengyawen 已提交
9

Z
zengyawen 已提交
10

Z
zengyawen 已提交
11 12

## Child Components
Z
zengyawen 已提交
13

14
Not supported
Z
zengyawen 已提交
15

Z
zengyawen 已提交
16 17 18

## APIs

E
ester.zhou 已提交
19
DataPanel(options:{values: number[], max?: number, type?: DataPanelType})
Z
zengyawen 已提交
20

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

E
ester.zhou 已提交
23 24
| Name           | Type  | Mandatory | Description|
| ----------------- | -------- | ----- | -------- |
E
ester.zhou 已提交
25
| values            | number[]   | Yes   | Data value list. A maximum of nine values are supported. If more than nine values are set, only the first nine ones are used. If the value is less than 0, the value 0 is used.|
E
ester.zhou 已提交
26
| max               | number     | No   |   - When set to a value greater than 0, this parameter indicates the maximum value in the **values** list.<br>- When set to a value equal to or smaller than 0, this parameter indicates the sum of values in the **values** list. The values are displayed in proportion.<br>Default value: **100**|
E
ester.zhou 已提交
27
| type<sup>8+</sup> | [DataPanelType](#datapaneltype) | No| Type of the data panel.<br>Default value: **DataPanelType.Circle**|
Z
zengyawen 已提交
28 29


E
ester.zhou 已提交
30 31
## DataPanelType
| Name| Description|
E
ester.zhou 已提交
32
| -------| ------------ |
E
ester.zhou 已提交
33
| Line   | Line data panel.|
E
ester.zhou 已提交
34
| Circle | Circle data panel.|
Z
zengyawen 已提交
35 36


E
ester.zhou 已提交
37
## Example
Z
zengyawen 已提交
38

39 40
```ts
// xxx.ets
Z
zengyawen 已提交
41 42 43
@Entry
@Component
struct DataPanelExample {
E
ester.zhou 已提交
44
  public valueArr: number[] = [10, 10, 10, 10, 10, 10, 10, 10, 10]
Z
zengyawen 已提交
45 46 47

  build() {
    Column({ space: 5 }) {
E
ester.zhou 已提交
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
      Row() {
        Stack() {
          DataPanel({ values: [25], max: 100, type: DataPanelType.Circle }).width(168).height(168)
          Column() {
            Text('30').fontSize(35).fontColor('#182431')
            Text('1.0.0').fontSize(9.33).lineHeight(12.83).fontWeight(500).opacity(0.6)
          }

          Text('%')
            .fontSize(9.33)
            .lineHeight(12.83)
            .fontWeight(500)
            .opacity(0.6)
            .position({ x: 104.42, y: 78.17 })
        }.margin({ right: 44 })

        Stack() {
          DataPanel({ values: [50, 12, 8, 5], max: 100, type: DataPanelType.Circle }).width(168).height(168)
          Column() {
            Text('75').fontSize(35).fontColor('#182431')
            Text('Used: 98 GB/128 GB') .fontSize(8.17).lineHeight(11.08).fontWeight(500).opacity(0.6)
          }

          Text('%')
            .fontSize(9.33)
            .lineHeight(12.83)
            .fontWeight(500)
            .opacity(0.6)
            .position({ x: 104.42, y: 78.17 })
        }
      }.margin({ bottom: 59 })

      DataPanel({ values: this.valueArr, max: 100, type: DataPanelType.Line }).width(300).height(10)
Z
zengyawen 已提交
81 82 83 84 85
    }.width('100%').margin({ top: 5 })
  }
}
```

E
ester.zhou 已提交
86
![dataPanel](figures/dataPanel.PNG)