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

封装一个echarts的组件

父组件页面

<yyjlchartv-if="showyyjl"chartId="yyjllLine":sourceData="sourceDatayyjl":options="optionsyyjl"></yyjlchart>
components: {LineEcharts,yyjlchart: () => import("../yyjlchart"),},data() {return {showyyjl: false,optionsyyjl: {grid: {left: "3%",right: "3%",bottom: "10%",top: "1%",},},
},methods: {async yyjlmap() {this.showyyjl = false;xxx调接口
数据返回后this.sourceDatayyjl.xdata = res.data.xData;this.sourceDatayyjl.ydata = res.data.medicateNames.reverse();this.sourceDatayyjl.result[0].data = res.data.yData.reverse();this.showyyjl = true;}

猪脚登场

<template><div :id="chartId" class="box"></div>
</template>
<script>
export default {props: {// 品种下拉项chartId: {type: String,default: "",},// 数据源sourceData: {type: Object,default: () => {return {ydata: [],xdata: [],result: [],};},},// 特殊配置项options: {type: Object,default: () => {},},// 图表颜色colorList: {type: Array,default: () => [],},// 是否显示tooltipshowTooltip: {type: Boolean,default: true,},// 是否显示X轴和Y轴showXorY: {type: Boolean,default: true,},xyLineColor: {type: Array,default: () => ["#E5E6E8", "#86909C"],},},data() {return {chartInstance: null,};},mounted() {this.initChart();},methods: {initChart(data) {this.chartInstance = this.$echarts.init(document.getElementById(this.chartId));let that = this;var hours = this.sourceData.ydatavar days = this.sourceData.xdatavar data = []var data1 = []let option = {// 放你的option };this.chartInstance.setOption(option);window.addEventListener("resize", () => {this.chartInstance.resize();});const chartObserver = new ResizeObserver(() => {this.chartInstance.resize();});// 监听当前图表容器大小变化的时候resizechartObserver.observe(document.getElementById(this.chartId));},fontSize(res) {let clientWidth =window.innerWidth ||document.documentElement.clientWidth ||document.body.clientWidth;if (!clientWidth) return;// 此处的1920 为设计稿的宽度let fontSize = clientWidth / 1920;return res * fontSize;},},
};
</script><style lang="scss" scoped>
.box {width: 100%;height: 100%;
}
</style>
option = {grid: {left: '3%',right: '4%',bottom: '3%',containLabel: true},xAxis: {type: 'category',data: ['10-11', '10-12', '10-13', '10-14', '10-15', '10-16', '10-17', '10-18', '10-19', '10-20', '10-21', '10-22', '10-23', '10-24', '10-25', '10-26'],boundaryGap: true  // 让点之间有间隙},yAxis: {type: 'category',data: ['三维散', '复合多维', '硅烷', '硅烷1', '硅烷2'],},visualMap: {orient: 'horizontal',left: 'center',bottom: '0%',type: "piecewise",textStyle: {color: '#86909C' // 设置文字颜色},itemWidth: 25,itemHeight: 15,symbol: "square",inRange: {symbol: 'rect', // 设置图例为方形},show: false, // 显示 visualMapmin: 1,max: 50,// backgroundColor: function(params) {//     console.log(params);//       // 根据 y 轴类别来动态设置颜色//       if (params.value[1] === '三维散') return '#9b59b6';  // 紫色//       if (params.value[1] === '复合多维') return '#e67e22'; // 橙色//       if (params.value[1] === '硅烷') return '#1abc9c'; // 绿色//       return '#1abc9c';//     }},series: [{name: '热力图',type: 'heatmap',data: [// 数据格式 [x, y, value][0, 0, 40], [1, 0, 70], [2, 0, 50], [3, 0, 30], [4, 0, 0], [5, 0, 80], [6, 0, 60], [7, 0, 40], [8, 0, 50], [9, 0, 70], [10, 0, 60], [11, 0, 80], [12, 0, 50], [13, 0, 70], [14, 0, 40], [15, 0, 60],[0, 1, 60], [1, 1, 40], [2, 1, 90], [3, 1, 80], [4, 1, 60], [5, 1, 70], [6, 1, 50], [7, 1, 40], [8, 1, 80], [9, 1, 50], [10, 1, 60], [11, 1, 40], [12, 1, 60], [13, 1, 90], [14, 1, 70], [15, 1, 80],[0, 2, 30], [1, 2, 50], [2, 2, 60], [3, 2, 40], [4, 2, 70], [5, 2, 60], [6, 2, 80], [7, 2, 50], [8, 2, 40], [9, 2, 90], [10, 2, 70], [11, 2, 50], [12, 2, 60], [13, 2, 80], [14, 2, 50], [15, 2, 30]],label: {show: true,color: '#fff'},// emphasis: {//   itemStyle: {//     shadowBlur: 10,//     backgroundColor:'#000',//     shadowColor: function(params) {//       // 根据 y 轴类别来动态设置颜色//       if (params.value[1] === '三维散') return '#9b59b6';  // 紫色//       if (params.value[1] === '复合多维') return '#e67e22'; // 橙色//       if (params.value[1] === '硅烷') return '#1abc9c'; // 绿色//       return '#1abc9c';//     }//   }// },itemStyle: {normal: {borderColor: "#ffffff",borderWidth: "5",color: function(params) {var colorList = ["#3aa0ff", "#f44336", "#ffc107"];console.log(params);params.value[1]==0if (params.value[1] === 0) return '#9b59b6';  // 紫色if (params.value[1] === 1) return '#e67e22'; // 橙色if (params.value[1] === 2) return '#1abc9c'; // 绿色}}},}]
};
http://www.lryc.cn/news/540593.html

相关文章:

  • 计算机网络安全之一:网络安全概述
  • Linux 性能调优简单指南
  • 第十一章: vue2-3 生命周期
  • 【算法基础】--前缀和
  • 输入搜索、分组展示选项、下拉选取,el-select 实现:即输入关键字检索,返回分组选项,选取跳转到相应内容页 —— VUE 项目-全局模糊检索
  • Web入侵实战分析-常见web攻击类应急处置实验2
  • DeepSeek:AI商业化的新引擎与未来蓝图
  • 从零开始学习PX4源码9(部署px4源码到gitee)
  • wps中zotero插件消失,解决每次都需要重新开问题
  • 【Python 语法】collections 模块的字典类 defaultdict
  • 《论系统需求分析方法》写作心得 - 系统分析师
  • Jupyter里面的manim编程学习
  • Python之装饰器二 带参数的装饰器
  • rk3588/3576板端编译程序无法运行视频推理
  • 静态库与动态库区别
  • 鸿蒙-Canvas-图片滑动验证
  • Python应用算法之贪心算法理解和实践
  • 网络运维学习笔记 017HCIA-Datacom综合实验01
  • C++(17):为optional类型构造对象
  • Maven导入hutool依赖报错-java: 无法访问cn.hutool.core.io.IORuntimeException 解决办法
  • Simulink库浏览器中有大量的模型组件工具箱介绍
  • 从0到1:固件分析
  • 模电知识点总结(6)
  • 【Java学习】多态
  • Oracle 深入理解Lock和Latch ,解析访问数据块全流程
  • 什么是事务?并发事务引发的问题?什么是MVCC?
  • 【JavaEE进阶】MyBatis通过注解实现增删改查
  • Uptime Kuma实现业务接口自定义逻辑监控
  • 基于 JavaWeb 的 Spring Boot 调查问卷管理系统设计和实现(源码+文档+部署讲解)
  • 新手小白学习棒球规则·棒球1号位