如何实现类似运动健康渐变色热量环效果

如何实现类似运动健康渐变色热量环效果

HarmonyOS
2024-01-30 23:21:14
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
liuhuzhou

1. 使用DataPanel实现环形图形,通过valueColors属性设置数据段颜色和trackShadow属性设置投影样式来模拟颜色渐变效果。

2. 使用Stack叠加多个圆环叠加。

3. 使用rotate属性进行图形旋转。

实现效果:

参考代码:

@Entry 
@Component 
struct LinearGradientDataPanelExample { 
  public values1: number[] = [80]; 
  color1: LinearGradient = new LinearGradient([{ color: "#F22424", offset: 0 }, { color: "#FF9933", offset: 1 }]); 
  color2: LinearGradient = new LinearGradient([{ color: "#FFAE0D", offset: 0 }, { color: "#FFD814", offset: 1 }]); 
  color3: LinearGradient = new LinearGradient([{ color: "#266EFF", offset: 0 }, { color: "#4DC3FF", offset: 1 }]); 
  @State bgColor: string = '#08182431'; 
  @State offsetX: number = 15; 
  @State offsetY: number = 15; 
  @State radius: number = 5; 
  @State colorArray1: Array<LinearGradient | ResourceColor> = [this.color1]; 
  @State colorArray2: Array<LinearGradient | ResourceColor> = [this.color2]; 
  @State colorArray3: Array<LinearGradient | ResourceColor> = [this.color3]; 
 
  build() { 
    Column({ space: 5 }) { 
      Stack() { 
        DataPanel({ values: this.values1, max: 100, type: DataPanelType.Circle }) 
          .width(400) 
          .height(400) 
          .valueColors(this.colorArray1) 
          .trackShadow({ 
            radius: this.radius, 
            colors: this.colorArray1, 
            offsetX: this.offsetX, 
            offsetY: this.offsetY 
          }) 
          .strokeWidth(40) 
          .trackBackgroundColor(this.bgColor) 
        DataPanel({ values: this.values1, max: 100, type: DataPanelType.Circle }) 
          .width(300) 
          .height(300) 
          .valueColors(this.colorArray2) 
          .trackShadow({ 
            radius: this.radius, 
            colors: this.colorArray2, 
            offsetX: this.offsetX, 
            offsetY: this.offsetY 
          }) 
          .strokeWidth(40) 
          .trackBackgroundColor(this.bgColor) 
        DataPanel({ values: this.values1, max: 100, type: DataPanelType.Circle }) 
          .width(200) 
          .height(200) 
          .valueColors(this.colorArray3) 
          .trackShadow({ 
            radius: this.radius, 
            colors: this.colorArray3, 
            offsetX: this.offsetX, 
            offsetY: this.offsetY 
          }) 
          .strokeWidth(40) 
          .trackBackgroundColor(this.bgColor) 
      } 
      .rotate({ 
        x: 0, 
        y: 0, 
        z: 1, 
        centerX: '50%', 
        centerY: '50%', 
        angle: 215 
      }) 
    }.width('100%').margin({ top: 5 }) 
  } 
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.
  • 59.
  • 60.
  • 61.
  • 62.
  • 63.
  • 64.
  • 65.
  • 66.
分享
微博
QQ
微信
回复
2024-02-01 11:34:31
相关问题
HarmonyOS 如何实现文字渐变色效果
893浏览 • 1回复 待解决
组件如何实现渐变色
2560浏览 • 1回复 待解决
HarmonyOS 字体怎么实现渐变色
507浏览 • 1回复 待解决
HarmonyOS Canvas设置渐变色没有效果
747浏览 • 1回复 待解决
Progress进度条如何实现渐变色
1748浏览 • 1回复 待解决
HarmonyOS linearGradient渐变色问题
497浏览 • 1回复 待解决
HarmonyOS 文本渐变色怎么处理
618浏览 • 1回复 待解决
HarmonyOS 环状渐变色进度条
740浏览 • 1回复 待解决
Rect组件支持渐变色填充吗?
847浏览 • 1回复 待解决
如何设置边框的颜色为渐变色
1156浏览 • 1回复 待解决
HarmonyOS 组件背景是否支持渐变色
932浏览 • 1回复 待解决
HarmonyOS 运动健康kit无法授权
836浏览 • 1回复 待解决
HarmonyOS 如何实现滚动渐变效果
998浏览 • 1回复 待解决
如何实现顶部渐变遮罩效果
1092浏览 • 1回复 待解决
HarmonyOS 有没有类似渐变效果
594浏览 • 1回复 待解决
渐变动画效果如何实现
212浏览 • 0回复 待解决
HarmonyOS 渐变遮罩效果如何实现
856浏览 • 1回复 待解决