当前位置: 首页 > java >正文

echarts饼图中心呈现一张图片,并且能动态旋转的效果react组件

实现效果:

父组件:

import React from 'react'
import styles from './style.less'
import GaugeChart from './GaugeChart';export default function index() {return (<div><div className={styles.bg} ></div><div style={{ width: '500px', height: '500px' }}><GaugeChart value={65.23} title="数据" /></div></div>)
}

子组件:

import React, { useEffect, useRef } from 'react';
import * as echarts from "echarts";
import totalBg from '@assets/images/icon1@2x.png';const MyChart = () => {const chartRef = useRef(null);const intervalIdRef = useRef(null); // 使用ref保存intervalIduseEffect(() => {const myChart = echarts.init(chartRef.current);const pieOption = {series: [{type: 'pie',radius: ['40%', '70%'],center: ['50%', '50%'],data: [{ value: 335, name: '直接访问' },{ value: 310, name: '邮件营销' },{ value: 234, name: '联盟广告' },{ value: 135, name: '视频广告' },{ value: 1548, name: '搜索引擎' }],itemStyle: {emphasis: {shadowBlur: 10,shadowOffsetX: 0,shadowColor: 'rgba(0, 0, 0, 0.5)'}}}]};myChart.setOption(pieOption);const timer = setTimeout(() => {const earthOption = {graphic: [{type: 'group',left: 'center',top: 'center',rotation: 0,rotationX: 0,rotationY: 0,children: [{type: 'image',style: {image: totalBg,width: 60,height: 60,shadowBlur: 20,shadowColor: 'rgba(0, 0, 0, 0.5)'},z: 10,zlevel: 10}]}]};myChart.setOption(earthOption);let rotationX = 0;let rotationY = 0;let rotationZ = 0;intervalIdRef.current = setInterval(() => {rotationX += 0.5;rotationY += 1;rotationZ += 0.5;// 检查图表实例是否已被销毁if (!myChart.isDisposed()) {myChart.setOption({graphic: [{type: 'group',left: 'center',top: 'center',rotation: rotationZ,rotationX: rotationX,rotationY: rotationY,children: [{type: 'image',style: {image: totalBg,width: 60,height: 60,shadowBlur: 20,shadowColor: 'rgba(0, 0, 0, 0.5)'},z: 10,zlevel: 10}]}]});}}, 100);}, 1000);return () => {// 清除定时器和超时clearTimeout(timer);if (intervalIdRef.current) {clearInterval(intervalIdRef.current);}// 销毁图表实例myChart.dispose();};}, []);return (<div ref={chartRef} style={{ width: '400px', height: '400px', perspective: '1000px' }} />);
};export default MyChart;

http://www.xdnf.cn/news/207.html

相关文章:

  • 天梯赛数据结构合集
  • 51单片机实验三:数码管动态显示
  • Oracle 19c新特性:OCP认证考试与职业跃迁的关键?
  • 如何选择适合您的过程控制器?
  • VSCODE插值表达式失效问题
  • 4.18学习总结
  • CNN与VGG16的关系:从基础到经典模型的通俗解析
  • 【前沿】成像“跨界”测量——扫焦光场成像
  • 【AI部署】腾讯云GPU -—SadTalker的AI数字人访问web服务—未来之窗超算中心
  • 2025mathorcup妈妈杯数学建模挑战赛C题:汽车风阻预测,详细思路,模型,代码更新中
  • 专精特新政策推动,B端UI设计如何赋能中小企业创新发展?
  • 使用VHDL语言实现TXT文件的读写操作
  • 【LeetCode】大厂面试算法真题回忆(61)--组装新的数组
  • 7.Rust+Axum:打造高效 RESTful API 的最佳实践
  • FastGPT安装前,系统环境准备工作?
  • AI Agent系列(十) -Data Agent(数据分析智能体)开源资源汇总
  • Qt QTimer 详解与使用指南
  • PHP最新好看UI个人引导页网页源码
  • Flash存储器(二):SPI NAND Flash与SPI NOR Flash
  • 基于linux 设置无线网卡Monitor模式 sniffer抓包
  • 经济指标学习(二)
  • 神经网络优化 - 小批量梯度下降之批量大小的选择
  • ChatGPT-o3辅助学术写作的关键词和引言效果如何?
  • 鸿蒙NEXT开发键值型数据工具类(ArkTs)
  • PyTorch快速入门
  • 《软件设计师》复习笔记(12.1)——范围管理、进度管理
  • 全栈架构设计图
  • 浅谈验证(Verification)和确认(Validation)
  • 基于C++(MFC)图形编辑界面工具
  • 数据驱动、精准协同:高端装备制造业三位一体生产管控体系构建