echart 动画 饼图_echarts构建关系图,节点可收缩和展开,可添加点击事件

echarts下载及使用

ECharts,一个使用 JavaScript 实现的开源可视化库,可以流畅的运行在 PC 和移动设备上,兼容当前绝大部分浏览器(IE8/9/10/11,Chrome,Firefox,Safari等),底层依赖轻量级的矢量图形库 ZRender,提供直观,交互丰富,可高度个性化定制的数据可视化图表。 ECharts 提供了常规的折线图、柱状图、散点图、饼图、K线图,用于统计的盒形图,用于地理数据可视化的地图、热力图、线图,用于关系数据可视化的关系图、旭日图,多维数据可视化的平行坐标,还有用于 BI 的漏斗图,仪表盘,并且支持图与图之间的混搭。

这里我们用echarts来绘制关系图,它长这样。

6a58c4a9e93d9d01ee34e59139bfa3a1.png

echarts的使用与配置

1.下载 下载地址:https://echarts.apache.org/zh/download.html

0cd8091d84907407ea2ea0ac45b2722b.png

从github上下载,我们需要的是这个文件

000cfff618e070ecb3f8cd894408ab70.png

这里我们可以挑一个下载,一般来说,压缩版的echart.min.js就够用了。

5分钟上手echarts

先用官网的例子做个演示,顺便检查前期的准备是否就绪。 1.首先,创建一个html文件。我使用的是vs_code编辑器。当然方法多种多样,就看大家各显神通了。 2.引入echarts

<!DOCTYPE html>
<html>
<head><meta charset="utf-8"><!-- 引入 ECharts 文件 --><script src="echarts.min.js"></script>
</head>
</html>

这里需要注意,引用echarts时路径要正确,比如

fa50916b8a766697e182e618b656fcb8.png

那么我们引用时就要这么写

<script src="D:echartsecharts项目1echarts.min.js"></script>

当然更简单的方法是,将echarts.min.js和html文件放在同一个文件夹里面。 这样就可以直接引用

<script src="echarts.min.js"></script>

3.准备一个DOM容器,设置窗口的宽和高(必须有,不然显示不出来)

<body><!-- 为 ECharts 准备一个具备大小(宽高)的 DOM --><div id="main" style="width: 600px;height:400px;"></div>
</body>

4.初始化一个echarts实例。 完整代码:

<!DOCTYPE html>
<html>
<head><meta charset="utf-8"><title>ECharts</title><!-- 引入 echarts.js --><script src="echarts.min.js"></script>
</head>
<body><!-- 为ECharts准备一个具备大小(宽高)的Dom --><div id="main" style="width: 600px;height:400px;"></div><script type="text/javascript">// 基于准备好的dom,初始化echarts实例var myChart = echarts.init(document.getElementById('main'));// 指定图表的配置项和数据var option = {title: {text: 'ECharts 入门示例'},tooltip: {},legend: {data:['销量']},xAxis: {data: ["衬衫","羊毛衫","雪纺衫","裤子","高跟鞋","袜子"]},yAxis: {},series: [{name: '销量',type: 'bar',data: [5, 20, 36, 10, 10, 20]}]};// 使用刚指定的配置项和数据显示图表。myChart.setOption(option);</script>
</body>
</html>

5.双击刚刚写好的html。如果你看到这样的图,那么我们可以开始构建关系图了。

d61938571e626e71f063d0a8f7328dc0.png

echarts使用过程中可能出现的问题及解决办法

1.运行后web上空白,无显示。 原因:ecahrts.js文件不对 解决办法: 1.http://echarts.baidu.com/build/dist/echarts-all.js 把之前的js换成这个。

<script src="http://echarts.baidu.com/build/dist/echarts.js"></script>

2.下载正确的文件,我之前遇到的坑,用echarts.simple.js和echarts.all.js就不行,所以我建议大家就用ecahrts.min.js或者echarts.js。

节点的收缩与展开

直接上代码

<!DOCTYPE html>
<html><head><meta charset="UTF-8"><title>关系图</title>
</head><body><div id="main" style="width: 1200px; height: 700px"></div><div id="ss"></div><script src="http://echarts.baidu.com/build/dist/echarts.js"></script><script type="text/javascript">require.config({paths: {echarts: 'http://echarts.baidu.com/build/dist'}});require(["echarts", "echarts/chart/force"], function(ec) {var myChart = ec.init(document.getElementById('main'), 'macarons');var option = {tooltip: {show: false},series: [{type: 'force',name: "Force tree",itemStyle: {normal: {label: {show: true},nodeStyle: {brushType: 'both',borderColor: 'rgba(0,215,0,0.4)',borderWidth: 1}}},categories: [{name: 'lol'}, {name: '位置'}, {name: '英雄'}, {name: '技能'}],nodes: [{id: 0,category: 0,name: '0',label: '峡谷之巅',symbolSize: 60,ignore: false,flag: true}, {id: 1,category: 1,name: '1',label: '上单',symbolSize: 40,ignore: true,flag: true}, {id: 2,category: 2,name: '2',label: '剑姬',symbolSize: 20,ignore: true,flag: true}, {id: 3,category: 2,name: '3',label: '贾科斯',symbolSize: 20,ignore: true,flag: true}, {id: 4,category: 1,name: '4',label: '中单',symbolSize: 40,ignore: true,flag: true}, {id: 5,category: 2,name: '5',label: '辛德拉',symbolSize: 20,ignore: true,flag: true}, {id: 6,category: 2,name: '6',label: '阿卡丽',symbolSize: 20,ignore: true,flag: true}, {id: 7,category: 2,name: '7',label: '发条',symbolSize: 20,ignore: true,flag: true}, {id: 8,category: 1,name: '8',label: '打野',symbolSize: 40,ignore: true,flag: true}, {id: 9,category: 2,name: '9',label: '扎克',symbolSize: 20,ignore: true,flag: true}, {id: 10,category: 2,name: '10',label: '男枪',symbolSize: 20,ignore: true,flag: true}, {id: 11,category: 2,name: '11',label: '豹女',symbolSize: 20,ignore: true,flag: true}, {id: 12,category: 2,name: '12',label: '千珏',symbolSize: 20,ignore: true,flag: true}, {id: 13,category: 3,name: '13',label: '隼舞',number: 45,symbolSize: 20,ignore: true,flag: true}, {id: 14,category: 3,name: '14',label: '寒影',number: 52,symbolSize: 20,ignore: true,flag: true}, {id: 15,category: 3,name: '15',label: '霞阵',number: 52,symbolSize: 20,ignore: true,flag: true}, {id: 16,category: 3,name: '16',label: '幻樱杀缭乱',number: 52,symbolSize: 30,ignore: true,flag: true}],links: [{source: 1,target: 0}, {source: 4,target: 0}, {source: 8,target: 0}, {source: 2,target: 1}, {source: 3,target: 1}, {source: 5,target: 4}, {source: 6,target: 4}, {source: 7,target: 4}, {source: 9,target: 8}, {source: 10,target: 8}, {source: 11,target: 8}, {source: 12,target: 8}, {source: 13,target: 6}, {source: 14,target: 6}, {source: 15,target: 6}, {source: 16,target: 6}]}]};myChart.setOption(option);var ecConfig = require('echarts/config');function openOrFold(param) {var option = myChart.getOption();var nodesOption = option.series[0].nodes;var linksOption = option.series[0].links;var data = param.data;var linksNodes = [];var categoryLength = option.series[0].categories.length;if (data != null && data != undefined) {if (data.flag) {for (var m in linksOption) {if (linksOption[m].target == data.id) {linksNodes.push(linksOption[m].source);}}if (linksNodes != null && linksNodes != undefined) {for (var p in linksNodes) {nodesOption[linksNodes[p]].ignore = false;nodesOption[linksNodes[p]].flag = true;}}nodesOption[data.id].flag = false;myChart.setOption(option);} else {for (var m in linksOption) {if (linksOption[m].target == data.id) {linksNodes.push(linksOption[m].source);}if (linksNodes != null && linksNodes != undefined) {for (var n in linksNodes) {if (linksOption[m].target == linksNodes[n]) {linksNodes.push(linksOption[m].source);}}}}if (linksNodes != null && linksNodes != undefined) {for (var p in linksNodes) {nodesOption[linksNodes[p]].ignore = true;nodesOption[linksNodes[p]].flag = true;}}nodesOption[data.id].flag = true;myChart.setOption(option);}}}myChart.on(ecConfig.EVENT.CLICK, openOrFold);});</script></body></html>

点击事件的添加

在这里我添加一个跳转网页的点击事件。点击阿卡丽的技能后,跳转到技能介绍页面。

myChart.on('click', function(param) {url = 'https://www.ruan8.com/wenda/12132.html'if (param.data['category'] == '3') {window.open(url)}});

完整代码:

<!DOCTYPE html>
<html><head><meta charset="UTF-8"><title>关系图</title>
</head><body><div id="main" style="width: 1200px; height: 700px"></div><div id="ss"></div><script src="http://echarts.baidu.com/build/dist/echarts.js"></script><script type="text/javascript">require.config({paths: {echarts: 'http://echarts.baidu.com/build/dist'}});require(["echarts", "echarts/chart/force"], function(ec) {var myChart = ec.init(document.getElementById('main'), 'macarons');var option = {tooltip: {show: false},series: [{type: 'force',name: "Force tree",itemStyle: {normal: {label: {show: true},nodeStyle: {brushType: 'both',borderColor: 'rgba(0,215,0,0.4)',borderWidth: 1}}},categories: [{name: 'lol'}, {name: '位置'}, {name: '英雄'}, {name: '技能'}],nodes: [{id: 0,category: 0,name: '0',label: '峡谷之巅',symbolSize: 60,ignore: false,flag: true}, {id: 1,category: 1,name: '1',label: '上单',symbolSize: 40,ignore: true,flag: true}, {id: 2,category: 2,name: '2',label: '剑姬',symbolSize: 20,ignore: true,flag: true}, {id: 3,category: 2,name: '3',label: '贾科斯',symbolSize: 20,ignore: true,flag: true}, {id: 4,category: 1,name: '4',label: '中单',symbolSize: 40,ignore: true,flag: true}, {id: 5,category: 2,name: '5',label: '辛德拉',symbolSize: 20,ignore: true,flag: true}, {id: 6,category: 2,name: '6',label: '阿卡丽',symbolSize: 20,ignore: true,flag: true}, {id: 7,category: 2,name: '7',label: '发条',symbolSize: 20,ignore: true,flag: true}, {id: 8,category: 1,name: '8',label: '打野',symbolSize: 40,ignore: true,flag: true}, {id: 9,category: 2,name: '9',label: '扎克',symbolSize: 20,ignore: true,flag: true}, {id: 10,category: 2,name: '10',label: '男枪',symbolSize: 20,ignore: true,flag: true}, {id: 11,category: 2,name: '11',label: '豹女',symbolSize: 20,ignore: true,flag: true}, {id: 12,category: 2,name: '12',label: '千珏',symbolSize: 20,ignore: true,flag: true}, {id: 13,category: 3,name: '13',label: '隼舞',number: 45,symbolSize: 20,ignore: true,flag: true}, {id: 14,category: 3,name: '14',label: '寒影',number: 52,symbolSize: 20,ignore: true,flag: true}, {id: 15,category: 3,name: '15',label: '霞阵',number: 52,symbolSize: 20,ignore: true,flag: true}, {id: 16,category: 3,name: '16',label: '幻樱杀缭乱',number: 52,symbolSize: 30,ignore: true,flag: true}],links: [{source: 1,target: 0}, {source: 4,target: 0}, {source: 8,target: 0}, {source: 2,target: 1}, {source: 3,target: 1}, {source: 5,target: 4}, {source: 6,target: 4}, {source: 7,target: 4}, {source: 9,target: 8}, {source: 10,target: 8}, {source: 11,target: 8}, {source: 12,target: 8}, {source: 13,target: 6}, {source: 14,target: 6}, {source: 15,target: 6}, {source: 16,target: 6}]}]};myChart.setOption(option);var ecConfig = require('echarts/config');function openOrFold(param) {var option = myChart.getOption();var nodesOption = option.series[0].nodes;var linksOption = option.series[0].links;var data = param.data;var linksNodes = [];var categoryLength = option.series[0].categories.length;if (data != null && data != undefined) {if (data.flag) {for (var m in linksOption) {if (linksOption[m].target == data.id) {linksNodes.push(linksOption[m].source);}}if (linksNodes != null && linksNodes != undefined) {for (var p in linksNodes) {nodesOption[linksNodes[p]].ignore = false;nodesOption[linksNodes[p]].flag = true;}}nodesOption[data.id].flag = false;myChart.setOption(option);} else {for (var m in linksOption) {if (linksOption[m].target == data.id) {linksNodes.push(linksOption[m].source);}if (linksNodes != null && linksNodes != undefined) {for (var n in linksNodes) {if (linksOption[m].target == linksNodes[n]) {linksNodes.push(linksOption[m].source);}}}}if (linksNodes != null && linksNodes != undefined) {for (var p in linksNodes) {nodesOption[linksNodes[p]].ignore = true;nodesOption[linksNodes[p]].flag = true;}}nodesOption[data.id].flag = true;myChart.setOption(option);}}}myChart.on(ecConfig.EVENT.CLICK, openOrFold);myChart.on('click', function(param) {url = 'https://www.ruan8.com/wenda/12132.html'if (param.data['category'] == '3') {window.open(url)}});});</script></body></html>

想看更多点击事件的写法可以上官方文档:

https://echarts.apache.org/zh/tutorial.html#ECharts%20%E4%B8%AD%E7%9A%84%E4%BA%8B%E4%BB%B6%E5%92%8C%E8%A1%8C%E4%B8%BA

总结

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/440920.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

三菱socket通信实例_三菱自动化产品相关知识整理汇总

先从应用最广泛的PLC产品来说下&#xff1a;小型机&#xff1a;FX3S、FX3G、FX3U、FX5U 中型机&#xff1a;L系列大型机&#xff1a;Q系列、R系列Q是比较老的产品&#xff0c;也是现在大型机里面应用比较普遍的产品&#xff0c;在Q之后开发出性价比比较高的产品L系列和性能更高…

英语人机考试计算机算分吗,英语人机对话考试技巧

1英语 人机对话考试技巧目前要在英语口语人机对话中获得好的成绩&#xff0c;除了了解测试的特点之外&#xff0c;还需掌握一定的技巧、这对提高英语口语人机对话成绩将起到事半功倍的作用。接下来小编告诉你英语人机对话考试技巧。调整心态&#xff0c;临场莫慌听力不同于其他…

玛纽尔扫地机器人怎样_扫地机器人哪个牌子好?满足日常清洁需求才值得推荐...

随着科技的发展,越来越多的家庭入手扫地机器人来代替日常打扫,而扫地机器人以其高智能化、自动化和便捷的清洁方式也获得了大部分家庭的喜爱。从市面上出售的扫地机器人来看,就清洁方面足以满足大部分家庭的需求,但是更进一步的定位巡航技术、扫拖一体功能以及强劲的续航保证,却…

【牛客 - 317D】小a与黄金街道(数论,tricks)

题干&#xff1a; 链接&#xff1a;https://ac.nowcoder.com/acm/contest/317/D 来源&#xff1a;牛客网 小a和小b来到了一条布满了黄金的街道上。它们想要带几块黄金回去&#xff0c;然而这里的城管担心他们拿走的太多&#xff0c;于是要求小a和小b通过做一个游戏来决定最…

ios 旋转屏幕试图切换_iOS增强现实应用(AR)设计指南(上)

- 这是 交互设计 的第 4篇文章 -- 读完本文&#xff0c;大概需要您 10分钟的时间 -本文为《iOS人机交互指南》的一部分&#xff0c;由黄方闻翻译&#xff0c;转载请注明出处。受公众号限制&#xff0c;无法跳转第三方网页为了更好的体验&#xff0c;欢迎访问http://hfw.design阅…

【牛客 - 317E】小a的轰炸游戏(差分,前缀和)

题干&#xff1a; 小a正在玩一款即时战略游戏&#xff0c;现在他要用航空母舰对敌方阵地进行轰炸 地方阵地可以看做是nmnm的矩形 航空母舰总共会派出qq架飞机。 飞机有两种&#xff0c;第一种飞机会轰炸以(xi,yi)(xi,yi)为中心&#xff0c;对角线长为lili的正菱形(也就是两条对…

认真测试直播软件,直播这么火,你知道怎么测试直播软件吗?

作为互联网的新生力量&#xff0c;一种新型的社交互动方式&#xff0c;直播软件快速在互联网行业占有一席之地。市场上对于直播软件的开发应用也越来越多&#xff0c;直播软件的框架&#xff1f;直播软件的原理&#xff1f;直播软件的功能点&#xff1f;直播软件测试关注点&…

计算机辅助教学研究现状,计算机辅助教学应用现状及对策研究

计算机辅助教学应用现状及对策研究 (8页)本资源提供全文预览&#xff0c;点击全文预览即可全文预览,如果喜欢文档就下载吧&#xff0c;查找使用更方便哦&#xff01;9.9 积分计算机辅助教学应用现状及对策研究摘要&#xff1a;新形势下&#xff0c;计算机辅助教学迅速发展&…

hostapd 进程启动不了_项目管理|项目启动会实操要点,项目经理掌权的关键

项目启动会就像古代的誓师大会&#xff0c;把大家集中到一起&#xff0c;告诉大家我们要去干什么&#xff0c;这个事情如何重要、皇帝如何重视&#xff0c;干成以后大家升官加爵、富贵少不了大家的等等&#xff0c;大会目的在于调动起大家干活的热情&#xff0c;然后顺利地推进…

怎么看联想计算机的ip,如何查看本机ip

ip地址是我们连上互联网的凭证&#xff0c;每台能连上互联网的电脑都会分配有一个ip地址。每台电脑的IP地址都不唯一&#xff0c;并且从我们主机的IP地址上可以看出我们电脑连上互联网的所在位置与地区&#xff0c;就像我们生活中的门牌号码一样。很多朋友还不知道本机ip怎么查…

当前元素_前端系列——获取页面中的DOM元素

这里就聊一下获取页面中DOM元素最基本的两种方法&#xff1a;document.getElementById.在整个页面中通过元素的Id属性值来获取到这个元素对象&#xff0c;getElementById是获取元素的方法&#xff0c;而document是获取元素的范围&#xff0c;我们也将此范围称为“上下文”。注意…

东华大学计算机年薪,东华大学公布应届毕业生薪酬:本科生月薪中位数6637元...

岁末年初&#xff0c;国内多所名校陆续发布了2020届毕业生就业质量报告&#xff0c;各校毕业生的平均薪酬也随之公布。澎湃新闻(www.thepaper.cn)注意到&#xff0c;由教育部直属的新中国第一所纺织高等学府东华大学也于近日公布了本校毕业生的平均薪酬状况。1月4日&#xff0c…

怎么做蒙特卡洛计算npv_PowerBI非标准日历下的同比环比计算,你知道怎么做吗?...

​对于按照自然年月日来分析的业务数据&#xff0c;在PowerBI中可以轻松的使用时间智能函数来进行各种时间指标的计算&#xff0c;但如果不是按标准的日历&#xff0c;很多人就开始有点懵&#xff0c;不知道该如何计算了。比如有的公司的业务月份是从26号到下个月的25号&#x…

pvz安卓服务器维修礼包码,植物大战僵尸2礼包兑换码大全2020最新版

植物大战僵尸2礼包码2020最新版是一款能够让玩家体验烧脑塔防大战的放置游戏&#xff0c;拥有经典的游戏规则设计&#xff0c;带来的玩法也会让每个玩家体验最为精彩的体验&#xff0c;每个僵尸都有着自己的特性&#xff0c;游戏之中的每一种植物都有自己的战斗方式&#xff0c…

服务器风扇一直高速转系统起不来,【案例】别克君越风扇启动后一直高速常转 维修案例...

故障诊断启动车辆&#xff0c;冷车时风扇正常&#xff0c;当温度达到正常温度后&#xff0c;节温器打开风扇一直常转&#xff0c;客户描述的问题存在。目测检查发动机外观状态&#xff1a;无漏油、无移位、部件连接无松动、电气插头安装牢固、无异味、无过热现象&#xff0c;都…

添加一列_Joom平台CSV文件如何添加产品?CSV文件添加产品流程一览

CSV文件添加产品在添加产品及变型以前&#xff0c;请先了解产品的CSV文件介绍以及产品变型要求。CSV添加产品CSV文件中的一行对应一个产品变型。卖家想为产品添加变型的话&#xff0c;需要在表格里新添一行或多行信息。——列表第一行是产品基本信息及产品本身的信息。卖家需要…

编码方式_【每日一题】| 常见的编码方式之栅栏密码

CTF_密码学栅栏密码点击上方蓝字 发现更多精彩01简介栅栏密码(Rail-fence Cipher)就是把要加密的明文分成N个字一组&#xff0c;然后把每组的第1个字符组合&#xff0c;每组第2个字符组合…每组的第N(最后一个分组可能不足N个)个字符组合&#xff0c;最后把他们全部连接起来就是…

【HDU - 3746 】Cyclic Nacklace (KMP,最小循环节问题)

题干&#xff1a; CC always becomes very depressed at the end of this month, he has checked his credit card yesterday, without any surprise, there are only 99.9 yuan left. he is too distressed and thinking about how to tide over the last days. Being inspir…

autosar网络管理_AP AUTOSAR平台设计(11)——网络管理

点击蓝字右上角 关注置顶不迷路Hello&#xff01;大家好&#xff01;欢迎来到《搞一下汽车电子》本篇是AP AUTOSAR平台设计(11)——网络管理如果觉得不错&#xff0c;“转发” “ 在看”支持一下吧~1.网络管理算法概述AUTOSAR NM基于分散的网络管理策略&#xff0c;这意味…

【牛客 - 331G】炫酷数字(反素数打表 或 扩展埃式筛法,结论)

题干&#xff1a; 小希希望你构造一个最小的正整数&#xff0c;使得其有n个因子。 输入描述: 第一行一个整数T表示数据组数每组数据第一行输入一个正整数n&#xff0c;表示其因子数。n≤1,000,000n≤1,000,000T≤1,000,000T≤1,000,000输出描述: 输出一行一个整数&#xff…