首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使ECharts.js全屏

使ECharts.js全屏
EN

Stack Overflow用户
提问于 2022-03-11 18:45:50
回答 1查看 418关注 0票数 0

我一直在尝试在Echarts.js中复制这个Echarts.js功能,以制作一个全屏的情节:https://www.highcharts.com/demo/line-basic

请注意,通过单击右上角按钮,您可以选择全屏模式,然后按Esc即可禁用该模式。

我尝试过在Echarts.js中创建一个自定义按钮,就像在高级图表https://jsfiddle.net/BlackLabel/1ga2fqL0/中这样的按钮,但没有成功:

代码语言:javascript
复制
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);
})

有什么想法吗?

EN

回答 1

Stack Overflow用户

发布于 2022-07-15 05:00:20

代码语言:javascript
复制
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;
    }

我的图表

代码语言:javascript
复制
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);
            }
        }
    }
},
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71443316

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档