1# DataPanel 2 3The **\<DataPanel>** component displays proportions in a chart. 4 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. 8 9 10 11 12## Child Components 13 14Not supported 15 16 17## APIs 18 19DataPanel(options:{values: number[], max?: number, type?: DataPanelType}) 20 21Since API version 9, this API is supported in ArkTS widgets. 22 23**Parameters** 24 25| Name | Type | Mandatory | Description| 26| ----------------- | -------- | ----- | -------- | 27| 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. A value less than 0 evaluates to the value **0**.| 28| 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**| 29| type<sup>8+</sup> | [DataPanelType](#datapaneltype) | No| Type of the data panel (dynamic modification is not supported).<br>Default value: **DataPanelType.Circle**| 30 31 32## DataPanelType 33 34Since API version 9, this API is supported in ArkTS widgets. 35 36| Name| Description| 37| -------| ------------ | 38| Line | Line data panel.| 39| Circle | Circle data panel.| 40 41 42## Attributes 43 44In addition to the [universal attributes](ts-universal-attributes-size.md), the following attributes are supported. 45 46 47| Name | Type| Description| 48| ------------- | ------- | -------- | 49| closeEffect | boolean | Whether to disable the rotation and shadow effects for the component.<br>Default value: **false**<br>**NOTE**<br> This attribute enables or disables the shadow effect only when **trackShadow** is not set.<br> The shadow effect enabled through this attribute is in the default style.| 50| valueColors<sup>10+</sup> | Array<[ResourceColor](ts-types.md#resourcecolor) \| [LinearGradient](#lineargradient10)> | Array of data segment colors. A value of the **ResourceColor** type indicates a solid color, and A value of the **LinearGradient** type indicates a color gradient.| 51| trackBackgroundColor<sup>10+</sup> | [ResourceColor](ts-types.md#resourcecolor) | Background color.<br>The value is in hexadecimal ARGB notation. The first two digits indicate opacity.<br>Default value: **'#08182431'**| 52| strokeWidth<sup>10+</sup> | [Length](ts-types.md#Length) | Stroke width of the border.<br>Default value: **24**<br>Unit: vp<br>**NOTE**<br>A value less than 0 evaluates to the default value.<br>This attribute does not take effect when the data panel type is **DataPanelType.Line**.| 53| trackShadow<sup>10+</sup> | [DataPanelShadowOptions](#datapanelshadowoptions10) | Shadow style.<br>**NOTE**<br>If this attribute is set to **null**, the shadow effect is disabled.| 54 55 56## DataPanelShadowOptions<sup>10+</sup> 57| Name | Type| Mandatory| Description| 58| ------------- | ------- | ---- | -------- | 59| radius | number \| [Resource](ts-types.md#resource)| No| Shadow blur radius.<br>Default value: **5**<br>Unit: vp<br>**NOTE**<br>A value less than or equal to 0 evaluates to the default value.| 60| colors | Array<[ResourceColor](ts-types.md#resourcecolor) \| [LinearGradient](#lineargradient10)> | No| Array of shadow colors for data segments.<br>Default value: same as the value of **valueColors**<br>**NOTE**<br>If the number of the set shadow colors is less than that of the data segments, the number of the displayed shadow colors is the same as the former.<br>If the number of the set shadow colors is greater than that of the data segments, the number of the displayed shadow colors is the same as the latter.| 61| offsetX | number \| [Resource](ts-types.md#resource)| No| Offset on the x-axis.<br>Default value: **5**<br>Unit: vp| 62| offsetY | number \| [Resource](ts-types.md#resource)| No| Offset on the y-axis.<br>Default value: **5**<br>Unit: vp| 63 64## LinearGradient<sup>10+</sup> 65 66Describes the linear gradient. 67 68LinearGradient(colorStops: ColorStop[]) 69 70| Name | Type| Mandatory| Description| 71| ------------- | ------- | ---- | -------- | 72| colorStops | [ColorStop](#colorstop10)[] | Yes| Gradient colors and color stops.| 73 74 75## ColorStop<sup>10+</sup> 76 77Describes the gradient color stop. 78 79| Name | Type| Mandatory| Description| 80| ------------- | ------- | ---- | -------- | 81| color | [ResourceColor](ts-types.md#resourcecolor) | Yes| Color value.| 82| offset | [Length](ts-types.md#Length) | Yes| Gradient color stop (proportion value between 0 and 1). A value less than 0 evaluates to the value **0**. A value greater than 1 evaluates to the value **1**.| 83 84 85 86## Example 87 88### Example 1 89 90```ts 91// xxx.ets 92@Entry 93@Component 94struct DataPanelExample { 95 public valueArr: number[] = [10, 10, 10, 10, 10, 10, 10, 10, 10] 96 97 build() { 98 Column({ space: 5 }) { 99 Row() { 100 Stack() { 101 DataPanel({ values: [25], max: 100, type: DataPanelType.Circle }).width(168).height(168) 102 Column() { 103 Text('30').fontSize(35).fontColor('#182431') 104 Text('1.0.0').fontSize(9.33).lineHeight(12.83).fontWeight(500).opacity(0.6) 105 } 106 107 Text('%') 108 .fontSize(9.33) 109 .lineHeight(12.83) 110 .fontWeight(500) 111 .opacity(0.6) 112 .position({ x: 104.42, y: 78.17 }) 113 }.margin({ right: 44 }) 114 115 Stack() { 116 DataPanel({ values: [50, 12, 8, 5], max: 100, type: DataPanelType.Circle }).width(168).height(168) 117 Column() { 118 Text('75').fontSize(35).fontColor('#182431') 119 Text('Used: 98 GB/128 GB') .fontSize(8.17).lineHeight(11.08).fontWeight(500).opacity(0.6) 120 } 121 122 Text('%') 123 .fontSize(9.33) 124 .lineHeight(12.83) 125 .fontWeight(500) 126 .opacity(0.6) 127 .position({ x: 104.42, y: 78.17 }) 128 } 129 }.margin({ bottom: 59 }) 130 131 DataPanel({ values: this.valueArr, max: 100, type: DataPanelType.Line }).width(300).height(10) 132 }.width('100%').margin({ top: 5 }) 133 } 134} 135``` 136 137 138 139### Example 2 140 141```ts 142// xxx.ets 143@Entry 144@Component 145struct LinearGradientDataPanelExample { 146 public values1: number[] = [20, 20, 20, 20] 147 public color1: LinearGradient = new LinearGradient([{ color: "#65EEC9A3", offset: 0 }, { color: "#FFEF629F", offset: 1 }]) 148 public color2: LinearGradient = new LinearGradient([{ color: "#FF67F9D4", offset: 0 }, { color: "#FFFF9554", offset: 1 }]) 149 public colorShadow1: LinearGradient = new LinearGradient([{ color: "#65EEC9A3", offset: 0 }, { color: "#65EF629F", offset: 1 }]) 150 public colorShadow2: LinearGradient = new LinearGradient([{ color: "#65e26709", offset: 0 }, { color: "#65efbd08", offset: 1 }]) 151 public colorShadow3: LinearGradient = new LinearGradient([{ color: "#6572B513", offset: 0 }, { color: "#6508efa6", offset: 1 }]) 152 public colorShadow4: LinearGradient = new LinearGradient([{ color: "#65ed08f5", offset: 0 }, { color: "#65ef0849", offset: 1 }]) 153 @State color3: string = '#00FF00' 154 @State color4: string = '#20FF0000' 155 @State bgColor: string = '#08182431' 156 @State offsetX: number = 15 157 @State offsetY: number = 15 158 @State radius: number = 5 159 @State colorArray: Array<LinearGradient | ResourceColor> = [this.color1, this.color2, this.color3, this.color4] 160 @State shadowColorArray: Array<LinearGradient | ResourceColor> = [this.colorShadow1, this.colorShadow2, this.colorShadow3, this.colorShadow4] 161 162 build() { 163 Column({ space: 5 }) { 164 Text('LinearGradient').fontSize(9).fontColor(0xCCCCCC).textAlign(TextAlign.Start).width('100%').margin({ top: 20, left: 20}) 165 DataPanel({ values: this.values1, max: 100, type: DataPanelType.Circle }) 166 .width(300) 167 .height(300) 168 .valueColors(this.colorArray) 169 .trackShadow({ 170 radius: this.radius, 171 colors: this.shadowColorArray, 172 offsetX: this.offsetX, 173 offsetY: this.offsetY 174 }) 175 .strokeWidth(30) 176 .trackBackgroundColor(this.bgColor) 177 }.width('100%').margin({ top: 5 }) 178 } 179} 180``` 181 182 183