我一直在尝试在Echarts.js中复制这个Echarts.js功能,以制作一个全屏的情节:https://www.highcharts.com/demo/line-basic。
请注意,通过单击右上角按钮,您可以选择全屏模式,然后按Esc即可禁用该模式。
我尝试过在Echarts.js中创建一个自定义按钮,就像在高级图表https://jsfiddle.net/BlackLabel/1ga2fqL0/中这样的按钮,但没有成功:
btn.addEventListener('click', function() {
Highcharts.FullScreen = function(container) {
this.init(container.parentNode); // main div of the chart
};
Highcharts.FullScreen.prototype = {
init: function(container) {
if (container.requestFullscreen) {
container.requestFullscreen();
} else if (container.mozRequestFullScreen) {
container.mozRequestFullScreen();
} else if (container.webkitRequestFullscreen) {
container.webkitRequestFullscreen();
} else if (container.msRequestFullscreen) {
container.msRequestFullscreen();
}
}
};
chart.fullscreen = new Highcharts.FullScreen(chart.container);
})有什么想法吗?
发布于 2022-07-15 05:00:20
function GoInFullscreen(element) {
if (element.requestFullscreen)
element.requestFullscreen();
else if (element.mozRequestFullScreen)
element.mozRequestFullScreen();
else if (element.webkitRequestFullscreen)
element.webkitRequestFullscreen();
else if (element.msRequestFullscreen)
element.msRequestFullscreen();
}
function GoOutFullscreen() {
if (document.exitFullscreen)
document.exitFullscreen();
else if (document.mozCancelFullScreen)
document.mozCancelFullScreen();
else if (document.webkitExitFullscreen)
document.webkitExitFullscreen();
else if (document.msExitFullscreen)
document.msExitFullscreen();
}
function IsFullScreenCurrently() {
var full_screen_element = document.fullscreenElement || document.webkitFullscreenElement || document.mozFullScreenElement || document.msFullscreenElement || null;
// If no element is in full-screen
if (full_screen_element === null)
return false;
else
return true;
}
function setFullScreenToolBox(divname, idchart) {
var classold = document.getElementById(divname).className;
var idold = document.getElementById(idchart);
if (classold == 'col-md-12') {
document.getElementById(divname).className = "col-md-6";
if (IsFullScreenCurrently())
GoOutFullscreen();
idold.style = 'height:300px';
}
else if (classold == 'col-md-6') {
document.getElementById(divname).className = "col-md-12";
//idold.style = 'height:500px';
var heights = screen.height;// window.innerHeight;
idold.style.height = heights -100 + "px";
GoInFullscreen($("#" + divname).get(0));
}
return true;
}我的图表
toolbox: {
feature: {
magicType: {
type: ['line', 'bar'],
title: {
line: 'line',
bar: 'bar'
},
},
saveAsImage: {
show: true,
title: 'Save Image',
pixelRatio: 3
},
myTool: { //Custom tool myTool
show: true,
title: 'Full screen',
icon: 'image://img/fullscr.png',
onclick: function() {
setFullScreenToolBox('divdtngay', 'iddoanhthungay');
setTimeout(function() {
stackedPointerArea_dt.resize();
}, 500);
}
}
}
},https://stackoverflow.com/questions/71443316
复制相似问题