基础ArkTS组件:数据面板组件(图表),日期选择器组件(HarmonyOS学习第三课【3.5】)
创始人
2024-11-10 03:10:31
0

tuoz数据面板组件

DataPanel

数据面板组件,用于将多个数据占比情况使用占比图进行展示。

说明

该组件从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。

子组件

接口

DataPanel(options:{values: number[], max?: number, type?: DataPanelType})

从API version 9开始,该接口支持在ArkTS卡片中使用。

参数:

参数名

参数类型

必填

参数描述

values

number[]

数据值列表,最多包含9个数据,大于9个数据则取前9个数据。若数据值小于0则置为0。

max

number

- max大于0,表示数据的最大值。

- max小于等于0,max等于value数组各项的和,按比例显示。

默认值:100

type8+

DataPanelType

数据面板的类型(不支持动态修改)。

默认值:DataPanelType.Circle

属性

除支持通用属性外,还支持以下属性:

名称

类型

描述

closeEffect

boolean

关闭数据占比图表旋转动效。

默认值:false

DataPanelType枚举说明

从API version 9开始,该接口支持在ArkTS卡片中使用。

名称

描述

Line

线型数据面板。

Circle

环形数据面板。

示例

// xxx.ets @Entry @Component struct DataPanelExample {   public valueArr: number[] = [10, 10, 10, 10, 10, 10, 10, 10, 10]    build() {     Column({ space: 5 }) {       Row() {         Stack() {           DataPanel({ values: [30], 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('已使用98GB/128GB').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)     }.width('100%').margin({ top: 5 })   } }

 拓展

我们也可以使用网络上组件库进行图表引用这里我找到了一款比较简单的图表组件库,缺点是目前只有四个类型图表

使用Mc charts

McCharts 已经使用OpenHarmony三方库进行托管,你可以使用OpenHarmony提供的 ohpm 工具安装McCharts

ohpm install @mcui/mccharts

安装完成之后直接在项目当中进行引用即可

折线图

 import { McLineChart, Options } from '@mcui/mccharts'  @Entry @Component struct Index {   @State defOption: Options = new Options({       xAxis:{         data:['周一','周二','周三','周四','周五','周六','周日']       },       yAxis:{         name:'温度'       },       series:[         {           name:'最高气温',           data:[11, 11, 15, 13, 12, 130, 10]         }       ]   })   build() {     Row() {       McLineChart({         options: this.defOption       })     }     .height('50%')   } }

效果:

柱状图

 import { McBarChart, Options } from '@mcui/mccharts'  @Entry @Component struct Index {   @State defOption: Options = new Options({       xAxis:{         data:['周一','周二','周三','周四','周五','周六','周日']       },       yAxis:{         name:'温度'       },       series:[         {           name:'最高气温',           data:[11, 11, 15, 13, 12, 130, 10]         }       ]   })   build() {     Row() {       McBarChart({         options: this.defOption       })     }     .height('50%')   } }

 效果:

 饼图

 import { McPieChart, Options } from '@mcui/mccharts'  @Entry @Component struct Index {   @State defOption: Options = new Options({       series:[         {           data:[             {value:435, name:'直接访问'},             {value:310, name:'邮件营销'},             {value:234, name:'联盟广告'},             {value:135, name:'视频广告'},             {value:1548, name:'搜索引擎'}           ]         }       ]   })   build() {     Row() {       McPieChart({         options: this.defOption       })     }     .height('50%')   } }

效果:

散点图 

import { McPointChart, Options } from '@mcui/mccharts'  @Entry @Component struct Index {   @State defOption: Options = new Options({     series:[       {         name:'高气温',         data: [           {xVal: 40, yVal: 26, num: 17096869, name: '广州'},           {xVal: 20, yVal: 30, num: 17096869, name: '上海'},           {xVal: 30, yVal: 40, num: 17096869, name: '北京'},           {xVal: 10, yVal: 28, num: 17096869, name: '深圳'}         ]       }     ]   })   build() {     Row() {       McPointChart({         options: this.defOption       })     }     .height('50%')   } }

效果:

以上就是全部支持的四种图表以供大家进行参考。

日期选择器组件

DatePicker

子组件

接口

DatePicker(options?: {start?: Date, end?: Date, selected?: Date})

根据指定范围的Date创建可以选择日期的滑动选择器。

参数:

参数名

参数类型

必填

参数描述

start

Date

指定选择器的起始日期。

默认值:Date('1970-1-1')

end

Date

指定选择器的结束日期。

默认值:Date('2100-12-31')

selected

Date

设置选中项的日期。

默认值:当前系统日期

属性

除支持通用属性外,还支持以下属性:

名称

参数类型

描述

lunar

boolean

日期是否显示农历。

- true:展示农历。

- false:不展示农历。

默认值:false

事件

除支持通用事件外,还支持以下事件:

名称

功能描述

onChange(callback: (value: DatePickerResult) => void)

选择日期时触发该事件。

DatePickerResult对象说明

名称

参数类型

描述

year

number

选中日期的年。

month

number

选中日期的月(0~11),0表示1月,11表示12月。

day

number

选中日期的日。

 官方示例:

// xxx.ets @Entry @Component struct DatePickerExample {   @State isLunar: boolean = false   private selectedDate: Date = new Date('2021-08-08')    build() {     Column() {       Button('切换公历农历')         .margin({ top: 30, bottom: 30 })         .onClick(() => {           this.isLunar = !this.isLunar         })       DatePicker({         start: new Date('1970-1-1'),         end: new Date('2100-1-1'),         selected: this.selectedDate       })         .lunar(this.isLunar)         .onChange((value: DatePickerResult) => {           this.selectedDate.setFullYear(value.year, value.month, value.day)           console.info('select current date is: ' + JSON.stringify(value))         })      }.width('100%')   } }

相关内容

热门资讯

秒懂普及”珊瑚互娱房卡领取码“... 秒懂普及”珊瑚互娱房卡领取码“王者大厅房间卡怎么购买游戏中心打开微信,添加客服【113857776】...
秒懂教程!我买微信牛牛房卡链接... 斗牛是一款非常受欢迎的棋牌游戏,咨询房/卡添加微信:71319951许多玩家在游戏中会购买房卡来享受...
正规平台有哪些,怎么买斗牛房卡... 微信游戏中心:火神大厅房卡在哪里买打开微信,添加客服微信【88355042】,进入游戏中心或相关小程...
给大家讲解“购买斗牛房卡联系方... 起点大厅是一款非常受欢迎的棋牌游戏,咨询房/卡添加微信:160470940许多玩家在游戏中会购买房卡...
ia攻略/游戏推荐斗牛房卡出售... ia攻略/游戏推荐斗牛房卡出售长虹大厅/科技房卡多少钱一张Sa9Ix苹果iPhone 17手机即将进...
一分钟实测分享”时光互娱低价获... 第二也可以在游戏内商城:在游戏界面中找到 “微信金花,斗牛链接房卡”“商城”选项,选择房卡的购买选项...
一分钟了解!牛牛房卡游戏平台加... 微信游戏中心:乐乐堂房卡在哪里买打开微信,添加客服微信【88355042】,进入游戏中心或相关小程序...
正规平台有哪些,金花房卡是正规... 海航大厅是一款非常受欢迎的棋牌游戏,咨询房/卡添加微信:【3329006910】或QQ:332900...
秒懂教程!微信牛牛房间怎么弄,... 斗牛是一款非常受欢迎的棋牌游戏,咨询房/卡添加微信:66336574许多玩家在游戏中会购买房卡来享受...
终于找到“微信怎样开炸金花房间... 金花是一款非常受欢迎的棋牌游戏,咨询房/卡添加微信:160470940许多玩家在游戏中会购买房卡来享...
秒懂百科”海洋世界哪里有详细房... 哪里有详细房卡介绍是一款非常受欢迎的棋牌游戏,咨询房/卡添加微信:113857776许多玩家在游戏中...
头条推荐!游戏推荐斗牛房卡出售... 头条推荐!游戏推荐斗牛房卡出售新神兽/流樱大厅/微信链接房间卡怎么购买新神兽/流樱大厅是一款非常受欢...
推荐一款!怎么买斗牛房卡朱雀大... 微信游戏中心:朱雀大厅房卡在哪里买打开微信,添加客服微信【88355042】,进入游戏中心或相关小程...
玩家攻略,牛牛房卡代理荣耀联盟... 荣耀联盟是一款非常受欢迎的棋牌游戏,咨询房/卡添加微信:【3329006910】或QQ:332900...
IA解析/牛牛房卡游戏平台加盟... IA解析/牛牛房卡游戏平台加盟天道联盟/随意玩/微信链接房卡卖家联系方式Sa9Ix苹果iPhone ...
分享经验”百万牛哪里买低价获取... 分享经验”百万牛哪里买低价获取“新老夫子房卡充值游戏中心打开微信,添加客服【113857776】,进...
一分钟了解!金花房卡出售大众互... 今 日消息,大众互娱房卡添加微信33549083 苹果今日发布了 iOS 16.1 正式版更新,简单...
秒懂教程!微信买链接拼三张房卡... 拼三张是一款非常受欢迎的棋牌游戏,咨询房/卡添加微信:56001354许多玩家在游戏中会购买房卡来享...
房卡必备教程“购买金花房卡联系... 新琉璃金花是一款非常受欢迎的棋牌游戏,咨询房/卡添加微信:44346008许多玩家在游戏中会购买房卡...
1分秒分析”茄子娱乐房卡详细充... 第二也可以在游戏内商城:在游戏界面中找到 “微信金花,斗牛链接房卡”“商城”选项,选择房卡的购买选项...