在 OpenHarmony 中“使用图表”,通常有三种常见方式,取决于你使用的开发框架(ArkTS / ArkUI)以及图表复杂度。下面按最常用、最推荐的方式给你讲清楚。
使用 ohpm(OpenHarmony 包管理器):
ohpm install @ohos/echarts
如果使用旧版本 DevEco Studio,可能是:
npm install @ohos/echarts
// index.ets
import { ECharts } from '@ohos/echarts'
@Entry
@Component
struct ChartPage {
private chart: ECharts | null = null
build() {
Column() {
// 图表容器
Stack() {
// ECharts 组件
ECharts({
option: this.getOption(),
onInit: (chart) => {
this.chart = chart
}
})
.width('100%')
.height(300)
}
}
}
getOption() {
return {
xAxis: {
type: 'category',
data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri']
},
yAxis: {
type: 'value'
},
series: [{
data: [120, 200, 150, 80, 70],
type: 'bar'
}]
}
}
}
this.chart?.setOption({
series: [{
data: [90, 120, 130, 160, 200]
}]
})
Canvas(this.context)
.width('100%')
.height(200)
.onReady(() => {
const ctx = this.context
ctx.fillStyle = '#409EFF'
ctx.fillRect(20, 150, 30, 50)
ctx.fillRect(70, 100, 30, 100)
})
OpenHarmony 目前没有官方图表组件,主要依赖:
检查:
onInit 之后调用 setOption✅ ECharts OpenHarmony 版支持:
如果你愿意,可以告诉我:
我可以直接给你 可运行完整示例。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。