简体   繁体   English

使 ECharts.js 全屏显示

[英]Make ECharts.js full screen

I have been trying to reproduce this Highcharts.js functionality in Echarts.js to make a plot full screen: https://www.highcharts.com/demo/line-basic .我一直在尝试在Echarts.js中重现此 Highcharts.js 功能以制作全屏绘图: https ://www.highcharts.com/demo/line-basic。

Note that by clicking on the top right button you can select a full screen mode, which can then be disabled by pressing Esc.请注意,通过单击右上角的按钮,您可以选择全屏模式,然后可以通过按 Esc 禁用该模式。

I have tried creating a custom button in Echarts.js like this one in Highcharts https://jsfiddle.net/BlackLabel/1ga2fqL0/ without much success:我尝试在Echarts.js中创建一个自定义按钮,就像在 Highcharts 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);
})

Any ideas?有任何想法吗?

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;
    }

My chart我的图表

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);
            }
        }
    }
},

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM