echarts 矩阵树图treemap

news/2024/10/26 9:50:13/

1、根据value值渲染各个数据的占用面积;
2、根据percentValue值判断各个数据的颜色展示;
3、根据value值判断各个数据的标签名称字号的大小(占用面积越大字号越大,占用面积越小字号越小);

直接上代码:

html:

 <divid="ETFBroadBased"style="width: 100%;height: 450px;"></div>

js:

javascript">data () {return {chart: null,chartData: [{"value": "1637.05","name": "啊啊啊","percentValue": "-1.89","chg1w": "-32.06","chg2w": "-25.88","chg1m": "38.15","chg3m": "230.76","chg6m": null,"chgYtd": "508.16","mkv": "1637.05"},{"value": "10321.66","name": "不不不","percentValue": "-0.60","chg1w": "-63.95","chg2w": "258.40","chg1m": "768.35","chg3m": "468.38","chg6m": null,"chgYtd": "4159.72","mkv": "10321.66"},{"value": "1625.86","name": "踩踩踩","percentValue": "-2.43","chg1w": "-39.82","chg2w": "-62.44","chg1m": "112.42","chg3m": "134.54","chg6m": null,"chgYtd": "642.95","mkv": "1625.86"},{"value": "1427.23","name": "点点点","percentValue": "-4.21","chg1w": "-59.29","chg2w": "-87.24","chg1m": "223.69","chg3m": "412.39","chg6m": null,"chgYtd": "853.74","mkv": "1427.23"},{"value": "1919.21","name": "呃呃呃","percentValue": "-1.95","chg1w": "-38.41","chg2w": "551.01","chg1m": "545.03","chg3m": "670.93","chg6m": null,"chgYtd": "903.60","mkv": "1919.21"},],}
},
mounted () {this.$nextTick(() => {this.initTreeMapChart()})
},
methods: { initTreeMapChart() {var chartDom = document.getElementById('ETFBroadBased');this.chart = echarts.init(chartDom);this.addColors(this.chartData)let option = {tooltip: {trigger: 'item',backgroundColor: 'rgba( 0, 0, 0,0.7)',borderColor: 'rgba( 0, 0, 0,0.7)',formatter: function(params) {let str = params.name + '</br>'str = `<div style='color: #fff;'><div>${str}</div><div style="display: flex;justify-content: space-between;"><div>近1周:</div><div>${params.data.chg1w || '-'}亿</div></div><div style="display: flex;justify-content: space-between;"><div>近2周:</div><div>${params.data.chg2w || '-'}亿</div></div><div style="display: flex;justify-content: space-between;"><div>近1月:</div><div>${params.data.chg1m || '-'}亿</div></div><div style="display: flex;justify-content: space-between;"><div>近3月:</div><div>${params.data.chg3m || '-'}亿</div></div><div style="display: flex;justify-content: space-between;"><div>YTD:</div><div>${params.data.chgYtd || '-'}亿</div></div><div style="display: flex;justify-content: space-between;"><div>规模合计:</div><div>${params.data.mkv || '-'}亿</div></div></div>`return str;}},series: [{type: 'treemap',left: '0%',top: '0%',right: '0%',bottom: '0%',roam: false, // 是否开启拖拽漫游(移动和缩放)nodeClick: false, // 点击节点后的行为,false无反应breadcrumb: {show: false},label: {show: true,align: 'center',verticalAlign: 'middle',position: 'bottom',offset: [0, -15],color: '#fff',// formatter: function(params) {//   // console.log(params,'params--');//   // let area = Number(params.data.value) || 0//   // that.setSizeName = (area / 100) > 100 ? 30 : ((area / 100) < 100) && ((area / 100) >= 50) ? 16 : 24 // 根据面积大小设置字体大小//   // that.setSizeValue = (area / 100) > 100 ? 20 : ((area / 100) < 100) && ((area / 100) >= 50) ? 12 : 10 // 根据面积大小设置字体大小//   // console.log(that.setSizeName,that.setSizeValue,'9999999');//   // return `{name|${params.data.name}}` + '\n' + `{percentValue|${params.data.percentValue}%}`//   // return params.data.name  + '\n' + params.data.percentValue + '%'// },// rich: {//   name: {//     // color: '#fff',//     // fontSize: 13,//     // fontSize: that.setSizeName,//   },//   percentValue: {//     // color: '#fff',//     // fontSize: 10,//     // fontSize: that.setSizeValue,//   }// },},itemStyle: {show: true,borderWidth: 1,borderColor: '#fff',emphasis: {label: {show: true}}},data: this.chartData,}],}this.chart.setOption(option,true);},addColors(arr) {// 根据值的大小添加对应的颜色值(根据实际情况可修改)arr.map((item) => {if (Number(item.percentValue) > 4) {item.itemStyle = {color: '#ac1116',}} else if (Number(item.percentValue) > 2 && Number(item.percentValue) <= 4) {item.itemStyle = {color: '#7e1014',}} else if (Number(item.percentValue) >= 0 && Number(item.percentValue) <= 2) {item.itemStyle = {color: '#5e0d11',}} else if (Number(item.percentValue) < 0 && Number(item.percentValue) >= -2) {item.itemStyle = {color: '#094320',}} else if (Number(item.percentValue) < -2 && Number(item.percentValue) >= -4) {item.itemStyle = {color: '#095d29',}} else if (Number(item.percentValue) < -4 ) {item.itemStyle = {color: '#107f3a',}}})// 根据占用面积大小添加对应的字号(根据实际情况可修改)arr.map((item) => {if (Number(item.value) / 100 > 100) {item.label = {lineHeight: 25,formatter: function(params) {return `{name|${params.data.name}}` + '\n' + `{percentValue|${params.data.percentValue}%}`},rich: {name: {fontSize: 28,},percentValue: {fontSize: 16,}},}} else if (Number(item.value) / 100 > 80 && Number(item.value) / 100 <= 100 ) {item.label = {lineHeight: 25,formatter: function(params) {return `{name|${params.data.name}}` + '\n' + `{percentValue|${params.data.percentValue}%}`},rich: {name: {fontSize: 26,},percentValue: {fontSize: 14,}},}} else if (Number(item.value) / 100 > 60 && Number(item.value) / 100 <= 80 ) {item.label = {lineHeight: 25,formatter: function(params) {return `{name|${params.data.name}}` + '\n' + `{percentValue|${params.data.percentValue}%}`},rich: {name: {fontSize: 24,},percentValue: {fontSize: 12,}},}} else if (Number(item.value) / 100 > 40 && Number(item.value) / 100 <= 60 ) {item.label = {lineHeight: 25,formatter: function(params) {return `{name|${params.data.name}}` + '\n' + `{percentValue|${params.data.percentValue}%}`},rich: {name: {fontSize: 22,},percentValue: {fontSize: 12,}},}} else if (Number(item.value) / 100 > 20 && Number(item.value) / 100 <= 40 ) {item.label = {lineHeight: 20,formatter: function(params) {return `{name|${params.data.name}}` + '\n' + `{percentValue|${params.data.percentValue}%}`},rich: {name: {fontSize: 20,},percentValue: {fontSize: 12,}},}} else if (Number(item.value) / 100 > 15 && Number(item.value) / 100 <= 20 ) {item.label = {lineHeight: 20,formatter: function(params) {return `{name|${params.data.name}}` + '\n' + `{percentValue|${params.data.percentValue}%}`},rich: {name: {fontSize: 18,},percentValue: {fontSize: 12,}},}} else if (Number(item.value) / 100 > 10 && Number(item.value) / 100 <= 15 ) {item.label = {lineHeight: 18,formatter: function(params) {return `{name|${params.data.name}}` + '\n' + `{percentValue|${params.data.percentValue}%}`},rich: {name: {fontSize: 16,},percentValue: {fontSize: 12,}},}} else if (Number(item.value) / 100 > 5 && Number(item.value) / 100 <= 10 ) {item.label = {lineHeight: 18,formatter: function(params) {return `{name|${params.data.name}}` + '\n' + `{percentValue|${params.data.percentValue}%}`},rich: {name: {fontSize: 14,},percentValue: {fontSize: 10,}},}} else if (Number(item.value) / 100 > 0 && Number(item.value) / 100 <= 5 ) {item.label = {lineHeight: 10,formatter: function(params) {return `{name|${params.data.name}}` + '\n' + `{percentValue|${params.data.percentValue}%}`},rich: {name: {fontSize: 10,},percentValue: {fontSize: 8,}},}}})},}

效果图如下,仅供参考(效果图数据和以上数据不一样哈):
在这里插入图片描述


http://www.ppmy.cn/news/1542076.html

相关文章

纯血鸿蒙的未来前景

纯血鸿蒙作为华为推出的新一代操作系统&#xff0c;其未来的发展前景可以从多个方面进行分析。 从技术角度来看&#xff0c;纯血鸿蒙实现了全面的自主可控。它去除了传统的AOSP代码&#xff0c;仅支持鸿蒙内核和鸿蒙系统的应用&#xff0c;不再兼容安卓OS。这种技术上的独立性…

使用单链表实现集合操作:并集、交集与差集

✅作者简介&#xff1a;2022年博客新星 第八。热爱国学的Java后端开发者&#xff0c;修心和技术同步精进。 &#x1f34e;个人主页&#xff1a;Java Fans的博客 &#x1f34a;个人信条&#xff1a;不迁怒&#xff0c;不贰过。小知识&#xff0c;大智慧。 &#x1f49e;当前专栏…

道路车辆功能安全 ISO 26262标准(8-8)—支持过程

写在前面 本系列文章主要讲解道路车辆功能安全ISO26262标准的相关知识&#xff0c;希望能帮助更多的同学认识和了解功能安全标准。 若有相关问题&#xff0c;欢迎评论沟通&#xff0c;共同进步。(*^▽^*) 1. 道路车辆功能安全ISO 26262标准 8. ISO 26262-8 支持过程 十、论…

青少年编程与数学 02-002 Sql Server 数据库应用 05课题、结构化查询语言 SQL

青少年编程与数学 02-002 Sql Server 数据库应用 05课题、结构化查询语言 SQL 课题摘要:一、结构化查询语言&#xff08;SQL&#xff09;二、SQL分类三、Transact-SQL四、Transact-SQL的语法约定五、标识符标识符的分类&#xff1a;标识符的规则&#xff1a;特殊符号的意义&…

【深度解析】WRF-LES与PALM微尺度气象大涡模拟

针对微尺度气象的复杂性&#xff0c;大涡模拟&#xff08;LES&#xff09;提供了一种无可比拟的解决方案。微尺度气象学涉及对小范围内的大气过程进行精确模拟&#xff0c;这些过程往往与天气模式、地形影响和人为因素如城市布局紧密相关。在这种规模上&#xff0c;传统的气象模…

NVIDIA发布Nemotron-70B-Instruct,超越GPT-4o和Claude 3.5的AI模型

一、Nemotron-70B-Instruct 是什么 Nemotron-70B-Instruct 是由 NVIDIA 基于 Meta 的 Llama 3.1-70B 模型开发的先进大语言模型&#xff08;LLM&#xff09;。该模型采用了新颖的神经架构搜索&#xff08;Neural Architecture Search&#xff0c;NAS&#xff09;方法和知识蒸馏…

windows中git无法通过ssh连接github

windows中git无法通过ssh连接github 1 问题描述 在windows中&#xff0c;使用ssh-keygen -t rsa -C "<your-email>qq.com"生成ssh公钥和私钥&#xff0c;并按照要求将公钥添加到github中。此时&#xff0c;使用命令ssh -T gitgithub.com可以得到正确输出Hi x…

解决: java.lang.RuntimeException: can not run elasticsearch as root

目录 一、问题分析二、问题解决三、注意事项 种一棵树最好的时间是10年前&#xff0c;其次就是现在&#xff0c;加油&#xff01; --by蜡笔小柯南 一、问题分析 启动es时&#xff0c;报…