简体   繁体   English

删除固定高度以显示全屏图表

[英]Remove fixed height for full screen highcharts

I have a highchart with two yAxis. 我有一个带有两个yAxis的图表。 One axis is below the other. 一个轴在另一个轴下方。 Both have a fixed height. 两者都有固定的高度。 My Problem is that when I make it full screen the graph still takes only this original height. 我的问题是,当我将其全屏显示时,图形仍仅采用此原始高度。 Normally it will occupy the full height. 通常它将占据整个高度。 Is there anyway I can get full height element in full screen? 无论如何,我可以在全屏模式下获得全高元素吗?

Highcharts.chart('container', {
chart: {
    type: 'area'
},

yAxis: [{
        height : 200,
},
{
top:300,
height: 200,
}
],

xAxis: {
    categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
        'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
},

series: [{
    data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 126.0, 148.5, 216.4, 194.1, 95.6, 54.4],
    yAxis : 0,
},
{
    data: [54.4, 95.6, 194.1, 216.4, 148.5, 126.0, 135.6, 176.0, 144.5, 129.4, 106.1, 71.6, 29.4],
    yAxis : 1,
}]

}); });

This is my javascript code. 这是我的JavaScript代码。

I am attaching the fiddle here 我在这里附小提琴

Thanks in advance. 提前致谢。

You need to use the responsive parameters in order to get this done the way you wish: 您需要使用响应参数才能按照您希望的方式完成此操作:

https://jsfiddle.net/gugalondon/n0g9rhzw/1/ https://jsfiddle.net/gugalondon/n0g9rhzw/1/

This is the updated code that I added: 这是我添加的更新代码:

responsive: {
        rules: [{
            condition: {
                maxWidth: 500
            },
            // Make the labels less space demanding on mobile
            chartOptions: {
                xAxis: {
                    labels: {
                        formatter: function () {
                            return this.value.charAt(0);
                        }
                    }
                },
                yAxis: {
                    labels: {
                        align: 'left',
                        x: 0,
                        y: -2
                    },
                    title: {
                        text: ''
                    }
                }
            }
        }]
    },

and here's the modification of your yAxis: 这是您的yAxis的修改:

    yAxis: [{
            labels: {
                align: 'right',
                x: -3
            },
            height: '50%',
            lineWidth: 2,
            resize: {
                enabled: true
            }
        }, {
            labels: {
                align: 'right',
                x: -3
            },
            top: '50%',
            height: '50%',
            offset: 0,
            lineWidth: 2
        }],

 Highcharts.chart('container', { chart: { type: 'area' }, responsive: { rules: [{ condition: { maxWidth: 500 }, // Make the labels less space demanding on mobile chartOptions: { xAxis: { labels: { formatter: function () { return this.value.charAt(0); } } }, yAxis: { labels: { align: 'left', x: 0, y: -2 }, title: { text: '' } } } }] }, yAxis: [{ labels: { align: 'right', x: -3 }, height: '50%', lineWidth: 2, resize: { enabled: true } }, { labels: { align: 'right', x: -3 }, top: '50%', height: '50%', offset: 0, lineWidth: 2 }], xAxis: { categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'] }, series: [{ data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 126.0, 148.5, 216.4, 194.1, 95.6, 54.4], yAxis : 0, }, { data: [54.4, 95.6, 194.1, 216.4, 148.5, 126.0, 135.6, 176.0, 144.5, 129.4, 106.1, 71.6, 29.4], yAxis : 1, }] }); 
 #container { height:600px; } 
 <script src="https://code.highcharts.com/highcharts.js"></script> <script src="https://code.highcharts.com/modules/exporting.js"></script> <script src="https://code.highcharts.com/modules/offline-exporting.js"></script> <div id="container"></div> 

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

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