echarts官网
vue项目中会遇到点击echarts工具栏中的全屏按钮,让图表全屏显示的问题,这里涉及到自定义工具栏按钮问题。
话不多说,直接上代码:在echart的工具栏中添加全屏按钮并设置点击事件。即toolbox添加自定义图标全屏按钮事件。
下面是代码:
// 右上角下载的按钮
toolbox: {
feature: {
saveAsImage: {}, // 下载的按钮
myFull: { // 全屏
show: true,
title: '全屏',
icon: 'path://M432.45,595.444c0,2.177-4.661,6.82-11.305,6.82c-6.475,0-11.306-4.567-11.306-6.82s4.852-6.812,11.306-6.812C427.841,588.632,432.452,593.191,432.45,595.444L432.45,595.444z M421.155,589.876c-3.009,0-5.448,2.495-5.448,5.572s2.439,5.572,5.448,5.572c3.01,0,5.449-2.495,5.449-5.572C426.604,592.371,424.165,589.876,421.155,589.876L421.155,589.876z M421.146,591.891c-1.916,0-3.47,1.589-3.47,3.549c0,1.959,1.554,3.548,3.47,3.548s3.469-1.589,3.469-3.548C424.614,593.479,423.062,591.891,421.146,591.891L421.146,591.891zM421.146,591.891',
onclick: (e) => {
const element = this.$refs.radarbox
// 全屏查看
if (element.requestFullScreen) {
// HTML W3C 提议
element.requestFullScreen()
} else if (element.msRequestFullscreen) {
// IE11
element.msRequestFullScreen()
} else if (element.webkitRequestFullScreen) {
// Webkit
element.webkitRequestFullScreen()
} else if (element.mozRequestFullScreen) {
// Firefox
element.mozRequestFullScreen()
}
// 退出全屏
if (element.requestFullScreen) {
document.exitFullscreen()
} else if (element.msRequestFullScreen) {
document.msExitFullscreen()
} else if (element.webkitRequestFullScreen) {
document.webkitCancelFullScreen()
} else if (element.mozRequestFullScreen) {
document.mozCancelFullScreen()
}
}
}
}
},
如下图点击就是全屏了
如果您觉得有用请点赞 + 评论就是对我最大的支持了!