gpt4 book ai didi

html - 无法增加 Google Chart 高度

转载 作者:太空宇宙 更新时间:2023-11-04 07:34:02 24 4
gpt4 key购买 nike

我有这个谷歌图表(折线图)代码:

<html>
<head>

<style>
.chart {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
min-height: 500px;
}

#chart {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
min-height: 500px;
}

</style>

<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>

<script type="text/javascript">

google.charts.load('current', {'packages':['line']});
google.charts.setOnLoadCallback(drawChart);

window.addEventListener('resize', function (event) {
drawChart();
});

function drawChart() {

var data = new google.visualization.DataTable();
data.addColumn('number', 'Day');
data.addColumn('number', 'Guardians of the Galaxy');
data.addColumn('number', 'The Avengers');
data.addColumn('number', 'Transformers: Age of Extinction');

data.addRows([
[1, 37.8, 80.8, 41.8],
[2, 30.9, 69.5, 32.4],
[3, 25.4, 57, 25.7],
[4, 11.7, 18.8, 10.5],
[5, 11.9, 17.6, 10.4],
[6, 8.8, 13.6, 7.7],
[7, 7.6, 12.3, 9.6],
[8, 12.3, 29.2, 10.6],
[9, 16.9, 42.9, 14.8],
[10, 12.8, 30.9, 11.6],
[11, 5.3, 7.9, 4.7],
[12, 6.6, 8.4, 5.2],
[13, 4.8, 6.3, 3.6],
[14, 4.2, 6.2, 3.4]
]);

var options = {
chart: {
title: 'Box Office Earnings in First Two Weeks of Opening',
subtitle: 'in millions of dollars (USD)'
},
// width: 1800,
// height: 1000,
axes: {
x: {
0: {side: 'top'}
}
}
};

var chart = new google.charts.Line(document.getElementById('line_top_x'));
chart.draw(data, google.charts.Line.convertOptions(options));
}


</script>


</head>
<body>
<div id="line_top_x"></div>
</body>
</html>

您可以将其写入文件并使用浏览器打开它 - 它呈现良好,但无论我向 css(样式标签)添加什么,我都无法增加图形的高度。

谁知道如何让高度达到页面的 100%?

enter image description here

从屏幕截图中可以看出,图表在高度仅为 100 像素左右的地方被压扁了。

我添加了以下 CSS:

body {
width:80%;
height:80%;
margin:10% auto;
background:#e6e6e6;
}

#chart_wrap {
border:1px solid gray;
position: relative;
padding-bottom: 100%;
height: 0;
overflow:hidden;
}

#chart {
position: absolute;
top: 0;
left: 0;
width:100%;
height:100%;
}

我仍然无法增加高度:

enter image description here

我想我需要用它来改变宽度/高度

     var options = {
chart: {
title: 'Node.js memory usage (RSS, Heap Used, Heap Total)',
subtitle: '(In megabytes.)'
},
// width: 1800,
// height: 1000,
axes: {
x: {
0: {side: 'top'}
}
}
};

var chart = new google.charts.Line(document.getElementById('line_top_x'));
chart.draw(data, google.charts.Line.convertOptions(options));

但我不知道如何使用高度/宽度来使其成为窗口/容器的 100%。

最佳答案

添加这个CSS

#line_top_x {
height: 100vh;
}

关于html - 无法增加 Google Chart 高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49121619/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com